28 #define WRN_DP LOG_STREAM(warn, log_display)
47 return (SDL_GetModState() & KMOD_CTRL) != 0;
55 , minimap_scrolling_(false)
56 , dragging_left_(false)
57 , dragging_touch_(false)
58 , dragging_started_(false)
59 , dragging_right_(false)
67 , scroll_started_(false)
138 #ifdef MOUSE_TOUCH_EMULATION
139 if(
dragging_left_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT))) {
141 mouse_state = SDL_BUTTON(SDL_BUTTON_LEFT);
144 if((
dragging_left_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0) ||
145 (
dragging_right_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0))
147 const double drag_distance =
182 static clock_t touch_timestamp = 0;
185 if (event.state == SDL_PRESSED) {
187 touch_timestamp = clock();
192 }
else if (event.state == SDL_RELEASED) {
196 clock_t dt = clock() - touch_timestamp;
197 if (dt > CLOCKS_PER_SEC * 3 / 10) {
213 if(event.state == SDL_PRESSED) {
219 }
else if(event.state == SDL_RELEASED) {
227 if(event.state == SDL_PRESSED) {
232 }
else if(event.state == SDL_RELEASED) {
241 if(event.state == SDL_PRESSED) {
248 if(minimap_loc.
valid()) {
266 }
else if(event.state == SDL_RELEASED) {
273 }
else if(event.button == SDL_BUTTON_X1 || event.button == SDL_BUTTON_X2) {
274 if(event.state == SDL_PRESSED) {
294 #ifdef MOUSE_TOUCH_EMULATION
295 if(event.button == SDL_BUTTON_RIGHT) {
299 if(event.which == SDL_TOUCH_MOUSEID) {
307 return event.button == SDL_BUTTON_MIDDLE;
312 #ifdef MOUSE_TOUCH_EMULATION
316 if(event.which == SDL_TOUCH_MOUSEID) {
319 return event.button == SDL_BUTTON_RIGHT
326 return event.which == SDL_TOUCH_MOUSEID;
331 if(
gui().view_locked()) {
370 if(movex != 0 || movey != 0) {
373 if(pressed[SDLK_LALT] || pressed[SDLK_RALT]) {
382 }
else if(scrollx > 0) {
388 }
else if(scrolly > 0) {
403 WRN_DP <<
"no context menu found...";
409 dragging_flag =
true;
Class that keeps track of all the keys on the keyboard.
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 scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
virtual void highlight_hex(map_location hex)
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.
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 mouse_button_event(const SDL_MouseButtonEvent &event, uint8_t button, map_location loc, bool click=false)
bool show_menu_
Show context menu flag.
bool dragging_right_
RMB drag init flag.
virtual void left_drag_end(int, int, const bool)
Called whenever the left mouse drag has "ended".
bool minimap_scrolling_
minimap scrolling (scroll-drag) state flag
bool dragging_left_
LMB drag init flag.
map_location last_hex_
last highlighted hex
virtual void mouse_wheel_right(int, int, const bool)
Called when the mouse wheel is scrolled right.
virtual void mouse_wheel_down(int, int, const bool)
Called when the mouse wheel is scrolled down.
map_location drag_from_hex_
Drag start or mouse-down map location.
virtual int drag_threshold() const
Minimum dragging distance to fire the drag&drop.
virtual void right_drag_end(int, int, const bool)
Called whenever the right mouse drag has "ended".
void touch_motion_event(const SDL_TouchFingerEvent &event, const bool browse)
bool is_left_click(const SDL_MouseButtonEvent &event) const
int drag_from_y_
Drag start position y.
virtual void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
bool is_touch_click(const SDL_MouseButtonEvent &event) const
bool dragging_started() const
If mouse/finger has moved far enough to consider it move/swipe, and not a click/touch.
virtual void mouse_wheel_up(int, int, const bool)
Called when the mouse wheel is scrolled up.
bool simple_warp_
MMB click (on game map) state flag.
bool is_middle_click(const SDL_MouseButtonEvent &event) const
void mouse_update(const bool browse, map_location loc)
Update the mouse with a fake mouse motion.
void init_dragging(bool &dragging_flag)
void clear_drag_from_hex()
virtual void left_mouse_up(int, int, const bool)
Called when the left mouse button is up.
bool is_right_click(const SDL_MouseButtonEvent &event) const
bool mouse_motion_default(int x, int y, bool update)
This handles minimap scrolling and click-drag.
bool dragging_started_
Actual drag flag.
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 display & gui()=0
Reference to the used display objects.
virtual bool right_click(int x, int y, const bool browse)
Overridden in derived classes, called on a right click (mousedown).
void mouse_motion_event(const SDL_MouseMotionEvent &event, const bool browse)
virtual void right_mouse_up(int, int, const bool)
Called when the right mouse button is up.
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 touch_action(const map_location hex, bool browse)
bool dragging_touch_
Finger drag init flag.
int drag_from_x_
Drag start position x.
virtual void mouse_wheel(int xscroll, int yscroll, bool browse)
Called when scrolling with the mouse wheel.
virtual void move_action(bool)
Overridden in derived class.
virtual bool left_click(int x, int y, const bool browse)
Overridden in derived classes, called on a left click (mousedown).
virtual void mouse_wheel_left(int, int, const bool)
Called when the mouse wheel is scrolled left.
void clear_dragging(const SDL_MouseButtonEvent &event, 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 set_scroll_start(int x, int y)
Called when the middle click scrolling.
const menu * context_menu() const
map_display and display: classes which take care of displaying the map and game-data on the screen.
Standard logging facilities (interface).
static lg::log_domain log_display("display")
void set_dragging(bool drag)
Handling of system events.
static bool command_active()
uint32_t get_mouse_button_mask()
Returns the current mouse button mask.
uint32_t get_mouse_state(int *x, int *y)
A wrapper for SDL_GetMouseState that gives coordinates in draw space.
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
Contains the SDL_Rect helper code.
Encapsulates the map of the game.
static const map_location & null_location()