Removed all (except some project files I don't dare to touch) remains of

the old brush_bar and put the new solution in place.
This commit is contained in:
fendrin 2013-04-01 15:13:16 +02:00
parent c9eabcdadc
commit 370b002906
15 changed files with 76 additions and 285 deletions

View file

@ -1,25 +0,0 @@
src/editor/action/action.cpp
src/editor/action/action_label.cpp
src/editor/action/action_unit.cpp
src/editor/action/action_village.cpp
src/editor/action/mouse/mouse_action.cpp
src/editor/action/mouse/mouse_action_map_label.cpp
src/editor/action/mouse/mouse_action_unit.cpp
src/editor/editor_controller.cpp
src/editor/editor_display.cpp
src/editor/editor_main.cpp
src/editor/map/context_manager.cpp
src/editor/map/editor_map.cpp
src/editor/map/map_context.cpp
src/editor/map/map_fragment.cpp
src/editor/palette/editor_palettes.cpp
src/editor/palette/palette_manager.cpp
src/editor/palette/terrain_palettes.cpp
src/editor/palette/unit_palette.cpp
src/editor/toolkit/brush_bar.cpp
src/editor/toolkit/brush.cpp
src/gui/dialogs/editor_generate_map.cpp
src/gui/dialogs/editor_new_map.cpp
src/gui/dialogs/editor_resize_map.cpp
src/gui/dialogs/editor_set_starting_position.cpp
src/gui/dialogs/editor_settings.cpp

View file

@ -664,7 +664,6 @@ set(wesnoth-main_SRC
editor/map/map_fragment.cpp
editor/palette/palette_manager.cpp
editor/toolkit/brush.cpp
editor/toolkit/brush_bar.cpp
editor/palette/editor_palettes.cpp
editor/palette/terrain_palettes.cpp
editor/palette/unit_palette.cpp

View file

@ -237,12 +237,11 @@ wesnoth_sources = Split("""
editor/palette/terrain_palettes.cpp
editor/palette/unit_palette.cpp
editor/palette/palette_manager.cpp
editor/toolkit/brush.cpp
editor/toolkit/brush_bar.cpp
editor/editor_controller.cpp
editor/editor_display.cpp
editor/editor_main.cpp
editor/editor_preferences.cpp
editor/toolkit/brush.cpp
editor/toolkit/editor_toolkit.cpp
filechooser.cpp
floating_textbox.cpp

View file

@ -268,9 +268,17 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_EDITOR_MAP_LOAD:
case HOTKEY_EDITOR_MAP_SAVE_AS:
case HOTKEY_EDITOR_BRUSH_NEXT:
return true;
case HOTKEY_EDITOR_BRUSH_1:
case HOTKEY_EDITOR_BRUSH_2:
case HOTKEY_EDITOR_BRUSH_3:
case HOTKEY_EDITOR_BRUSH_NW_SE:
case HOTKEY_EDITOR_BRUSH_SE_NW:
return toolkit_->get_mouse_action()->supports_brushes();
case HOTKEY_EDITOR_TOOL_NEXT:
case HOTKEY_EDITOR_PALETTE_ITEM_SWAP:
return true; //editor hotkeys we can always do
return true;
case HOTKEY_EDITOR_MAP_SAVE:
case HOTKEY_EDITOR_MAP_SAVE_ALL:
case HOTKEY_EDITOR_SWITCH_MAP:
@ -330,6 +338,18 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND command, int index) const {
using namespace hotkey;
switch (command) {
case HOTKEY_EDITOR_BRUSH_1:
return toolkit_->is_active_brush("brush-1") ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_BRUSH_2:
return toolkit_->is_active_brush("brush-2") ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_BRUSH_3:
return toolkit_->is_active_brush("brush-3") ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_BRUSH_NW_SE:
return toolkit_->is_active_brush("brush-nw-se") ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_BRUSH_SE_NW:
return toolkit_->is_active_brush("brush-se-nw") ? ACTION_ON : ACTION_OFF;
case HOTKEY_ZOOM_DEFAULT:
return (gui_->get_zoom_factor() == 1.0) ? ACTION_ON : ACTION_OFF;
case HOTKEY_TOGGLE_GRID:
@ -458,6 +478,23 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_BRUSH_NEXT:
toolkit_->cycle_brush();
return true;
case HOTKEY_EDITOR_BRUSH_1:
toolkit_->set_brush("brush-1");
return true;
case HOTKEY_EDITOR_BRUSH_2:
toolkit_->set_brush("brush-2");
return true;
case HOTKEY_EDITOR_BRUSH_3:
toolkit_->set_brush("brush-3");
return true;
case HOTKEY_EDITOR_BRUSH_NW_SE:
toolkit_->set_brush("brush-nw-se");
return true;
case HOTKEY_EDITOR_BRUSH_SE_NW:
toolkit_->set_brush("brush-se-nw");
return true;
case HOTKEY_EDITOR_COPY:
copy_selection();
return true;

View file

@ -37,8 +37,6 @@ public:
void set_toolbar_hint(const std::string& value) { toolbar_hint_ = value; }
void set_palette_report(const config& palette_report) {palette_report_ = palette_report;};
const SDL_Rect& brush_bar_area() const
{ return theme_.brush_bar_location(screen_area()); }
protected:
void pre_draw();

View file

@ -61,14 +61,14 @@ namespace editor {
brush::brush()
: relative_tiles_()
, name_()
, image_()
, id_()
{
}
brush::brush(const config& cfg)
: relative_tiles_()
, name_(cfg["name"])
, image_(cfg["image"])
, id_(cfg["id"])
{
int radius = cfg["radius"];
if (radius > 0) {

View file

@ -55,7 +55,7 @@ public:
/**
* @return the image of this brush
*/
const std::string image() const { return image_; }
const std::string id() const { return id_; }
protected:
/**
@ -64,7 +64,7 @@ protected:
std::set<map_location> relative_tiles_;
std::string name_;
std::string image_;
std::string id_;
};

View file

@ -1,142 +0,0 @@
/*
Copyright (C) 2003 - 2013 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* Manage the brush bar in the editor.
* Note: this is a near-straight rip from the old editor.
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "brush_bar.hpp"
#include "sound.hpp"
namespace editor {
brush_bar::brush_bar(editor_display &gui, std::vector<brush>& brushes, brush** the_brush)
: gui::widget(gui.video()), gui_(gui),
selected_(0), brushes_(brushes), the_brush_(the_brush),
size_(30) {
adjust_size();
}
void brush_bar::adjust_size() {
set_location(gui_.brush_bar_area());
//TODO
//set_location(size_specs_.brush_x -1, size_specs_.brush_y -1);
set_measurements(size_ * brushes_.size() + (brushes_.size() -1) * (brush_padding_) + 2, (size_ +2));
set_dirty();
}
unsigned int brush_bar::selected_brush_size() {
return selected_;
}
void brush_bar::left_mouse_click(const int mousex, const int mousey) {
sound::play_UI_sound(game_config::sounds::button_press);
int index = selected_index(mousex, mousey);
if(index >= 0) {
if (static_cast<size_t>(index) != selected_) {
set_dirty();
selected_ = index;
*the_brush_ = &brushes_[index];
}
}
}
void brush_bar::handle_event(const SDL_Event& event) {
if (event.type == SDL_MOUSEMOTION) {
// If the mouse is inside the palette, give it focus.
if (point_in_rect(event.button.x, event.button.y, location())) {
if (!focus(&event)) {
set_focus(true);
}
}
// If the mouse is outside, remove focus.
else {
if (focus(&event)) {
set_focus(false);
}
}
}
if (!focus(&event)) {
return;
}
int mousex, mousey;
SDL_GetMouseState(&mousex,&mousey);
const SDL_MouseButtonEvent mouse_button_event = event.button;
if (mouse_button_event.type == SDL_MOUSEBUTTONDOWN) {
if (mouse_button_event.button == SDL_BUTTON_LEFT) {
left_mouse_click(mousex, mousey);
}
}
}
void brush_bar::draw() {
draw(false);
}
void brush_bar::draw(bool force) {
if (!dirty() && !force) {
return;
}
const SDL_Rect loc = location();
int x = loc.x;
// Everything will be redrawn even though only one little part may
// have changed, but that happens so seldom so we'll settle with this.
surface screen = gui_.video().getSurface();
for (size_t i = 0; i < brushes_.size(); i++) {
std::string filename = brushes_[i].image();
filename += ( i == selected_brush_size() ?
"-pressed.png" : ".png" );
surface image(image::get_image(filename));
if (image == NULL) {
ERR_ED << "Image " << filename << " not found." << std::endl;
continue;
}
if (static_cast<unsigned>(image->w) != size_
|| static_cast<unsigned>(image->h) != size_) {
image.assign(scale_surface(image, size_, size_));
}
SDL_Rect dstrect = create_rect(x, gui_.brush_bar_area().y, image->w, image->h);
sdl_blit(image, NULL, screen, &dstrect);
x += image->w + brush_padding_;
}
update_rect(loc);
set_dirty(false);
}
int brush_bar::selected_index(int x, int y) const {
const int bar_x = gui_.brush_bar_area().x;
const int bar_y = gui_.brush_bar_area().y;
if ((x < bar_x || static_cast<size_t>(x) > bar_x + size_ * brushes_.size() +
brushes_.size() * brush_padding_) ||
(y < bar_y || static_cast<size_t>(y) > bar_y + size_))
{
return -1;
}
for(size_t i = 0; i < brushes_.size(); i++) {
int px = bar_x + size_ * i + i * brush_padding_;
if (x >= px && x <= px + static_cast<int>(size_) && y >= bar_y && y <= bar_y + static_cast<int>(size_)) {
return i;
}
}
return -1;
}
}

View file

@ -1,73 +0,0 @@
/*
Copyright (C) 2003 - 2013 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* Manage the brush bar in the editor.
* Note: this is a near-straight rip from the old editor.
*/
#ifndef BRUSH_BAR_H_INCLUDED
#define BRUSH_BAR_H_INCLUDED
#include "../editor_display.hpp"
#include "brush.hpp"
namespace editor {
/** A bar where the brush is drawn */
class brush_bar : public gui::widget {
public:
brush_bar(editor_display &gui, std::vector<brush>& brushes, brush** the_brush);
/** Return the size of currently selected brush. */
unsigned int selected_brush_size();
/**
* Draw the palette. If force is true, everything
* will be redrawn, even though it is not dirty.
*/
void draw(bool force=false);
virtual void draw();
virtual void handle_event(const SDL_Event& event);
/**
* Update the size of this widget.
*
* Use if the size_specs have changed.
*/
void adjust_size();
private:
/**
* To be called when a mouse click occurs.
*
* Check if the coordinates is a terrain that may be chosen, and select the
* terrain if that is the case.
*/
void left_mouse_click(const int mousex, const int mousey);
/** Return the index of the brush that is at coordinates (x, y) in the panel. */
int selected_index(const int x, const int y) const;
editor_display &gui_;
unsigned int selected_;
std::vector<brush>& brushes_;
brush** the_brush_;
const size_t size_;
static const int brush_padding_ = 1;
};
} // end namespace editor
#endif // BRUSH_BAR_H_INCLUDED

View file

@ -34,7 +34,6 @@ editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key,
, mouse_action_hints_()
, brush_(NULL)
, brushes_()
, brush_bar_(NULL)
{
init_brushes(game_config);
init_sidebar(game_config);
@ -44,12 +43,10 @@ editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key,
editor_toolkit::~editor_toolkit()
{
//TODO ask someone about that
// BOOST_FOREACH(const mouse_action_map::value_type a, mouse_actions_) {
// delete a.second;
// }
//BOOST_FOREACH(const mouse_action_map::value_type a, mouse_actions_) {
// delete a.second;
//}
//delete palette_manager_.get();
//delete brush_bar_.get();
// delete brush_bar_.
}
void editor_toolkit::init_brushes(const config& game_config)
@ -67,7 +64,6 @@ void editor_toolkit::init_brushes(const config& game_config)
void editor_toolkit::init_sidebar(const config& game_config)
{
brush_bar_.reset(new brush_bar(gui_, brushes_, &brush_));
palette_manager_.reset(new palette_manager(gui_, game_config, &mouse_action_));
}
@ -119,8 +115,7 @@ void editor_toolkit::hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
mouse_action_ = i->second;
palette_manager_->adjust_size();
//TODO make active_palette() private again.
//palette_manager_->switch_palette();
/// @TODO make active_palette() private again.
gui_.set_palette_report(palette_manager_->active_palette().active_group_report());
set_mouseover_overlay();
@ -157,6 +152,15 @@ void editor_toolkit::clear_mouseover_overlay()
gui_.clear_mouseover_hex_overlay();
}
void editor_toolkit::set_brush(std::string id) {
BOOST_FOREACH(brush& i, brushes_) {
if (i.id() == id) {
brush_ = &i;
}
}
}
void editor_toolkit::cycle_brush()
{
if (brush_ == &brushes_.back()) {
@ -172,10 +176,6 @@ void editor_toolkit::adjust_size()
{
palette_manager_->adjust_size();
palette_manager_->draw(true);
brush_bar_->adjust_size();
brush_bar_->draw(true);
}

View file

@ -15,20 +15,18 @@
#ifndef EDITOR_TOOLKIT_H_INCLUDED
#define EDITOR_TOOLKIT_H_INCLUDED
//#include "../../display.hpp"
//#include "brush.hpp"
//#include "palette_layout.hpp"
#include "config.hpp"
#include <boost/scoped_ptr.hpp>
#include "editor/palette/palette_manager.hpp"
#include "hotkeys.hpp"
#include "editor/toolkit/brush_bar.hpp"
#include "editor/map/context_manager.hpp"
#include "editor/palette/palette_manager.hpp"
#include "editor/toolkit/brush.hpp"
#include "hotkeys.hpp"
#include <boost/scoped_ptr.hpp>
namespace editor {
/** A bar where the brush is drawn */
class editor_toolkit {
public:
@ -69,11 +67,17 @@ public:
/** Get the current mouse action */
mouse_action* get_mouse_action() { return mouse_action_; };
/** Brush related methods */
// Brush related methods
/** Cycle to the next brush. */
void cycle_brush();
/** TODO */
void set_brush(std::string id);
/** TODO */
bool is_active_brush(std::string id) const { return brush_->id() == id; };
palette_manager* get_palette_manager() { return palette_manager_.get(); };
private:
@ -82,7 +86,6 @@ private:
const CKey& key_;
/** TODO */
boost::scoped_ptr<palette_manager> palette_manager_;
//Tools
@ -106,9 +109,6 @@ private:
/** All available brushes */
std::vector<brush> brushes_;
/** The brush selector */
boost::scoped_ptr<brush_bar> brush_bar_;
};
}

View file

@ -167,6 +167,11 @@ const hotkey_command hotkey_list_[] = {
{ hotkey::HOTKEY_EDITOR_TOOL_VILLAGE, "editor-tool-village", N_("Village Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_NEXT, "editor-brush-next", N_("Next Brush"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_DEFAULT, "editor-brush-default", N_("Default Brush"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_1, "editor-brush-1", N_("Single Tile"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_2, "editor-brush-2", N_("Radius One"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_3, "editor-brush-3", N_("Radius Two"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_NW_SE, "editor-brush-nw-se", N_("Brush NW-SE"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_SE_NW, "editor-brush-se-nw", N_("Brush SE-NW"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_CUT, "editor-cut", N_("Cut"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_COPY, "editor-copy", N_("Copy"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_PASTE, "editor-paste", N_("Paste"), false, hotkey::SCOPE_EDITOR },

View file

@ -95,6 +95,7 @@ enum HOTKEY_COMMAND {
HOTKEY_EDITOR_TOOL_SELECT, HOTKEY_EDITOR_TOOL_STARTING_POSITION, HOTKEY_EDITOR_TOOL_LABEL,
HOTKEY_EDITOR_TOOL_UNIT, HOTKEY_EDITOR_TOOL_VILLAGE,
HOTKEY_EDITOR_BRUSH_NEXT, HOTKEY_EDITOR_BRUSH_DEFAULT,
HOTKEY_EDITOR_BRUSH_1, HOTKEY_EDITOR_BRUSH_2, HOTKEY_EDITOR_BRUSH_3, HOTKEY_EDITOR_BRUSH_NW_SE, HOTKEY_EDITOR_BRUSH_SE_NW,
HOTKEY_EDITOR_CUT, HOTKEY_EDITOR_COPY, HOTKEY_EDITOR_PASTE,
HOTKEY_EDITOR_EXPORT_SELECTION_COORDS,
HOTKEY_EDITOR_SELECT_ALL, HOTKEY_EDITOR_SELECT_INVERSE,

View file

@ -535,7 +535,6 @@ theme::theme(const config& cfg, const SDL_Rect& screen) :
mini_map_(),
unit_image_(),
palette_(),
brush_bar_(),
border_()
{
config tmp;
@ -614,10 +613,6 @@ void theme::add_object(const config& cfg)
palette_ = object(c);
}
if (const config &c = cfg.child("brush_bar")) {
brush_bar_ = object(c);
}
if (const config &status_cfg = cfg.child("status"))
{
BOOST_FOREACH(const config::any_child &i, status_cfg.all_children_range()) {
@ -748,7 +743,6 @@ theme::object& theme::find_element(std::string id){
if (id == "main-map") { res = &main_map_; }
if (id == "mini-map") { res = &mini_map_; }
if (id == "palette") { res = &palette_; }
if (id == "brush-bar") { res = &brush_bar_; }
if (id == "unit-image") { res = &unit_image_; }
return *res;
}

View file

@ -218,8 +218,6 @@ public:
{ return unit_image_.location(screen); }
const SDL_Rect& palette_location(const SDL_Rect& screen) const
{ return palette_.location(screen); }
const SDL_Rect& brush_bar_location(const SDL_Rect& screen) const
{ return brush_bar_.location(screen); }
static void set_known_themes(const config* cfg);
static std::vector<std::string> get_known_themes();
@ -249,7 +247,7 @@ private:
std::map<std::string,status_item> status_;
object main_map_, mini_map_, unit_image_, palette_, brush_bar_;
object main_map_, mini_map_, unit_image_, palette_;
tborder border_;
};