1 #pragma once 2 #ifndef DRAG_WIDGET_HPP_INCLUDED 3 #define DRAG_WIDGET_HPP_INCLUDED 4 #ifndef NO_EDITOR 5 6 #include <boost/function.hpp> 7 #include <boost/shared_ptr.hpp> 8 9 #include "geometry.hpp" 10 #include "widget.hpp" 11 12 namespace gui 13 { 14 15 typedef boost::shared_ptr<SDL_Cursor> cursor_ptr; 16 17 class drag_widget : public widget 18 { 19 public: 20 enum drag_direction {DRAG_HORIZONTAL, DRAG_VERTICAL}; 21 explicit drag_widget(const int x, const int y, const int w, const int h, 22 const drag_direction dir, 23 boost::function<void(int, int)> drag_start, 24 boost::function<void(int, int)> drag_end, 25 boost::function<void(int, int)> drag_move); 26 explicit drag_widget(const variant&, game_logic::formula_callable* e); 27 28 private: 29 void init(); 30 void handle_draw() const; 31 bool handle_event(const SDL_Event& event, bool claimed); 32 bool handle_mousedown(const SDL_MouseButtonEvent& event, bool claimed); 33 bool handle_mouseup(const SDL_MouseButtonEvent& event, bool claimed); 34 bool handle_mousemotion(const SDL_MouseMotionEvent& event, bool claimed); 35 rect get_border_rect() const; 36 rect get_dragger_rect() const; 37 38 int x_, y_, w_, h_; 39 boost::function<void(int, int)> drag_start_; 40 boost::function<void(int, int)> drag_end_; 41 boost::function<void(int, int)> drag_move_; 42 43 // delegates 44 void drag(int dx, int dy); 45 void drag_start(int x, int y); 46 void drag_end(int x, int y); 47 // FFL formulas 48 game_logic::formula_ptr drag_handler_; 49 game_logic::formula_ptr drag_start_handler_; 50 game_logic::formula_ptr drag_end_handler_; 51 52 widget_ptr dragger_; 53 drag_direction dir_; 54 SDL_Cursor *old_cursor_; 55 cursor_ptr drag_cursor_; 56 57 point start_pos_; 58 int dragging_handle_; 59 }; 60 61 typedef boost::intrusive_ptr<drag_widget> drag_widget_ptr; 62 63 } 64 65 #endif // NO_EDITOR 66 #endif // DRAG_WIDGET_HPP_INCLUDED 67