Author: ilor
Date: Sun Jul  6 17:27:36 2008
New Revision: 27784

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27784&view=rev
Log:
Make editor2 editor_controller derive from controller_base and use 
editor_mouse_handler

Modified:
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_controller.hpp

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=27784&r1=27783&r2=27784&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sun Jul  6 17:27:36 2008
@@ -23,8 +23,10 @@
 namespace editor2 {
 
 editor_controller::editor_controller(const config &game_config, CVideo& video)
-: game_config_(game_config), map_(editor_map::new_map(game_config, 44, 33, 
t_translation::GRASS_LAND))
+: controller_base(SDL_GetTicks(), game_config, video)
+, map_(editor_map::new_map(game_config, 44, 33, t_translation::GRASS_LAND))
 , gui_(NULL)
+, mouse_handler_(gui_, map_)
 {
        init(video);
        gui_->invalidate_game_status();
@@ -40,6 +42,7 @@
        const config* theme_cfg = get_theme(game_config_, "editor2");
        theme_cfg = theme_cfg ? theme_cfg : &dummy;
        gui_ = new editor_display(video, map_, *theme_cfg, game_config_, 
config());
+       mouse_handler_.set_gui(gui_);
 }
 
 editor_controller::~editor_controller()
@@ -50,89 +53,23 @@
 void editor_controller::main_loop()
 {
        for(;;) {
-               int mousex, mousey;
-               const int scroll_speed = preferences::scroll_speed();
-               Uint8 mouse_flags = SDL_GetMouseState(&mousex,&mousey);
-               const bool l_button_down = (0 != (mouse_flags & 
SDL_BUTTON_LMASK));
-               const bool r_button_down = (0 != (mouse_flags & 
SDL_BUTTON_RMASK));
-               const bool m_button_down = (0 != (mouse_flags & 
SDL_BUTTON_MMASK));
-
-               const gamemap::location cur_hex = 
gui_->hex_clicked_on(mousex,mousey);
-               const theme::menu* const m = gui_->menu_pressed();
-               if (m != NULL) {
-                       const SDL_Rect& menu_loc = 
m->location(gui_->screen_area());
-                       const int x = menu_loc.x + 1;
-                       const int y = menu_loc.y + menu_loc.h + 1;
-//                     show_menu(m->items(), x, y, false);
-               }
-
-               if(key_[SDLK_UP] || mousey == 0) {
-                       gui_->scroll(0,-scroll_speed);
-               }
-               if(key_[SDLK_DOWN] || mousey == gui_->h()-1) {
-                       gui_->scroll(0,scroll_speed);
-               }
-               if(key_[SDLK_LEFT] || mousex == 0) {
-                       gui_->scroll(-scroll_speed,0);
-               }
-               if(key_[SDLK_RIGHT] || mousex == gui_->w()-1) {
-                       gui_->scroll(scroll_speed,0);
-               }
-
-               if (l_button_down) {
-//                     left_button_down(mousex, mousey);
-               }
-               else {
-//                     if (l_button_held_func_ == MOVE_SELECTION) {
-                               // When it is detected that the mouse is no 
longer down
-                               // and we are in the progress of moving a 
selection,
-                               // perform the movement.
-//                             perform_selection_move();
-//                     }
-               }
-               if (r_button_down) {
-//                     right_button_down(mousex, mousey);
-               }
-               if (m_button_down) {
-//                     middle_button_down(mousex, mousey);
-               }
-
-               gui_->draw(true, true);
-               events::raise_draw_event();
-
-               // When the map has changed, wait until the left mouse button
-               // is not held down, and then update the minimap and
-               // the starting position labels.
-//             if (map_dirty_) {
-//                     if (!l_button_down && !r_button_down) {
-//                             if (auto_update_) {
-//                                     gui_.rebuild_all();
-//                                     gui_.invalidate_all();
-//                                     map_dirty_ = false;
-//                             }
-                               //gui_.recalculate_minimap();
-//                             recalculate_starting_pos_labels();
-//                     }
-//             }
-               gui_->update_display();
-               SDL_Delay(20);
-               events::pump();
-//             if (everything_dirty_) {
-//                     redraw_everything();
-//                     everything_dirty_ = false;
-//             }
-//             if (abort_ == ABORT_NORMALLY) {
-//                     if (!confirm_exit_and_save()) {
-//                             set_abort(DONT_ABORT);
-//                     }
-//             }
-//             mouse_moved_ = false;
+               play_slice();
        }
 }
 
-bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND, int) const
+bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND, int 
/*index*/) const
 {
        return false;
 }
-       
+
+editor_mouse_handler& editor_controller::get_mouse_handler_base()
+{
+       return mouse_handler_;
+}
+
+editor_display& editor_controller::get_display()
+{
+       return *gui_;
+}
+
 } //end namespace editor2

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=27784&r1=27783&r2=27784&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Sun Jul  6 17:27:36 2008
@@ -15,39 +15,41 @@
 #define EDITOR2_EDITOR_CONTROLLER_HPP_INCLUDED
 
 #include "editor_common.hpp"
+#include "editor_display.hpp"
 #include "editor_map.hpp"
-#include "editor_display.hpp"
+#include "editor_mouse_handler.hpp"
+
+#include "../config.hpp"
+#include "../controller_base.hpp"
+#include "../events.hpp"
+#include "../hotkeys.hpp"
+#include "../key.hpp"
+#include "../sdl_utils.hpp"
 
 #include <boost/utility.hpp>
 
-#include "../key.hpp"
-#include "../config.hpp"
-#include "../events.hpp"
-#include "../hotkeys.hpp"
-#include "../sdl_utils.hpp"
-
 namespace editor2 {
 
-class editor_controller : public events::handler, public 
hotkey::command_executor,
+class editor_controller : public controller_base,
                private boost::noncopyable
 {
        public:
                editor_controller(const config &game_config, CVideo& video);
                ~editor_controller();
                void main_loop();
-               bool can_execute_command(hotkey::HOTKEY_COMMAND, int) const;
-               void handle_event(const SDL_Event&){}
+               bool can_execute_command(hotkey::HOTKEY_COMMAND, int index = 
-1) const;
+       protected:
+               editor_mouse_handler& get_mouse_handler_base();
+               editor_display& get_display();  
        private:    
                /** init the display object and general set-up */ 
                void init(CVideo& video);
-               /** cref to the main game config */
-               const config& game_config_;
                /** The current map object */
                editor_map map_;
                /** The display object used and owned by the editor. Possibly 
recreated when a new map is created */
                editor_display* gui_;
+               editor_mouse_handler mouse_handler_;
                
-               CKey key_;
         bool map_dirty_;
 };
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to