35 #define ERR_DP LOG_STREAM(err, log_display)
37 using namespace std::chrono_literals;
46 , scroll_right_(false)
48 , scroll_carry_x_(0.0)
49 , scroll_carry_y_(0.0)
50 , key_release_listener_(*this)
51 , long_touch_timer_(0)
70 #ifdef MOUSE_TOUCH_EMULATION
71 if(mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
73 mouse_state = SDL_BUTTON(SDL_BUTTON_LEFT);
81 bool yes_actually_dragging = dx * dx + dy * dy >= threshold * threshold;
83 if(!yes_actually_dragging
84 && (mouse_state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0)
101 SDL_Event new_event = {};
110 case SDL_TEXTEDITING:
112 SDL_Event evt = event;
113 evt.type = SDL_TEXTINPUT;
116 SDL_StartTextInput();
124 if(event.key.keysym.sym == SDLK_ESCAPE) {
142 case SDL_JOYBUTTONDOWN:
146 case SDL_JOYHATMOTION:
150 case SDL_MOUSEMOTION:
152 if(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
153 while(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {};
165 case SDL_FINGERMOTION:
166 if(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_FINGERMOTION, SDL_FINGERMOTION) > 0) {
167 while(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_FINGERMOTION, SDL_FINGERMOTION) > 0) {
175 case SDL_MOUSEBUTTONDOWN:
177 int x =
event.button.x;
178 int y =
event.button.y;
185 if(event.button.clicks == 2) {
198 case SDL_MOUSEBUTTONUP:
218 #if defined(_WIN32) || defined(__APPLE__)
231 const char* video_driver = SDL_GetCurrentVideoDriver();
233 SDL_GetVersion(&ver);
234 if(video_driver !=
nullptr && ver.major <= 2 && ver.minor <= 0) {
235 if(std::strcmp(video_driver,
"x11") == 0 && ver.patch < 18) {
237 }
else if(std::strcmp(video_driver,
"wayland") == 0 && ver.patch < 20) {
252 case SDL_MULTIGESTURE:
269 if(event.type == SDL_KEYUP) {
281 const bool mouse_in_window =
286 double dx = 0.0, dy = 0.0;
288 int scroll_threshold =
prefs::get().mouse_scrolling()
293 if(m.get_location().contains(mousex, mousey)) {
294 scroll_threshold = 0;
299 auto tick_now = std::chrono::steady_clock::now();
304 dt = std::chrono::duration_cast<std::chrono::milliseconds>(tick_now -
last_scroll_tick_);
310 double scroll_amount = dt.count() * 0.036 * double(scroll_speed);
320 if(mouse_in_window) {
321 if(mousey < scroll_threshold) {
329 if(mousex < scroll_threshold) {
341 if((mouse_flags & SDL_BUTTON_MMASK) != 0 &&
prefs::get().middle_click_scrolls()) {
349 const double speed = 0.01 * scroll_amount;
350 const double snap_dist = 16;
351 const double x_diff = (mousex - original_loc.x);
352 const double y_diff = (mousey - original_loc.y);
354 if(std::fabs(x_diff) > snap_dist || std::fabs(y_diff) <= snap_dist) {
355 dx += speed * x_diff;
358 if(std::fabs(y_diff) > snap_dist || std::fabs(x_diff) <= snap_dist) {
359 dy += speed * y_diff;
376 point dist{int(dx), int(dy)};
406 show_menu(m, { menu_loc.x + 1, menu_loc.y + menu_loc.h + 1 },
false);
417 if(!str_vec.empty()) {
440 if(!menu || !cmd_exec) {
controller_base & controller_
void handle_event(const SDL_Event &event) override
bool handle_scroll(int mousex, int mousey, int mouse_flags)
Handle scrolling by keyboard, joystick and moving mouse near map edges.
virtual events::mouse_handler_base & get_mouse_handler_base()=0
Get a reference to a mouse handler member a derived class uses.
virtual ~controller_base()
virtual plugins_context * get_plugins_context()
Get (optionally) a plugins context a derived class uses.
virtual soundsource::manager * get_soundsource_man()
Get (optionally) a soundsources manager a derived class uses.
void handle_event(const SDL_Event &event) override
Process mouse- and keypress-events from SDL.
virtual void process_keyup_event(const SDL_Event &)
Process keyup (always).
bool show_menu(const theme::menu *menu, const point &loc, bool context_menu)
virtual void process() override
virtual void process_focus_keydown_event(const SDL_Event &)
Process keydown (only when the general map display does not have focus).
virtual bool have_keyboard_focus()
Derived classes should override this to return false when arrow keys should not scroll the map,...
virtual void execute_action(const std::vector< std::string > &items_arg)
virtual void process_keydown_event(const SDL_Event &)
Process keydown (always).
virtual display & get_display()=0
Get a reference to a display member a derived class uses.
void long_touch_callback(int x, int y)
std::size_t long_touch_timer_
Context menu timer.
virtual std::vector< std::string > additional_actions_pressed()
virtual hotkey::command_executor * get_hotkey_command_executor()
Optionally get a command executor to handle context menu events.
virtual void play_slice()
std::chrono::steady_clock::time_point last_scroll_tick_
virtual bool is_browsing() const
const theme::action * action_pressed()
const theme::menu * menu_pressed()
const map_location & mouseover_hex() const
bool scroll(const point &amount, bool force=false)
Scrolls the display by amount pixels.
virtual int drag_threshold() const
Minimum dragging distance to fire the drag&drop.
void touch_motion_event(const SDL_TouchFingerEvent &event, const bool browse)
virtual void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
void mouse_update(const bool browse, map_location loc)
Update the mouse with a fake mouse motion.
void mouse_motion_event(const SDL_MouseMotionEvent &event, const bool browse)
bool scroll_started() const
bool get_show_menu() const
virtual void mouse_wheel(int xscroll, int yscroll, bool browse)
Called when scrolling with the mouse wheel.
const point get_scroll_start() const
void set_scroll_start(int x, int y)
Called when the middle click scrolling.
virtual void show_menu(const std::vector< config > &items_arg, const point &menu_loc, bool context_menu)
void execute_quit_command()
void execute_action(const std::vector< std::string > &items_arg)
bool get_scroll_when_mouse_outside(bool def)
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
const std::vector< std::string > & items() const
static const auto long_touch_duration
static lg::log_domain log_display("display")
controller_base framework: controller_base is roughly analogous to a "dialog" class in a GUI toolkit ...
map_display and display: classes which take care of displaying the map and game-data on the screen.
Standard logging facilities (interface).
void draw()
Trigger a draw cycle.
void raise_process_event()
void pump()
Process all events currently in the queue.
bool is_touch(const SDL_MouseButtonEvent &event)
Check if this mouse button event is caused by a touch.
Game configuration data as global variables.
std::chrono::milliseconds popup_show_delay
Delay before a popup shows.
bool is_in_dialog()
Is a dialog open?
std::size_t add_timer(const std::chrono::milliseconds &interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
bool remove_timer(const std::size_t id)
Removes a timer.
bool execute_timer(const std::size_t id)
Executes a timer.
void jhat_event(const SDL_Event &event, command_executor *executor)
void key_event(const SDL_Event &event, command_executor *executor)
void mbutton_event(const SDL_Event &event, command_executor *executor)
void run_events(command_executor *executor)
void jbutton_event(const SDL_Event &event, command_executor *executor)
void keyup_event(const SDL_Event &, command_executor *executor)
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.
bool window_has_mouse_focus()
True iff the window has mouse focus.
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
rect game_canvas()
The game canvas area, in drawing coordinates.
This file contains the settings handling of the widget library.
Encapsulates the map of the game.
An abstract description of a rectangle with integer coordinates.
Contains the gui2 timer routines.