Author: ilor
Date: Sun Aug 10 22:52:32 2008
New Revision: 28449

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28449&view=rev
Log:
Editor2: 
* use display redraw observers to redraw the palettes (this is a quick fix for 
something that needs a larger redesign)
* draw current tool outline
* make the refresh_all more thorough

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

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28449&r1=28448&r2=28449&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sun Aug 10 22:52:32 2008
@@ -41,6 +41,8 @@
 
 #include "SDL.h"
 
+#include <boost/bind.hpp>
+
 namespace editor2 {
 
 editor_controller::editor_controller(const config &game_config, CVideo& video)
@@ -48,7 +50,7 @@
 , mouse_handler_base(get_map())
 , map_context_(editor_map(game_config, 44, 33, t_translation::GRASS_LAND))
 , gui_(NULL), map_generator_(NULL), do_quit_(false), quit_mode_(EXIT_ERROR)
-, auto_update_transitions_(true)
+, toolbar_dirty_(true), auto_update_transitions_(true)
 {
        init(video);
        floating_label_manager_ = new font::floating_label_context();
@@ -79,6 +81,14 @@
                new mouse_action_starting_position()));
        mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
                new mouse_action_paste(clipboard_)));
+       foreach (const theme::menu& menu, gui().get_theme().menus()) {
+               if (menu.items().size() == 1) {
+                       mouse_action_map::iterator i = 
mouse_actions_.find(hotkey::get_hotkey(menu.items().front()).get_id());
+                       if (i != mouse_actions_.end()) {
+                               i->second->set_toolbar_button(&menu);
+                       }
+               }
+       }                       
        hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);      
        
        background_terrain_ = t_translation::GRASS_LAND;
@@ -101,6 +111,7 @@
        gui_ = new editor_display(video, get_map(), *theme_cfg, game_config_, 
config());
        gui_->set_grid(preferences::grid());
        prefs_disp_manager_ = new preferences::display_manager(gui_);
+       
gui_->add_redraw_observer(boost::bind(&editor_controller::display_redraw_callback,
 this, _1));
 }
 
 editor_controller::~editor_controller()
@@ -110,8 +121,7 @@
        delete floating_label_manager_;
        delete map_generator_;
     delete gui_;
