mouse cursor

This commit is contained in:
Squishy Bloob 2024-03-26 17:32:52 +00:00
parent 8214786a3e
commit df5a5979da
3 changed files with 16 additions and 1 deletions

View File

@ -4,12 +4,17 @@
#include "settings.h" #include "settings.h"
struct game { struct game {
game();
void run(); void run();
virtual void init(settings& settings); virtual void init(settings& settings);
virtual void render(image& target); virtual void render(image& target);
virtual void update(); virtual void update();
protected: protected:
vec2i const& mouse_pos() const; vec2i const& mouse_pos() const;
void cursor(image const* cursor);
private: private:
vec2i _mouse_pos; vec2i _mouse_pos;
image const* _cursor;
}; };

View File

@ -18,6 +18,9 @@ LRESULT WINAPI wnd_proc(HWND window, UINT msg, WPARAM w, LPARAM l) {
return ::DefWindowProc(window, msg, w, l); return ::DefWindowProc(window, msg, w, l);
} }
game::game() : _cursor(0) {
}
void game::run() { void game::run() {
settings settings; settings settings;
init(settings); init(settings);
@ -87,6 +90,8 @@ void game::run() {
if(now - last_frame >= frame_duration) { if(now - last_frame >= frame_duration) {
update(); update();
render(screen); render(screen);
if(_cursor)
screen.draw(*_cursor, _mouse_pos);
window_image.draw_upscaled(screen); window_image.draw_upscaled(screen);
BITMAPINFOHEADER bi{ sizeof(bi) }; BITMAPINFOHEADER bi{ sizeof(bi) };
@ -192,3 +197,7 @@ void game::update() {
vec2i const& game::mouse_pos() const { vec2i const& game::mouse_pos() const {
return _mouse_pos; return _mouse_pos;
} }
void game::cursor(image const* cursor) {
_cursor = cursor;
}

View File

@ -22,6 +22,7 @@ my_game::my_game() :
void my_game::init(settings& settings) { void my_game::init(settings& settings) {
settings.target_fps = 60; settings.target_fps = 60;
cursor(&font['\\']);
} }
void my_game::update() { void my_game::update() {
@ -35,7 +36,7 @@ void my_game::render(image& target) {
//target.draw(img, vec2i(320, 180) + pos); //target.draw(img, vec2i(320, 180) + pos);
//target.draw(tileset[0xda], vec2i(320, 180) + pos, 0xff00ff); //target.draw(tileset[0xda], vec2i(320, 180) + pos, 0xff00ff);
target.draw("hello world!", vec2i(320, 180) + pos, font, 0xffffff, 0); target.draw("hello world!", vec2i(320, 180) + pos, font, 0xffffff, 0);
target.draw("\\", mouse_pos(), font, 0xffffff, 0); //target.draw("\\", mouse_pos(), font, 0xffffff, 0);
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {