26 #define WRN_DP LOG_STREAM(warn, log_display)
45 return (SDL_GetModState()&KMOD_CTRL) != 0;
53 minimap_scrolling_(false),
54 dragging_left_(false),
55 dragging_started_(false),
56 dragging_right_(false),
64 scroll_started_(false)
81 SDL_GetMouseState(&x,&y);
97 minimap_scrolling_ = ((SDL_GetMouseState(
nullptr,
nullptr) & (SDL_BUTTON(1) | SDL_BUTTON(2))) != 0);
118 if ((
dragging_left_ && (SDL_GetMouseState(&mx,&my) & SDL_BUTTON_LEFT) != 0)
119 || (
dragging_right_ && (SDL_GetMouseState(&mx,&my) & SDL_BUTTON_RIGHT) != 0)) {
120 const double drag_distance = std::pow(static_cast<double>(
drag_from_x_- mx), 2)
141 if (event.state == SDL_PRESSED) {
145 }
else if (event.state == SDL_RELEASED) {
151 if (event.state == SDL_PRESSED) {
155 }
else if (event.state == SDL_RELEASED) {
161 if (event.state == SDL_PRESSED) {
180 }
else if (event.state == SDL_RELEASED) {
194 const SDL_MouseButtonEvent&
event)
const
200 const SDL_MouseButtonEvent&
event)
const
202 return event.button == SDL_BUTTON_MIDDLE;
206 const SDL_MouseButtonEvent&
event)
const
208 return event.button == SDL_BUTTON_RIGHT
256 SDL_GetMouseState(&x, &y);
264 movex = 0; movey = 0;
267 if (movex != 0 || movey != 0) {
270 if (pressed[SDLK_LALT] || pressed[SDLK_RALT]) {
279 }
else if (scrollx > 0) {
285 }
else if (scrolly > 0) {
314 WRN_DP <<
"no context menu found..." << std::endl;
333 dragging_flag =
true;
bool mouse_motion_default(int x, int y, bool update)
This handles minimap scrolling and click-drag.
int drag_from_x_
Drag start position x.
void clear_dragging(const SDL_MouseButtonEvent &event, bool browse)
virtual void left_mouse_up(int x, int y, const bool browse)
Called when the left mouse button is up.
bool is_left_click(const SDL_MouseButtonEvent &event) const
bool dragging_right_
RMB drag init flag.
std::shared_ptr< gui::zoom_slider > find_slider(const std::string &id)
void set_scroll_start(int x, int y)
Called when the middle click scrolling.
bool dragging_started_
Actual drag flag.
virtual bool right_click_show_menu(int x, int y, const bool browse)
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
virtual void right_drag_end(int x, int y, const bool browse)
Called whenever the right mouse drag has "ended".
virtual void mouse_wheel_down(int x, int y, const bool browse)
Called when the mouse wheel is scrolled down.
map_location minimap_location_on(int x, int y)
given x,y co-ordinates of the mouse, will return the location of the hex in the minimap that the mous...
virtual bool allow_mouse_wheel_scroll(int x, int y)
Derived classes can override this to disable mousewheel scrolling under some circumstances, e.g.
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
GLint GLint GLint GLint GLint GLint y
virtual void mouse_motion(int x, int y, const bool browse, bool update=false, map_location new_loc=map_location::null_location())=0
Called when a mouse motion event takes place.
virtual void draw()
Draws invalidated items.
void mouse_motion_event(const SDL_MouseMotionEvent &event, const bool browse)
virtual void mouse_wheel_up(int x, int y, const bool browse)
Called when the mouse wheel is scrolled up.
virtual void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
virtual bool left_click(int x, int y, const bool browse)
Overridden in derived classes, called on a left click (mousedown).
virtual bool right_click(int x, int y, const bool browse)
Overridden in derived classes, called on a right click (mousedown).
bool minimap_scrolling_
minimap scrolling (scroll-drag) state flag
void set_dragging(bool drag)
virtual void right_mouse_up(int x, int y, const bool browse)
Called when the right mouse button is up.
virtual void mouse_wheel_right(int x, int y, const bool browse)
Called when the mouse wheel is scrolled right.
bool show_menu_
Show context menu flag.
map_location drag_from_hex_
Drag start map location.
map_display and display: classes which take care of displaying the map and game-data on the screen...
const menu * context_menu() const
bool dragging_left_
LMB drag init flag.
static lg::log_domain log_display("display")
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
Encapsulates the map of the game.
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
virtual void mouse_wheel_left(int x, int y, const bool browse)
Called when the mouse wheel is scrolled left.
bool middle_click_scrolls()
static bool command_active()
GLint GLint GLint GLint GLint x
virtual void mouse_wheel(int xscroll, int yscroll, bool browse)
Called when scrolling with the mouse wheel.
Handling of system events.
map_location last_hex_
last highlighted hex
Contains the SDL_Rect helper code.
void init_dragging(bool &dragging_flag)
virtual display & gui()=0
Reference to the used display objects.
Standard logging facilities (interface).
virtual int drag_threshold() const
bool is_right_click(const SDL_MouseButtonEvent &event) const
virtual void move_action(bool browse)
Overridden in derived class.
Class that keeps track of all the keys on the keyboard.
void mouse_update(const bool browse, map_location loc)
update the mouse with a fake mouse motion
virtual void left_drag_end(int x, int y, const bool browse)
Called whenever the left mouse drag has "ended".
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
bool simple_warp_
MMB click (on game map) state flag.
bool is_middle_click(const SDL_MouseButtonEvent &event) const
int drag_from_y_
Drag start position y.