36 #define ERR_DP LOG_STREAM(err, log_display)
47 , scroll_right_(false)
48 , last_scroll_tick_(0)
49 , scroll_carry_x_(0.0)
50 , scroll_carry_y_(0.0)
51 , key_release_listener_(*this)
52 , last_mouse_is_touch_(false)
53 , long_touch_timer_(0)
72 #ifdef MOUSE_TOUCH_EMULATION
73 if(mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
75 mouse_state = SDL_BUTTON(SDL_BUTTON_LEFT);
83 bool yes_actually_dragging = dx * dx + dy * dy >= threshold * threshold;
85 if(!yes_actually_dragging
86 && (mouse_state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0
107 SDL_Event new_event = {};
116 case SDL_TEXTEDITING:
118 SDL_Event evt = event;
119 evt.type = SDL_TEXTINPUT;
122 SDL_StartTextInput();
130 if(event.key.keysym.sym == SDLK_ESCAPE) {
148 case SDL_JOYBUTTONDOWN:
152 case SDL_JOYHATMOTION:
156 case SDL_MOUSEMOTION:
158 if(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
159 while(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
161 if(new_event.motion.which != SDL_TOUCH_MOUSEID) {
165 if(new_event.motion.which != SDL_TOUCH_MOUSEID) {
171 case SDL_FINGERMOTION:
172 if(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_FINGERMOTION, SDL_FINGERMOTION) > 0) {
173 while(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_FINGERMOTION, SDL_FINGERMOTION) > 0) {
181 case SDL_MOUSEBUTTONDOWN:
198 case SDL_MOUSEBUTTONUP:
214 int x =
static_cast<int>(
reinterpret_cast<std::intptr_t
>(
event.user.data1));
215 int y =
static_cast<int>(
reinterpret_cast<std::intptr_t
>(
event.user.data2));
216 if(event.user.code ==
static_cast<int>(SDL_TOUCH_MOUSEID)
235 #if defined(_WIN32) || defined(__APPLE__)
247 case SDL_MULTIGESTURE:
264 if(event.type == SDL_KEYUP) {
276 const bool mouse_in_window =
281 double dx = 0.0, dy = 0.0;
288 if(m.get_location().contains(mousex, mousey)) {
289 scroll_threshold = 0;
294 uint32_t tick_now = SDL_GetTicks();
303 double scroll_amount = double(dt) * 0.036 * double(
scroll_speed);
313 if(mouse_in_window) {
314 if(mousey < scroll_threshold) {
322 if(mousex < scroll_threshold) {
343 const double speed = 0.01 * scroll_amount;
344 const double snap_dist = 16;
345 const double x_diff = (mousex - original_loc.x);
346 const double y_diff = (mousey - original_loc.y);
348 if(std::fabs(x_diff) > snap_dist || std::fabs(y_diff) <= snap_dist) {
349 dx += speed * x_diff;
352 if(std::fabs(y_diff) > snap_dist || std::fabs(x_diff) <= snap_dist) {
353 dy += speed * y_diff;
371 int dx_int = int(dx);
372 int dy_int = int(dy);
412 execute_action(
a->items(), action_loc.x + 1, action_loc.y + action_loc.h + 1,
false);
418 if(!str_vec.empty()) {
444 const std::vector<config>& items_arg,
int xloc,
int yloc,
bool context_menu,
display& disp)
451 std::vector<config>
items;
452 for(
const config&
c : items_arg) {
453 const std::string&
id =
c[
"id"];
475 std::vector<std::string>
items;
476 for(
const std::string&
item : items_arg) {
Class that keeps track of all the keys on the keyboard.
A config object defines a single node in a WML file, with access to child nodes.
controller_base & controller_
void handle_event(const SDL_Event &event) override
uint32_t last_scroll_tick_
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.
size_t long_touch_timer_
Context menu timer.
virtual soundsource::manager * get_soundsource_man()
Get (optionally) a soundsources manager a derived class uses.
virtual bool in_context_menu(const hotkey::ui_command &cmd) const
virtual void play_slice(bool is_delay_enabled=true)
void handle_event(const SDL_Event &event) override
Process mouse- and keypress-events from SDL.
virtual void process(events::pump_info &) override
virtual void process_keyup_event(const SDL_Event &)
Process keyup (always).
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,...
bool last_mouse_is_touch_
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)
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 show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &disp)
virtual bool is_browsing() const
virtual void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu)
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
const theme::action * action_pressed()
const theme::menu * menu_pressed()
rect map_area() const
Returns the area used for the map.
const map_location & mouseover_hex() const
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.
virtual display & gui()=0
Reference to the used display objects.
void mouse_motion_event(const SDL_MouseMotionEvent &event, const bool browse)
bool scroll_started() const
const SDL_Point get_scroll_start() const
bool get_show_menu() const
virtual void mouse_wheel(int xscroll, int yscroll, bool browse)
Called when scrolling with the mouse wheel.
void set_scroll_start(int x, int y)
Called when the middle click scrolling.
void execute_quit_command()
void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
virtual void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
virtual bool can_execute_command(const hotkey::ui_command &command) const =0
const menu * context_menu() const
static lg::log_domain log_display("display")
static const int long_touch_duration_ms
controller_base framework: controller_base is roughly analogous to a "dialog" class in a GUI toolkit ...
#define DOUBLE_CLICK_EVENT
Standard logging facilities (interface).
void draw()
Trigger a draw cycle.
void raise_process_event()
void pump()
Process all events currently in the queue.
Game configuration data as global variables.
std::size_t add_timer(const uint32_t interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
bool is_in_dialog()
Is a dialog open?
bool remove_timer(const std::size_t id)
Removes a timer.
bool execute_timer(const std::size_t id)
Executes a timer.
std::pair< std::string, unsigned > item
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)
const std::vector< std::string > items
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
bool mouse_scroll_enabled()
bool middle_click_scrolls()
std::string get(const std::string &key)
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.
bool window_is_visible()
True iff the window is not hidden.
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.
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to ex...
Encapsulates the map of the game.
An abstract description of a rectangle with integer coordinates.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
Contains the gui2 timer routines.