00001 /* $Id: mouse_handler_base.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2006 - 2012 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de> 00004 wesnoth playturn Copyright (C) 2003 by David White <dave@whitevine.net> 00005 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY. 00013 00014 See the COPYING file for more details. 00015 */ 00016 00017 #ifndef MOUSE_HANDLER_BASE_H_INCLUDED 00018 #define MOUSE_HANDLER_BASE_H_INCLUDED 00019 00020 #include "map_location.hpp" 00021 #include "SDL.h" 00022 00023 class display; 00024 00025 namespace events { 00026 00027 struct command_disabler 00028 { 00029 command_disabler(); 00030 ~command_disabler(); 00031 }; 00032 00033 extern int commands_disabled; 00034 00035 class mouse_handler_base { 00036 public: 00037 mouse_handler_base(); 00038 virtual ~mouse_handler_base() {} 00039 00040 /** 00041 * Reference to the used display objects. Derived classes should ensure 00042 * this is always valid. Note the constructor of this class cannot use this. 00043 */ 00044 virtual display& gui() = 0; 00045 00046 /** 00047 * Const version. 00048 */ 00049 virtual const display& gui() const = 0; 00050 00051 /** 00052 * @return true when the class in the "dragging" state. 00053 */ 00054 bool is_dragging() const; 00055 00056 //minimum dragging distance to fire the drag&drop 00057 virtual int drag_threshold() const {return 0;}; 00058 00059 void mouse_motion_event(const SDL_MouseMotionEvent& event, const bool browse); 00060 00061 /** update the mouse with a fake mouse motion */ 00062 void mouse_update(const bool browse, map_location loc); 00063 00064 bool get_show_menu() const { return show_menu_; } 00065 00066 /** 00067 * This handles minimap scrolling and click-drag. 00068 * @returns true when the caller should not process the mouse motion 00069 * further (i.e. should return), false otherwise. 00070 */ 00071 bool mouse_motion_default(int x, int y, bool update); 00072 00073 /** 00074 * Called when a mouse motion event takes place. Derived classes mustprovide an 00075 * implementation, possibly using mouse_motion_default(). 00076 */ 00077 virtual void mouse_motion(int x, int y, const bool browse, bool update=false, map_location new_loc = map_location::null_location) = 0; 00078 00079 virtual void mouse_press(const SDL_MouseButtonEvent& event, const bool browse); 00080 bool is_left_click(const SDL_MouseButtonEvent& event) const; 00081 bool is_middle_click(const SDL_MouseButtonEvent& event) const; 00082 bool is_right_click(const SDL_MouseButtonEvent& event) const; 00083 00084 /** 00085 * Derived classes can overrid this to disable mousewheel scrolling under 00086 * some circumstances, e.g. when the mouse wheel controls something else, 00087 * but the event is also received by this class 00088 */ 00089 virtual bool allow_mouse_wheel_scroll(int x, int y); 00090 00091 /** 00092 * Overridden in derived classes, called on a left click (mousedown). 00093 * Defaults to process (initiate) minimap scrolling. 00094 * @returns true when the click should not process the event further. 00095 * This means do not treat the call as a start of drag movement. 00096 * FIXME: This return value is currently ignored 00097 */ 00098 virtual bool left_click(int x, int y, const bool browse); 00099 00100 /** 00101 * Called whenever the left mouse drag has "ended". 00102 */ 00103 virtual void left_drag_end(int x, int y, const bool browse); 00104 00105 /** 00106 * Called when the left mouse button is up 00107 */ 00108 virtual void left_mouse_up(int x, int y, const bool browse); 00109 00110 /** 00111 * Overridden in derived classes, called on a right click (mousedown). 00112 * Defaults to displaying the menu (by setting the appropriate flag) 00113 * if right_click_show_menu returns true. 00114 * @returns true when the click should not process the event further. 00115 * This means do not treat the call as a start of drag movement. 00116 */ 00117 virtual bool right_click(int x, int y, const bool browse); 00118 00119 /** 00120 * Called in the default right_click when the context menu is about to 00121 * be shown, can be used for preprocessing and preventing the menu from 00122 * being displayed without rewriting the right click function. 00123 * @returns true when the menu should be displayed and false otherwise 00124 * FIXME: This return value is currently ignored 00125 */ 00126 virtual bool right_click_show_menu(int x, int y, const bool browse); 00127 00128 /** 00129 * Called whenever the right mouse drag has "ended". 00130 */ 00131 virtual void right_drag_end(int x, int y, const bool browse); 00132 00133 /** 00134 * Called when the right mouse button is up 00135 */ 00136 virtual void right_mouse_up(int x, int y, const bool browse); 00137 00138 protected: 00139 void cancel_dragging(); 00140 void clear_dragging(const SDL_MouseButtonEvent& event, bool browse); 00141 void init_dragging(bool& dragging_flag); 00142 00143 /** MMB click (on game map) state flag */ 00144 bool simple_warp_; 00145 /** minimap scrolling (scroll-drag) state flag */ 00146 bool minimap_scrolling_; 00147 /** LMB drag init flag */ 00148 bool dragging_left_; 00149 /** Actual drag flag */ 00150 bool dragging_started_; 00151 /** RMB drag init flag */ 00152 bool dragging_right_; 00153 /** Drag start position x */ 00154 int drag_from_x_; 00155 /** Drag start position y */ 00156 int drag_from_y_; 00157 /** Drag start map location */ 00158 map_location drag_from_hex_; 00159 00160 /** last highlighted hex */ 00161 map_location last_hex_; 00162 00163 /** Show context menu flag */ 00164 bool show_menu_; 00165 }; 00166 00167 } // end namespace events 00168 00169 #endif
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:05 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |