mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 12:10:25 +00:00
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
This commit is contained in:
parent
c38da99039
commit
f1eae0eec7
@ -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 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
||||
, 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 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
||||
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 @@ void editor_controller::init(CVideo& video)
|
||||
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 @@ editor_controller::~editor_controller()
|
||||
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 @@ void editor_controller::hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
|
||||
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 @@ mouse_action* editor_controller::get_mouse_action()
|
||||
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,17 +771,21 @@ void editor_controller::refresh_after_action(bool drag_part)
|
||||
|
||||
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()
|
||||
{
|
||||
get_map_context().undo();
|
||||
|
@ -114,12 +114,16 @@ class editor_controller : public controller_base,
|
||||
/** 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,9 +155,12 @@ class editor_controller : public controller_base,
|
||||
|
||||
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_;
|
||||
map_fragment clipboard_;
|
||||
|
@ -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 @@ void editor_display::rebuild_terrain(const gamemap::location &loc) {
|
||||
builder_.rebuild_terrain(loc);
|
||||
}
|
||||
|
||||
void editor_display::redraw_everything() {
|
||||
|
||||
}
|
||||
|
||||
void editor_display::pre_draw()
|
||||
{
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "../display.hpp"
|
||||
|
||||
namespace editor2 {
|
||||
|
||||
|
||||
class editor_display : public display
|
||||
{
|
||||
public:
|
||||
@ -33,6 +33,7 @@ public:
|
||||
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();
|
||||
/**
|
||||
|
@ -34,6 +34,7 @@ class mouse_action
|
||||
{
|
||||
public:
|
||||
mouse_action()
|
||||
: toolbar_button_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -55,9 +56,15 @@ public:
|
||||
* 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user