Make editor2 editor_controller derive from controller_base...

...and use editor_mouse_handler
This commit is contained in:
Tomasz Śniatowski 2008-07-06 16:27:36 +01:00
parent 5f7ae302c7
commit 5926df106a
2 changed files with 32 additions and 93 deletions

View File

@ -23,8 +23,10 @@
namespace editor2 { namespace editor2 {
editor_controller::editor_controller(const config &game_config, CVideo& video) 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) , gui_(NULL)
, mouse_handler_(gui_, map_)
{ {
init(video); init(video);
gui_->invalidate_game_status(); gui_->invalidate_game_status();
@ -40,6 +42,7 @@ void editor_controller::init(CVideo& video)
const config* theme_cfg = get_theme(game_config_, "editor2"); const config* theme_cfg = get_theme(game_config_, "editor2");
theme_cfg = theme_cfg ? theme_cfg : &dummy; theme_cfg = theme_cfg ? theme_cfg : &dummy;
gui_ = new editor_display(video, map_, *theme_cfg, game_config_, config()); gui_ = new editor_display(video, map_, *theme_cfg, game_config_, config());
mouse_handler_.set_gui(gui_);
} }
editor_controller::~editor_controller() editor_controller::~editor_controller()
@ -50,89 +53,23 @@ editor_controller::~editor_controller()
void editor_controller::main_loop() void editor_controller::main_loop()
{ {
for(;;) { for(;;) {
int mousex, mousey; play_slice();
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;
} }
} }
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; 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 } //end namespace editor2

View File

@ -15,39 +15,41 @@
#define EDITOR2_EDITOR_CONTROLLER_HPP_INCLUDED #define EDITOR2_EDITOR_CONTROLLER_HPP_INCLUDED
#include "editor_common.hpp" #include "editor_common.hpp"
#include "editor_map.hpp"
#include "editor_display.hpp" #include "editor_display.hpp"
#include "editor_map.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 <boost/utility.hpp>
#include "../key.hpp"
#include "../config.hpp"
#include "../events.hpp"
#include "../hotkeys.hpp"
#include "../sdl_utils.hpp"
namespace editor2 { namespace editor2 {
class editor_controller : public events::handler, public hotkey::command_executor, class editor_controller : public controller_base,
private boost::noncopyable private boost::noncopyable
{ {
public: public:
editor_controller(const config &game_config, CVideo& video); editor_controller(const config &game_config, CVideo& video);
~editor_controller(); ~editor_controller();
void main_loop(); void main_loop();
bool can_execute_command(hotkey::HOTKEY_COMMAND, int) const; bool can_execute_command(hotkey::HOTKEY_COMMAND, int index = -1) const;
void handle_event(const SDL_Event&){} protected:
editor_mouse_handler& get_mouse_handler_base();
editor_display& get_display();
private: private:
/** init the display object and general set-up */ /** init the display object and general set-up */
void init(CVideo& video); void init(CVideo& video);
/** cref to the main game config */
const config& game_config_;
/** The current map object */ /** The current map object */
editor_map map_; editor_map map_;
/** The display object used and owned by the editor. Possibly recreated when a new map is created */ /** The display object used and owned by the editor. Possibly recreated when a new map is created */
editor_display* gui_; editor_display* gui_;
editor_mouse_handler mouse_handler_;
CKey key_;
bool map_dirty_; bool map_dirty_;
}; };