Made the editor brushbar configurable by theme WML...

...instead of being hardcoded.
This commit is contained in:
Fabian Müller 2012-07-09 16:18:13 +00:00
parent b9b015ec86
commit afead1632d
5 changed files with 51 additions and 33 deletions

View file

@ -174,15 +174,15 @@
# yanchor=fixed
# [/menu]
# [menu]
# id=menu-editor-side
# title= _ "Side"
# image=lite_small
# items=editor-switch-side,editor-side-new,editor-side-modify
# rect="+2,=,+55,="
# xanchor=fixed
# yanchor=fixed
# [/menu]
[menu]
id=menu-editor-side
title= _ "Side"
image=lite_small
items=editor-switch-side,editor-side-new #,editor-side-modify
rect="+2,=,+55,="
xanchor=fixed
yanchor=fixed
[/menu]
# [panel]
# #TODO rename since we don't display turns, only sides
@ -422,24 +422,30 @@
yanchor=fixed
[/menu]
[brush_bar]
id=brush-bar
ref=bottom-right-panel
rect="=+10,=+0,+250,+30"
xanchor=right
yanchor=top
[/brush_bar]
[menu]
id=menu-editor-terrain
title= _ "Group"
image=lite_small
font_size=9
items=editor-palette-groups
ref=bottom-right-panel
rect="=+16,=+2,+55,+18"
ref=brush-bar
rect="=+6,+7,+55,+18"
xanchor=right
yanchor=fixed
[/menu]
[panel]
id=villages-panel
image=themes/status-bg.png
ref=menu-editor-window
#ref=menu-editor-side
ref=menu-editor-side
#ref=turn-panel
rect="+5,=+1,+71,+19"
xanchor=fixed
@ -600,6 +606,15 @@
yanchor=fixed
[/menu]
[palette]
id=palette
ref=menu-editor-terrain
rect="=-5,+7,+250,+465"
xanchor=right
yanchor=top
[/palette]
[/resolution]
[partialresolution]

View file

@ -38,6 +38,8 @@ 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

@ -27,17 +27,18 @@
namespace editor {
brush_bar::brush_bar(display &gui, const size_specs &sizes,
std::vector<brush>& brushes, brush** the_brush)
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui),
selected_(0), brushes_(brushes), the_brush_(the_brush),
size_(30) {
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(size_specs_.brush_x -1, size_specs_.brush_y -1);
set_measurements(size_ * brushes_.size() + (brushes_.size() -1) * (size_specs_.brush_padding) + 2, (size_ +2));
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();
}
@ -109,7 +110,7 @@ void brush_bar::draw(bool force) {
|| static_cast<unsigned>(image->h) != size_) {
image.assign(scale_surface(image, size_, size_));
}
SDL_Rect dstrect = create_rect(x, size_specs_.brush_y, image->w, image->h);
SDL_Rect dstrect = create_rect(x, gui_.brush_bar_area().y, image->w, image->h);
sdl_blit(image, NULL, screen, &dstrect);
const Uint32 color = i == selected_brush_size() ?
SDL_MapRGB(screen->format,0xFF,0x00,0x00) :
@ -117,25 +118,25 @@ void brush_bar::draw(bool force) {
//TODO fendrin
//draw_rectangle(dstrect.x -1, dstrect.y -1, image->w +2, image->h+2, color, screen);
draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, color, screen);
x += image->w + size_specs_.brush_padding;
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 = size_specs_.brush_x;
const int bar_y = size_specs_.brush_y;
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() * size_specs_.brush_padding) ||
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 * size_specs_.brush_padding;
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;
}

View file

@ -21,16 +21,15 @@
#ifndef BRUSH_BAR_H_INCLUDED
#define BRUSH_BAR_H_INCLUDED
#include "../../display.hpp"
#include "../editor_display.hpp"
#include "brush.hpp"
#include "editor/palette/palette_layout.hpp"
namespace editor {
/** A bar where the brush is drawn */
class brush_bar : public gui::widget {
public:
brush_bar(display &gui, const size_specs &sizes, std::vector<brush>& brushes, brush** the_brush);
brush_bar(editor_display &gui, std::vector<brush>& brushes, brush** the_brush);
/** Return the size of currently selected brush. */
unsigned int selected_brush_size();
@ -62,12 +61,13 @@ private:
/** 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;
const size_specs &size_specs_;
display &gui_;
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

View file

@ -70,7 +70,7 @@ void editor_toolkit::init_sidebar(const config& game_config)
{
size_specs_.reset(new size_specs());
adjust_sizes(gui_, *size_specs_);
brush_bar_.reset(new brush_bar(gui_, *size_specs_, brushes_, &brush_));
brush_bar_.reset(new brush_bar(gui_, brushes_, &brush_));
palette_manager_.reset(new palette_manager(gui_, *size_specs_, game_config, &mouse_action_));
}