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_touch_(false)
56 , dragging_started_(false)
57 , dragging_right_(false)
65 , scroll_started_(false)
94 SDL_GetMouseState(&x, &y);
110 minimap_scrolling_ = ((SDL_GetMouseState(
nullptr,
nullptr) & (SDL_BUTTON(SDL_BUTTON_LEFT) | SDL_BUTTON(SDL_BUTTON_MIDDLE))) != 0);
136 #ifdef MOUSE_TOUCH_EMULATION 137 if(
dragging_left_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT))) {
139 mouse_state = SDL_BUTTON(SDL_BUTTON_LEFT);
142 if((
dragging_left_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0) ||
143 (
dragging_right_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0))
145 const double drag_distance =
169 static clock_t touch_timestamp = 0;
172 if (event.state == SDL_PRESSED) {
174 touch_timestamp = clock();
177 }
else if (event.state == SDL_RELEASED) {
181 time_t dt = clock() - touch_timestamp;
182 if (dt > CLOCKS_PER_SEC * 3 / 10) {
193 if(event.state == SDL_PRESSED) {
197 }
else if(event.state == SDL_RELEASED) {
203 if(event.state == SDL_PRESSED) {
207 }
else if(event.state == SDL_RELEASED) {
213 if(event.state == SDL_PRESSED) {
219 if(minimap_loc.
valid()) {
231 }
else if(event.state == SDL_RELEASED) {
247 #ifdef MOUSE_TOUCH_EMULATION 248 if(event.button == SDL_BUTTON_RIGHT) {
252 if(event.which == SDL_TOUCH_MOUSEID) {
260 return event.button == SDL_BUTTON_MIDDLE;
265 #ifdef MOUSE_TOUCH_EMULATION 269 if(event.which == SDL_TOUCH_MOUSEID) {
272 return event.button == SDL_BUTTON_RIGHT
279 return event.which == SDL_TOUCH_MOUSEID;
284 if(
gui().view_locked()) {
313 SDL_GetMouseState(&x, &y);
323 if(movex != 0 || movey != 0) {
326 if(pressed[SDLK_LALT] || pressed[SDLK_RALT]) {
335 }
else if(scrollx > 0) {
341 }
else if(scrolly > 0) {
356 WRN_DP <<
"no context menu found..." << std::endl;
362 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)
bool dragging_right_
RMB drag init flag.
void set_scroll_start(int x, int y)
Called when the middle click scrolling.
bool dragging_touch_
Finger drag init flag.
virtual int drag_threshold() const
Minimum dragging distance to fire the drag&drop.
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...
bool dragging_started_
Actual drag flag.
bool is_middle_click(const SDL_MouseButtonEvent &event) const
virtual void mouse_wheel_right(int, int, const bool)
Called when the mouse wheel is scrolled right.
virtual bool right_click(int x, int y, const bool browse)
Overridden in derived classes, called on a right click (mousedown).
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...
void touch_motion_event(const SDL_TouchFingerEvent &event, const bool browse)
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.
void mouse_motion_event(const SDL_MouseMotionEvent &event, const bool browse)
virtual void mouse_wheel_down(int, int, const bool)
Called when the mouse wheel is scrolled down.
bool is_right_click(const SDL_MouseButtonEvent &event) const
virtual bool right_click_show_menu(int, int, const bool)
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
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).
bool minimap_scrolling_
minimap scrolling (scroll-drag) state flag
bool is_left_click(const SDL_MouseButtonEvent &event) const
void set_dragging(bool drag)
bool show_menu_
Show context menu flag.
virtual void mouse_wheel_up(int, int, const bool)
Called when the mouse wheel is scrolled up.
bool dragging_started() const
If mouse/finger has moved far enough to consider it move/swipe, and not a click/touch.
map_location drag_from_hex_
Drag start map location.
virtual void left_drag_end(int, int, const bool)
Called whenever the left mouse drag has "ended".
virtual void right_mouse_up(int, int, const bool)
Called when the right mouse button is up.
map_display and display: classes which take care of displaying the map and game-data on the screen...
bool dragging_left_
LMB drag init flag.
static lg::log_domain log_display("display")
virtual void move_action(bool)
Overridden in derived class.
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.
virtual void right_drag_end(int, int, const bool)
Called whenever the right mouse drag has "ended".
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.
bool is_touch_click(const SDL_MouseButtonEvent &event) const
bool middle_click_scrolls()
virtual void touch_action(const map_location hex, bool browse)
static bool command_active()
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.
virtual void touch_motion(int x, int y, const bool browse, bool update=false, map_location new_loc=map_location::null_location())=0
virtual void mouse_wheel_left(int, int, const bool)
Called when the mouse wheel is scrolled left.
void init_dragging(bool &dragging_flag)
virtual display & gui()=0
Reference to the used display objects.
Standard logging facilities (interface).
const menu * context_menu() const
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.
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.
int drag_from_y_
Drag start position y.
virtual void left_mouse_up(int, int, const bool)
Called when the left mouse button is up.