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)
66 , scroll_started_(false)
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 =
146 std::pow(
static_cast<double>(
drag_from_.x - pos.x), 2) +
147 std::pow(
static_cast<double>(
drag_from_.y - pos.y), 2);
180 static clock_t touch_timestamp = 0;
183 if (event.state == SDL_PRESSED) {
185 touch_timestamp = clock();
190 }
else if (event.state == SDL_RELEASED) {
194 clock_t dt = clock() - touch_timestamp;
195 if (dt > CLOCKS_PER_SEC * 3 / 10) {
211 if(event.state == SDL_PRESSED) {
217 }
else if(event.state == SDL_RELEASED) {
225 if(event.state == SDL_PRESSED) {
230 }
else if(event.state == SDL_RELEASED) {
239 if(event.state == SDL_PRESSED) {
246 if(minimap_loc.
valid()) {
264 }
else if(event.state == SDL_RELEASED) {
271 }
else if(event.button == SDL_BUTTON_X1 || event.button == SDL_BUTTON_X2) {
272 if(event.state == SDL_PRESSED) {
292 #ifdef MOUSE_TOUCH_EMULATION
293 if(event.button == SDL_BUTTON_RIGHT) {
297 if(event.which == SDL_TOUCH_MOUSEID) {
305 return event.button == SDL_BUTTON_MIDDLE;
310 #ifdef MOUSE_TOUCH_EMULATION
314 if(event.which == SDL_TOUCH_MOUSEID) {
317 return event.button == SDL_BUTTON_RIGHT
324 return event.which == SDL_TOUCH_MOUSEID;
329 if(
gui().view_locked()) {
367 if(movex != 0 || movey != 0) {
370 if(pressed[SDLK_LALT] || pressed[SDLK_RALT]) {
379 }
else if(scrollx > 0) {
385 }
else if(scrolly > 0) {
400 WRN_DP <<
"no context menu found...";
406 dragging_flag =
true;
Class that keeps track of all the keys on the keyboard.
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...
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(const point &amount, bool force=false)
Scrolls the display by amount pixels.
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
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.
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).
point drag_from_
Drag start position.
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.
point get_mouse_location()
Returns the current mouse location 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()