Skip to content

Commit

Permalink
Adição da rotina que obtem a posição do mouse.
Browse files Browse the repository at this point in the history
  • Loading branch information
edsomjr committed Jun 1, 2016
1 parent 26c3fa4 commit d30d062
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <memory>

using std::pair;
using std::string;
using std::unique_ptr;
using std::shared_ptr;
Expand Down Expand Up @@ -46,6 +47,7 @@ namespace ijengine {
void unregister_translator(EventsTranslator *translator);
void register_listener(GameEventsListener *listener);
void unregister_listener(GameEventsListener *listener);
pair<int, int> mouse_position();
}

namespace time {
Expand Down
2 changes: 2 additions & 0 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace ijengine {

virtual Texture * load_texture(const Canvas* canvas, const string& filepath) = 0;
virtual Font * load_font(const string& filepath, unsigned size) = 0;

virtual pair<int, int> mouse_position() = 0;
};
}

Expand Down
10 changes: 10 additions & 0 deletions kernel/sdl2/sdl2kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,13 @@ SDL2Kernel::load_font(const string& filepath, unsigned size)
SDL2Font *f = new SDL2Font(filepath, size, font);
return f;
}

pair<int, int>
SDL2Kernel::mouse_position()
{
int x, y;
SDL_GetMouseState(&x, &y);

return pair<int, int>(x, y);
}

1 change: 1 addition & 0 deletions kernel/sdl2/sdl2kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SDL2Kernel : public Kernel {
Texture * load_texture(const Canvas* canvas, const string& filepath);
Font * load_font(const string& filepath, unsigned size);

pair<int, int> mouse_position();
private:
Time *m_timer;
unsigned m_last_update;
Expand Down
7 changes: 7 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ namespace ijengine
if (listener->on_event(event))
break;
}

}

pair<int, int>
mouse_position()
{
return kernel->mouse_position();
}

void
Expand Down

0 comments on commit d30d062

Please sign in to comment.