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);
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"];
457 items.emplace_back(
"id",
id);
465 cmd_exec->
show_menu(items, xloc, yloc, context_menu, disp);
475 std::vector<std::string>
items;
476 for(
const std::string&
item : items_arg) {
479 items.push_back(
item);
virtual bool in_context_menu(hotkey::HOTKEY_COMMAND command) const
const map_location & mouseover_hex() const
virtual plugins_context * get_plugins_context()
Get (optionally) a plugins context a derived class uses.
const SDL_Point get_scroll_start() const
virtual void process_keyup_event(const SDL_Event &)
Process keyup (always).
static const int long_touch_duration_ms
void set_scroll_start(int x, int y)
Called when the middle click scrolling.
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
static lg::log_domain log_display("display")
virtual int drag_threshold() const
Minimum dragging distance to fire the drag&drop.
virtual void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &disp)
bool is_in_dialog()
Is a dialog open?
Stores all information related to functions that can be bound to hotkeys.
const std::vector< std::string > items
uint32_t last_scroll_tick_
void touch_motion_event(const SDL_TouchFingerEvent &event, const bool browse)
virtual void play_slice(bool is_delay_enabled=true)
void mbutton_event(const SDL_Event &event, command_executor *executor)
virtual display & get_display()=0
Get a reference to a display member a derived class uses.
HOTKEY_COMMAND command
The command associated with this hotkey.
void mouse_motion_event(const SDL_MouseMotionEvent &event, const bool browse)
controller_base framework: controller_base is roughly analogous to a "dialog" class in a GUI toolkit ...
rect map_area() const
Returns the area used for the map.
virtual bool have_keyboard_focus()
Derived classes should override this to return false when arrow keys should not scroll the map...
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
virtual bool can_execute_command(const hotkey_command &command, int index=-1) const =0
virtual std::vector< std::string > additional_actions_pressed()
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
const theme::action * action_pressed()
void run_events(command_executor *executor)
virtual void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
virtual soundsource::manager * get_soundsource_man()
Get (optionally) a soundsources manager a derived class uses.
rect game_canvas()
The game canvas area, in drawing coordinates.
virtual bool is_browsing() const
std::string get(const std::string &key)
bool scroll_started() const
void jbutton_event(const SDL_Event &event, command_executor *executor)
const theme::menu * menu_pressed()
void execute_quit_command()
bool last_mouse_is_touch_
void handle_event(const SDL_Event &event) override
virtual void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
void keyup_event(const SDL_Event &, command_executor *executor)
void handle_event(const SDL_Event &event) override
Process mouse- and keypress-events from SDL.
map_display and display: classes which take care of displaying the map and game-data on the screen...
const std::vector< std::string > & items() const
virtual ~controller_base()
void jhat_event(const SDL_Event &event, command_executor *executor)
virtual events::mouse_handler_base & get_mouse_handler_base()=0
Get a reference to a mouse handler member a derived class uses.
void pump()
Process all events currently in the queue.
virtual void process(events::pump_info &) override
virtual void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu)
Encapsulates the map of the game.
virtual void process_keydown_event(const SDL_Event &)
Process keydown (always).
#define DOUBLE_CLICK_EVENT
void raise_process_event()
virtual void process_focus_keydown_event(const SDL_Event &)
Process keydown (only when the general map display does not have focus).
Game configuration data as global variables.
bool get_show_menu() const
bool middle_click_scrolls()
void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
Contains the gui2 timer routines.
An abstract description of a rectangle with integer coordinates.
virtual void mouse_wheel(int xscroll, int yscroll, bool browse)
Called when scrolling with the mouse wheel.
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 window_has_mouse_focus()
True iff the window has mouse focus.
size_t long_touch_timer_
Context menu timer.
void key_event(const SDL_Event &event, command_executor *executor)
bool handle_scroll(int mousex, int mousey, int mouse_flags)
Handle scrolling by keyboard, joystick and moving mouse near map edges.
bool window_is_visible()
True iff the window is not hidden.
void long_touch_callback(int x, int y)
virtual hotkey::command_executor * get_hotkey_command_executor()
Optionally get a command executor to handle context menu events.
bool mouse_scroll_enabled()
virtual rect & location(const SDL_Rect &screen) const
uint32_t get_mouse_state(int *x, int *y)
A wrapper for SDL_GetMouseState that gives coordinates in draw space.
virtual display & gui()=0
Reference to the used display objects.
Standard logging facilities (interface).
const menu * context_menu() const
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
A config object defines a single node in a WML file, with access to child nodes.
Class that keeps track of all the keys on the keyboard.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
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.
void draw()
Trigger a draw cycle.
bool execute_timer(const std::size_t id)
Executes a timer.
std::pair< std::string, unsigned > item
bool remove_timer(const std::size_t id)
Removes a timer.