-       typedef std::pair<hotkey::HOTKEY_COMMAND, mouse_action*> apr;
-       foreach (apr a, mouse_actions_) {
+       foreach (const mouse_action_map::value_type a, mouse_actions_) {
                delete a.second;
        }       
        delete prefs_disp_manager_;
@@ -660,6 +670,7 @@
        std::map<hotkey::HOTKEY_COMMAND, mouse_action*>::iterator i = 
mouse_actions_.find(command);
        if (i != mouse_actions_.end()) {
                mouse_action_ = i->second;
+               redraw_toolbar();
                gui().set_report_content(reports::EDIT_LEFT_BUTTON_FUNCTION,
                                hotkey::get_hotkey(command).get_description());
                gui().invalidate_game_status();         
@@ -695,7 +706,29 @@
        return mouse_action_;
 }
 
-void editor_controller::refresh_image_cache() {
+void editor_controller::redraw_toolbar()
+{
+       foreach (mouse_action_map::value_type a, mouse_actions_) {
+               if (a.second->toolbar_button() != NULL) {
+                       SDL_Rect r = 
a.second->toolbar_button()->location(gui().screen_area());
+                       SDL_Rect outline = {r.x - 2, r.y - 2, r.h + 4, r.w + 4};
+                       //outline = intersect_rects(r, gui().screen_area());
+                       SDL_Surface* const screen = gui().video().getSurface();
+                       Uint32 color;
+                       if (a.second == mouse_action_) {
+                               color = SDL_MapRGB(screen->format, 0xFF, 0x00, 
0x00);
+                       } else {
+                               color = SDL_MapRGB(screen->format, 0x00, 0x00, 
0x00);
+                       }
+                       draw_rectangle(outline.x, outline.y, outline.w, 
outline.h, color, gui().video().getSurface());
+                       update_rect(outline);
+               }
+       }
+       toolbar_dirty_ = false;
+}
+
+void editor_controller::refresh_image_cache()
+{
        image::flush_cache();
        refresh_all();
 }
@@ -738,15 +771,19 @@
 
 void editor_controller::refresh_all()
 {
-       adjust_sizes(gui(), *size_specs_);
-       //brush_bar_->adjust_size();
-       palette_->draw(true);
-       //brush_bar_->draw(true);
        gui().rebuild_all();
-       gui().invalidate_all();
+       gui().redraw_everything();
        gui().recalculate_minimap();
        get_map_context().set_needs_terrain_rebuild(false);
        get_map_context().clear_changed_locations();
+}
+
+void editor_controller::display_redraw_callback(display&)
+{
+       adjust_sizes(gui(), *size_specs_);
+       palette_->adjust_size();
+       palette_->draw(true);
+       gui().invalidate_all();
 }
 
 void editor_controller::undo()

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28449&r1=28448&r2=28449&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Sun Aug 10 22:52:32 2008
@@ -114,11 +114,15 @@
                /** init the display object and general set-up */ 
                void init(CVideo& video);
                
+               void redraw_toolbar();
+               
                void refresh_image_cache();
                
                void refresh_after_action(bool drag_part = false);
                
                void refresh_all();
+               
+               void display_redraw_callback(display&);
                
                /**
                 * Un-does an action, and puts it in the redo stack for a 
possible redo
@@ -151,8 +155,11 @@
                
                std::vector<brush> brushes_;
                brush* brush_;
-               std::map<hotkey::HOTKEY_COMMAND, mouse_action*> mouse_actions_;
+               typedef std::map<hotkey::HOTKEY_COMMAND, mouse_action*> 
mouse_action_map;
+               mouse_action_map mouse_actions_;
                mouse_action* mouse_action_;
+               
+               bool toolbar_dirty_;
                
                t_translation::t_terrain foreground_terrain_;
                t_translation::t_terrain background_terrain_;           

Modified: trunk/src/editor2/editor_display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_display.cpp?rev=28449&r1=28448&r2=28449&view=diff
==============================================================================
--- trunk/src/editor2/editor_display.cpp (original)
+++ trunk/src/editor2/editor_display.cpp Sun Aug 10 22:52:32 2008
@@ -19,7 +19,7 @@
 #include <cassert>
 
 namespace editor2 {
-       
+
 editor_display::editor_display(CVideo& video, const editor_map& map,
                const config& theme_cfg, const config& cfg,
                const config& level) :
@@ -57,6 +57,9 @@
         builder_.rebuild_terrain(loc);
 }
 
+void editor_display::redraw_everything() {
+       
+}
 
 void editor_display::pre_draw()
 {

Modified: trunk/src/editor2/editor_display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_display.hpp?rev=28449&r1=28448&r2=28449&view=diff
==============================================================================
--- trunk/src/editor2/editor_display.hpp (original)
+++ trunk/src/editor2/editor_display.hpp Sun Aug 10 22:52:32 2008
@@ -18,7 +18,7 @@
 #include "../display.hpp"
 
 namespace editor2 {
-       
+
 class editor_display : public display
 {
 public:
@@ -33,6 +33,7 @@
        void remove_brush_loc(const gamemap::location& hex);
        const editor_map& map() const { return static_cast<const 
editor_map&>(map_); }
        void rebuild_terrain(const gamemap::location &loc);
+       void redraw_everything();
 protected:
        void pre_draw();
        /**

Modified: trunk/src/editor2/mouse_action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.hpp?rev=28449&r1=28448&r2=28449&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Sun Aug 10 22:52:32 2008
@@ -34,6 +34,7 @@
 {
 public:
        mouse_action()
+       : toolbar_button_(NULL)
        {
        }
 
@@ -55,9 +56,15 @@
         * The end of dragging.
         */
        virtual editor_action* drag_end(editor_display& disp, int x, int y);
+       
+       void set_toolbar_button(const theme::menu* value) { toolbar_button_ = 
value; }
+       const theme::menu* toolbar_button() const { return toolbar_button_; }
 
 protected:
        gamemap::location previous_move_hex_;
+       
+private:
+       const theme::menu* toolbar_button_;
 };
 
 class brush_drag_mouse_action : public mouse_action


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

Reply via email to