33 #define ERR_DP LOG_STREAM(err, log_display) 44 , scroll_right_(false)
45 , key_release_listener_(*this)
46 , last_mouse_is_touch_(false)
47 , long_touch_timer_(0)
64 uint32_t mouse_state = SDL_GetMouseState(&x_now, &y_now);
66 #ifdef MOUSE_TOUCH_EMULATION 67 if(mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
69 mouse_state = SDL_BUTTON(SDL_BUTTON_LEFT);
77 bool yes_actually_dragging = dx * dx + dy * dy >= threshold * threshold;
79 if(!yes_actually_dragging
80 && (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) {
155 if(new_event.motion.which != SDL_TOUCH_MOUSEID) {
159 if(new_event.motion.which != SDL_TOUCH_MOUSEID) {
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:
192 case SDL_MOUSEBUTTONUP:
208 int x =
static_cast<int>(
reinterpret_cast<std::intptr_t
>(
event.user.data1));
209 int y =
static_cast<int>(
reinterpret_cast<std::intptr_t
>(
event.user.data2));
210 if(event.user.code == static_cast<int>(SDL_TOUCH_MOUSEID)
229 #if defined(_WIN32) || defined(__APPLE__) 241 case SDL_MULTIGESTURE:
258 if(event.type == SDL_KEYUP) {
270 const bool mouse_in_window =
283 scroll_threshold = 0;
294 if(mouse_in_window) {
295 if(mousey < scroll_threshold) {
303 if(mousex < scroll_threshold) {
324 const double speed = 0.04 * std::sqrt(static_cast<double>(scroll_speed));
325 const double snap_dist = 16;
326 const double x_diff = (mousex - original_loc.x);
327 const double y_diff = (mousey - original_loc.y);
329 if(std::fabs(x_diff) > snap_dist || std::fabs(y_diff) <= snap_dist) {
330 dx += speed * x_diff;
333 if(std::fabs(y_diff) > snap_dist || std::fabs(x_diff) <= snap_dist) {
334 dy += speed * y_diff;
379 if(!str_vec.empty()) {
387 uint8_t mouse_flags = SDL_GetMouseState(&mousex, &mousey);
405 const std::vector<config>& items_arg,
int xloc,
int yloc,
bool context_menu,
display& disp)
412 std::vector<config>
items;
413 for(
const config&
c : items_arg) {
414 const std::string&
id =
c[
"id"];
418 items.emplace_back(
"id",
id);
426 cmd_exec->
show_menu(items, xloc, yloc, context_menu, disp);
436 std::vector<std::string>
items;
437 for(
const std::string&
item : items_arg) {
440 items.push_back(
item);
458 if(theme_name.empty()) {
466 ERR_DP <<
"Theme '" << theme_name <<
"' not found. Trying the default theme." << std::endl;
472 ERR_DP <<
"Default theme not found." << std::endl;
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.
virtual SDL_Rect & location(const SDL_Rect &screen) const
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
HOTKEY_COMMAND id
the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the objec...
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?
static const config & get_theme(const game_config_view &game_config, std::string theme_name)
Stores all information related to functions that can be bound to hotkeys.
void touch_motion_event(const SDL_TouchFingerEvent &event, const bool browse)
virtual void play_slice(bool is_delay_enabled=true)
static CVideo & get_singleton()
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.
const std::vector< std::string > items
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 ...
virtual bool have_keyboard_focus()
Derived classes should override this to return false when arrow keys should not scroll the map...
virtual bool can_execute_command(const hotkey_command &command, int index=-1) const =0
virtual std::vector< std::string > additional_actions_pressed()
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.
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...
int get_width(bool as_pixels=true) const
Returns the window renderer width in pixels or screen coordinates.
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.
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
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)
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Contains the gui2 timer routines.
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.
int get_height(bool as_pixels=true) const
Returns the window renderer height in pixels or in screen coordinates.
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.
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
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 display & gui()=0
Reference to the used display objects.
Standard logging facilities (interface).
CVideo & video()
Gets the underlying screen object.
const menu * context_menu() const
static void delay(unsigned int milliseconds)
Waits a given number of milliseconds before returning.
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.
bool window_has_flags(uint32_t flags) const
Tests whether the given flags are currently set on the SDL window.
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.