Rewrite the config parser so we can use the resolution based system.
Converted the button class to use this system and did some cleanups for the button class. NOTE the canvas class now leaks memory, which will be fixed later.
This commit is contained in:
parent
e168e62f75
commit
6fc50d5327
7 changed files with 386 additions and 131 deletions
|
@ -24,9 +24,10 @@ namespace gui2 {
|
|||
void tbutton::set_width(const int width)
|
||||
{
|
||||
// resize canvasses
|
||||
canvas_up_.set_width(width);
|
||||
canvas_up_mouse_over_.set_width(width);
|
||||
canvas_down_.set_width(width);
|
||||
canvas_enabled_.set_width(width);
|
||||
canvas_disabled_.set_width(width);
|
||||
canvas_pressed_.set_width(width);
|
||||
canvas_focussed_.set_width(width);
|
||||
|
||||
// inherited
|
||||
tcontrol::set_width(width);
|
||||
|
@ -35,9 +36,10 @@ void tbutton::set_width(const int width)
|
|||
void tbutton::set_height(const int height)
|
||||
{
|
||||
// resize canvasses
|
||||
canvas_up_.set_height(height);
|
||||
canvas_up_mouse_over_.set_height(height);
|
||||
canvas_down_.set_height(height);
|
||||
canvas_enabled_.set_height(height);
|
||||
canvas_disabled_.set_height(height);
|
||||
canvas_pressed_.set_height(height);
|
||||
canvas_focussed_.set_height(height);
|
||||
|
||||
// inherited
|
||||
tcontrol::set_height(height);
|
||||
|
@ -47,14 +49,14 @@ void tbutton::mouse_down(const tevent_info& /*event*/, bool& /*handled*/)
|
|||
{
|
||||
DBG_GUI << "mouse down\n";
|
||||
|
||||
set_state(DOWN);
|
||||
set_state(PRESSED);
|
||||
}
|
||||
|
||||
void tbutton::mouse_up(const tevent_info& /*event*/, bool& /*handled*/)
|
||||
{
|
||||
DBG_GUI << "mouse up\n";
|
||||
|
||||
set_state(MOUSE_OVER);
|
||||
set_state(FOCUSSED);
|
||||
}
|
||||
|
||||
void tbutton::mouse_click(const tevent_info& /*event*/, bool& /*handled*/)
|
||||
|
@ -71,14 +73,14 @@ void tbutton::mouse_enter(const tevent_info& /*event*/, bool& /*handled*/)
|
|||
{
|
||||
DBG_GUI << "mouse enter\n";
|
||||
|
||||
set_state(MOUSE_OVER);
|
||||
set_state(FOCUSSED);
|
||||
}
|
||||
|
||||
void tbutton::mouse_leave(const tevent_info& /*event*/, bool& /*handled*/)
|
||||
{
|
||||
DBG_GUI << "mouse leave\n";
|
||||
|
||||
set_state(NORMAL);
|
||||
set_state(ENABLED);
|
||||
}
|
||||
|
||||
void tbutton::draw(surface& canvas)
|
||||
|
@ -88,25 +90,53 @@ void tbutton::draw(surface& canvas)
|
|||
SDL_Rect rect = get_rect();
|
||||
switch(state_) {
|
||||
|
||||
case NORMAL :
|
||||
canvas_up_.draw(true);
|
||||
SDL_BlitSurface(canvas_up_.surf(), 0, canvas, &rect);
|
||||
case ENABLED :
|
||||
DBG_GUI << "Enabled.\n";
|
||||
canvas_enabled_.draw(true);
|
||||
SDL_BlitSurface(canvas_enabled_.surf(), 0, canvas, &rect);
|
||||
break;
|
||||
|
||||
case DOWN :
|
||||
canvas_down_.draw(true);
|
||||
SDL_BlitSurface(canvas_down_.surf(), 0, canvas, &rect);
|
||||
case DISABLED :
|
||||
DBG_GUI << "Disabled.\n";
|
||||
canvas_disabled_.draw(true);
|
||||
SDL_BlitSurface(canvas_disabled_.surf(), 0, canvas, &rect);
|
||||
break;
|
||||
|
||||
case MOUSE_OVER :
|
||||
canvas_up_mouse_over_.draw(true);
|
||||
SDL_BlitSurface(canvas_up_mouse_over_.surf(), 0, canvas, &rect);
|
||||
case PRESSED :
|
||||
DBG_GUI << "Pressed.\n";
|
||||
canvas_pressed_.draw(true);
|
||||
SDL_BlitSurface(canvas_pressed_.surf(), 0, canvas, &rect);
|
||||
break;
|
||||
|
||||
case FOCUSSED :
|
||||
DBG_GUI << "Focussed.\n";
|
||||
canvas_focussed_.draw(true);
|
||||
SDL_BlitSurface(canvas_focussed_.surf(), 0, canvas, &rect);
|
||||
break;
|
||||
}
|
||||
|
||||
set_dirty(false);
|
||||
}
|
||||
|
||||
tpoint tbutton::get_best_size() const
|
||||
{
|
||||
if(definition_ == std::vector<tbutton_definition::tresolution>::const_iterator()) {
|
||||
return tpoint(get_button(definition())->default_width, get_button(definition())->default_height);
|
||||
} else {
|
||||
return tpoint(definition_->default_width, definition_->default_height);
|
||||
}
|
||||
}
|
||||
|
||||
void tbutton::set_best_size(const tpoint& origin)
|
||||
{
|
||||
resolve_definition();
|
||||
|
||||
set_x(origin.x);
|
||||
set_y(origin.y);
|
||||
set_width(definition_->default_width);
|
||||
set_height(definition_->default_height);
|
||||
}
|
||||
|
||||
void tbutton::set_state(tstate state)
|
||||
{
|
||||
if(state != state_) {
|
||||
|
@ -115,4 +145,16 @@ void tbutton::set_state(tstate state)
|
|||
}
|
||||
}
|
||||
|
||||
void tbutton::resolve_definition()
|
||||
{
|
||||
if(definition_ == std::vector<tbutton_definition::tresolution>::const_iterator()) {
|
||||
definition_ = get_button(definition());
|
||||
|
||||
canvas_enabled_ = definition_->enabled.canvas;
|
||||
canvas_disabled_ = definition_->disabled.canvas;
|
||||
canvas_pressed_ = definition_->pressed.canvas;
|
||||
canvas_focussed_ = definition_->focussed.canvas;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -27,13 +27,15 @@ class tbutton : public tcontrol
|
|||
{
|
||||
friend void load_settings();
|
||||
public:
|
||||
tbutton(const std::string& id) :
|
||||
tbutton() :
|
||||
tcontrol(),
|
||||
state_(NORMAL)
|
||||
canvas_enabled_(),
|
||||
canvas_disabled_(),
|
||||
canvas_pressed_(),
|
||||
canvas_focussed_(),
|
||||
state_(ENABLED),
|
||||
definition_()
|
||||
{
|
||||
canvas_up_.set_cfg(tbutton::default_enabled_draw_);
|
||||
canvas_up_mouse_over_.set_cfg(tbutton::default_mouse_over_draw_);
|
||||
canvas_down_.set_cfg(tbutton::default_pressed_draw_);
|
||||
}
|
||||
|
||||
virtual void set_width(const int width);
|
||||
|
@ -50,35 +52,28 @@ public:
|
|||
void draw(surface& canvas);
|
||||
|
||||
// note we should check whether the label fits in the button
|
||||
tpoint get_best_size() const { return tpoint(default_width_, default_height_); }
|
||||
tpoint get_best_size() const;
|
||||
|
||||
void set_best_size(const tpoint& origin)
|
||||
{
|
||||
set_x(origin.x);
|
||||
set_y(origin.y);
|
||||
set_width(default_width_);
|
||||
set_height(default_height_);
|
||||
}
|
||||
void set_best_size(const tpoint& origin);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
tcanvas
|
||||
canvas_up_,
|
||||
canvas_up_mouse_over_,
|
||||
canvas_down_;
|
||||
canvas_enabled_,
|
||||
canvas_disabled_,
|
||||
canvas_pressed_,
|
||||
canvas_focussed_;
|
||||
|
||||
static unsigned default_width_;
|
||||
static unsigned default_height_;
|
||||
static config default_enabled_draw_;
|
||||
static config default_mouse_over_draw_;
|
||||
static config default_pressed_draw_;
|
||||
|
||||
enum tstate { NORMAL, DOWN, MOUSE_OVER };
|
||||
enum tstate { ENABLED, DISABLED, PRESSED, FOCUSSED };
|
||||
|
||||
void set_state(tstate state);
|
||||
tstate state_;
|
||||
|
||||
std::vector<tbutton_definition::tresolution>::const_iterator definition_;
|
||||
|
||||
void resolve_definition();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -147,12 +147,18 @@ void tcanvas::parse_cfg(const config& cfg)
|
|||
|
||||
void tcanvas::clear_shapes()
|
||||
{
|
||||
// FIXME we copy pointers so we will get double frees, need to think about
|
||||
// whether or not to use intrusive pointers to handle this.
|
||||
// NOTE with the code disabled we don't get a double free but do leak the memory!!!
|
||||
#if 0
|
||||
|
||||
for(std::vector<tshape*>::iterator itor =
|
||||
shapes_.begin(); itor != shapes_.end(); ++itor) {
|
||||
|
||||
delete (*itor);
|
||||
}
|
||||
shapes_.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void tcanvas::tshape::put_pixel(unsigned start, Uint32 colour, unsigned w, unsigned x, unsigned y)
|
||||
|
|
|
@ -19,13 +19,17 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/parser.hpp"
|
||||
#include "serialization/preprocessor.hpp"
|
||||
#include "util.hpp"
|
||||
#include "video.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#define DBG_GUI LOG_STREAM(debug, widget)
|
||||
#define LOG_GUI LOG_STREAM(info, widget)
|
||||
|
@ -34,19 +38,20 @@
|
|||
|
||||
namespace gui2 {
|
||||
|
||||
namespace {
|
||||
|
||||
// config gui_;
|
||||
} // namespace
|
||||
|
||||
unsigned tbutton::default_width_ = 10;
|
||||
unsigned tbutton::default_height_ = 10;
|
||||
config tbutton::default_enabled_draw_ = config();
|
||||
config tbutton::default_mouse_over_draw_ = config();
|
||||
config tbutton::default_pressed_draw_ = config();
|
||||
unsigned screen_width = 0;
|
||||
unsigned screen_height = 0;
|
||||
|
||||
namespace {
|
||||
|
||||
//! Map with all known guis.
|
||||
std::map<std::string, tgui_definition> guis;
|
||||
|
||||
//! Points to the current gui.
|
||||
std::map<std::string, tgui_definition>::const_iterator current_gui = guis.end();
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
void load_settings()
|
||||
{
|
||||
LOG_GUI << "Init gui\n";
|
||||
|
@ -56,89 +61,205 @@ void load_settings()
|
|||
screen_width = rect.w;
|
||||
screen_height = rect.h;
|
||||
|
||||
config file;
|
||||
config cfg;
|
||||
const std::string& filename = "data/hardwired/gui.cfg";
|
||||
try {
|
||||
scoped_istream stream = preprocess_file(filename);
|
||||
read(file, *stream);
|
||||
read(cfg, *stream);
|
||||
} catch(config::error&) {
|
||||
ERR_GUI << "Could not read file '" << filename << "'\n";
|
||||
}
|
||||
|
||||
config* gui = file.child("gui");
|
||||
if(gui) {
|
||||
/*
|
||||
config* settings = gui->child("setting");
|
||||
if(settings) {
|
||||
const config::child_list& cfgs = cfg.get_children("gui");
|
||||
for(std::vector<config*>::const_iterator itor = cfgs.begin();
|
||||
itor != cfgs.end(); ++itor) {
|
||||
|
||||
} else {
|
||||
ERR_GUI << "[settings] not found in [gui].\n";
|
||||
}
|
||||
*/
|
||||
config* button = gui->child("button");
|
||||
if(button) {
|
||||
|
||||
tbutton::default_width_ = lexical_cast_default<unsigned>((*button)["width"]);
|
||||
tbutton::default_height_ = lexical_cast_default<unsigned>((*button)["height"]);
|
||||
|
||||
|
||||
config* state_enabled = button->child("state_enabled");
|
||||
if(state_enabled) {
|
||||
|
||||
config* draw = state_enabled->child("draw");
|
||||
|
||||
if(draw) {
|
||||
tbutton::default_enabled_draw_ = config(*draw);
|
||||
|
||||
DBG_GUI << "[gui][button][state_enabled][draw]" << tbutton::default_enabled_draw_;
|
||||
|
||||
} else {
|
||||
ERR_GUI << "[draw] not found in [gui][button][state_enabled].\n";
|
||||
}
|
||||
} else {
|
||||
ERR_GUI << "[state_enabled] not found in [gui][button].\n";
|
||||
}
|
||||
|
||||
config* state_mouse_over = button->child("state_mouse_over");
|
||||
if(state_mouse_over) {
|
||||
|
||||
config* draw = state_mouse_over->child("draw");
|
||||
|
||||
if(draw) {
|
||||
tbutton::default_mouse_over_draw_ = config(*draw);
|
||||
|
||||
DBG_GUI << "[gui][button][state_mouse_over][draw]" << tbutton::default_mouse_over_draw_;
|
||||
|
||||
} else {
|
||||
ERR_GUI << "[draw] not found in [gui][button][state_mouse_over].\n";
|
||||
}
|
||||
} else {
|
||||
ERR_GUI << "[state_mouse_over] not found in [gui][button].\n";
|
||||
}
|
||||
|
||||
config* state_down = button->child("state_down");
|
||||
if(state_down) {
|
||||
|
||||
config* draw = state_down->child("draw");
|
||||
|
||||
if(draw) {
|
||||
tbutton::default_pressed_draw_ = config(*draw);
|
||||
|
||||
DBG_GUI << "[gui][button][state_down][draw]" << tbutton::default_pressed_draw_;
|
||||
|
||||
} else {
|
||||
ERR_GUI << "[draw] not found in [gui][button][state_down].\n";
|
||||
}
|
||||
} else {
|
||||
ERR_GUI << "[state_down] not found in [gui][button].\n";
|
||||
}
|
||||
|
||||
} else {
|
||||
ERR_GUI << "[button] not found in [gui].\n";
|
||||
}
|
||||
} else {
|
||||
ERR_GUI << "[gui] not found.\n";
|
||||
std::pair<std::string, tgui_definition> child;
|
||||
child.first = child.second.read(**itor);
|
||||
guis.insert(child);
|
||||
}
|
||||
|
||||
VALIDATE(guis.find("default") != guis.end(), _ ("No default gui defined."));
|
||||
|
||||
current_gui = guis.find("default");
|
||||
}
|
||||
|
||||
const std::string& tgui_definition::read(const config& cfg)
|
||||
{
|
||||
/*WIKI
|
||||
* [gui]
|
||||
* The gui class contains the definitions of all widgets and windows used in
|
||||
* the game. The standard gui has the id 'default' and used as fallback it
|
||||
* another gui doesn't define a specific item. NOTE things might look odd when
|
||||
* that happens.
|
||||
*
|
||||
*
|
||||
* id = (string = "") Unique id for this gui (theme).
|
||||
* description = (t_string = "") Unique translatable name for this gui.
|
||||
*
|
||||
* [button_definition] The definitions of the buttons in this gui.
|
||||
* [/gui]
|
||||
*/
|
||||
id = cfg["id"];
|
||||
description = cfg["description"];
|
||||
|
||||
VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
|
||||
VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", "description"));
|
||||
|
||||
std::cerr << "Parsing gui " << id << '\n';
|
||||
|
||||
const config::child_list& button_cfgs = cfg.get_children("button_definition");
|
||||
for(std::vector<config*>::const_iterator itor = button_cfgs.begin();
|
||||
itor != button_cfgs.end(); ++itor) {
|
||||
|
||||
std::pair<std::string, tbutton_definition> child;
|
||||
child.first = child.second.read(**itor);
|
||||
buttons.insert(child);
|
||||
}
|
||||
|
||||
VALIDATE(buttons.find("default") != buttons.end(), _ ("No default button defined."));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
const std::string& tbutton_definition::read(const config& cfg)
|
||||
{
|
||||
/*WIKI
|
||||
* [button_definition]
|
||||
* The definition of a normal push button.
|
||||
*
|
||||
* id = (string = "") Unique id for this gui (theme).
|
||||
* description = (t_string = "") Unique translatable name for this gui.
|
||||
*
|
||||
* [resolution] The definitions of the button in various
|
||||
* resolutions.
|
||||
* [/button_definition]
|
||||
*/
|
||||
id = cfg["id"];
|
||||
description = cfg["description"];
|
||||
|
||||
VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
|
||||
VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", "description"));
|
||||
|
||||
std::cerr << "Parsing button " << id << '\n';
|
||||
|
||||
const config::child_list& cfgs = cfg.get_children("resolution");
|
||||
VALIDATE(!cfgs.empty(), _("No resolution defined."));
|
||||
for(std::vector<config*>::const_iterator itor = cfgs.begin();
|
||||
itor != cfgs.end(); ++itor) {
|
||||
|
||||
resolutions.push_back(tresolution(**itor));
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
tbutton_definition::tresolution::tresolution(const config& cfg) :
|
||||
window_width(lexical_cast_default<unsigned>(cfg["window_width"])),
|
||||
window_height(lexical_cast_default<unsigned>(cfg["window_height"])),
|
||||
min_width(lexical_cast_default<unsigned>(cfg["min_width"])),
|
||||
min_height(lexical_cast_default<unsigned>(cfg["min_height"])),
|
||||
default_width(lexical_cast_default<unsigned>(cfg["default_width"])),
|
||||
default_height(lexical_cast_default<unsigned>(cfg["default_height"])),
|
||||
max_width(lexical_cast_default<unsigned>(cfg["max_width"])),
|
||||
max_height(lexical_cast_default<unsigned>(cfg["max_height"])),
|
||||
text_extra_width(lexical_cast_default<unsigned>(cfg["text_extra_width"])),
|
||||
text_extra_height(lexical_cast_default<unsigned>(cfg["text_extra_height"])),
|
||||
text_font_size(lexical_cast_default<unsigned>(cfg["text_font_size"])),
|
||||
enabled(cfg.child("state_enabled")),
|
||||
disabled(cfg.child("state_disabled")),
|
||||
pressed(cfg.child("state_pressed")),
|
||||
focussed(cfg.child("state_focussed"))
|
||||
{
|
||||
/*WIKI
|
||||
* [resolution]
|
||||
* Depending on the resolution a widget can look different. Resolutions are
|
||||
* evaluated in order of appearance. The ''window_width'' and ''window_height''
|
||||
* are the upper limit this resolution is valid for. When one of the sizes
|
||||
* gets above the limit, the next resolution is selected. There's one special
|
||||
* case where both values are ''0''. This resolution always matches. (Resolution
|
||||
* definitions behind that one will never be picked.) This resolution can be
|
||||
* used as upper limit or if there's only one resolution.
|
||||
*
|
||||
* The default (and also minimum) size of a button is determined by two items,
|
||||
* the wanted default size and the size needed for the text. The size of the
|
||||
* text differs per used widget so needs to be determined per button.
|
||||
*
|
||||
* window_width = (unsigned = 0) Width of the application window.
|
||||
* window_height = (unsigned = 0)
|
||||
* Height of the application window.
|
||||
* min_width = (unsigned = 0) The minimum width of the widget.
|
||||
* min_height = (unsigned = 0) The minimum height of the widget.
|
||||
*
|
||||
* default_width = (unsigned = 0)
|
||||
* The default width of the widget.
|
||||
* default_height = (unsigned = 0)
|
||||
* The default height of the widget.
|
||||
*
|
||||
* max_width = (unsigned = 0) The maximum width of the widget.
|
||||
* max_height = (unsigned = 0) The maximum height of the widget.
|
||||
*
|
||||
* text_extra_width = (unsigned = 0)
|
||||
* The extra width needed to determine the
|
||||
* minimal size for the text.
|
||||
* text_extra_height = (unsigned = 0)
|
||||
* The extra height needed to determine the
|
||||
* minimal size for the text.
|
||||
* text_font_size = (unsigned =0)
|
||||
* The font size, which needs to be used to
|
||||
* determine the minimal size for the text.
|
||||
*
|
||||
* [state_enabled] Settings for the enabled state.
|
||||
* [state_disabled] Settings for the disabled state.
|
||||
* [state_pressed] Settings for the pressed state.
|
||||
* [state_focussed] Settings for the focussed state (happens
|
||||
* when the mouse moves over the button).
|
||||
*
|
||||
*
|
||||
* [/resolution]
|
||||
*/
|
||||
|
||||
std::cerr << "Parsing resolution "
|
||||
<< window_width << ", " << window_height << '\n';
|
||||
}
|
||||
|
||||
tbutton_definition::tresolution::tstate::tstate(const config* cfg) :
|
||||
canvas()
|
||||
{
|
||||
const config* draw = cfg ? cfg->child("draw") : 0;
|
||||
|
||||
VALIDATE(draw, _("No state or draw section defined."));
|
||||
|
||||
canvas.set_cfg(*draw);
|
||||
}
|
||||
|
||||
//tbutton_definition::tresolution*
|
||||
std::vector<tbutton_definition::tresolution>::const_iterator get_button(const std::string& definition)
|
||||
{
|
||||
std::map<std::string, tbutton_definition>::const_iterator
|
||||
button = current_gui->second.buttons.find(definition);
|
||||
|
||||
if(button == current_gui->second.buttons.end()) {
|
||||
button = current_gui->second.buttons.find("default");
|
||||
assert(button != current_gui->second.buttons.end());
|
||||
}
|
||||
|
||||
for(std::vector<tbutton_definition::tresolution>::const_iterator
|
||||
itor = button->second.resolutions.begin(),
|
||||
end = button->second.resolutions.end();
|
||||
itor != end;
|
||||
++itor) {
|
||||
|
||||
if(screen_width <= itor->window_width &&
|
||||
screen_height <= itor->window_height) {
|
||||
|
||||
return itor;
|
||||
} else if (itor == end) {
|
||||
return itor;
|
||||
}
|
||||
}
|
||||
|
||||
assert(false);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -18,10 +18,83 @@
|
|||
#ifndef __GUI_WIDGETS_SETTING_HPP_INCLUDED__
|
||||
#define __GUI_WIDGETS_SETTING_HPP_INCLUDED__
|
||||
|
||||
#include "gui/widgets/canvas.hpp"
|
||||
#include "tstring.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class config;
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
struct tbutton_definition
|
||||
{
|
||||
|
||||
std::string id;
|
||||
t_string description;
|
||||
|
||||
const std::string& read(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
{
|
||||
private:
|
||||
tresolution();
|
||||
|
||||
public:
|
||||
tresolution(const config& cfg);
|
||||
|
||||
unsigned window_width;
|
||||
unsigned window_height;
|
||||
|
||||
unsigned min_width;
|
||||
unsigned min_height;
|
||||
|
||||
unsigned default_width;
|
||||
unsigned default_height;
|
||||
|
||||
unsigned max_width;
|
||||
unsigned max_height;
|
||||
|
||||
unsigned text_extra_width;
|
||||
unsigned text_extra_height;
|
||||
unsigned text_font_size;
|
||||
|
||||
struct tstate
|
||||
{
|
||||
private:
|
||||
tstate();
|
||||
|
||||
public:
|
||||
tstate(const config* cfg);
|
||||
|
||||
tcanvas canvas;
|
||||
};
|
||||
|
||||
tstate enabled;
|
||||
tstate disabled;
|
||||
tstate pressed;
|
||||
tstate focussed;
|
||||
|
||||
};
|
||||
|
||||
std::vector<tresolution> resolutions;
|
||||
};
|
||||
|
||||
struct tgui_definition
|
||||
{
|
||||
std::string id;
|
||||
t_string description;
|
||||
|
||||
const std::string& read(const config& cfg);
|
||||
|
||||
std::map<std::string, tbutton_definition> buttons;
|
||||
};
|
||||
|
||||
std::vector<tbutton_definition::tresolution>::const_iterator get_button(const std::string& definition);
|
||||
|
||||
//! Loads the setting for the theme.
|
||||
void load_settings();
|
||||
|
||||
|
|
|
@ -334,7 +334,6 @@ tpoint tsizer::tchild::get_best_size()
|
|||
}
|
||||
|
||||
tcontrol::tcontrol(/*const int x, const int y, const int w, const int h*/) :
|
||||
twidget("") ,
|
||||
/* x_(x),
|
||||
y_(y),
|
||||
w_(w),
|
||||
|
|
|
@ -142,8 +142,9 @@ private:
|
|||
class twidget : public virtual tevent_executor
|
||||
{
|
||||
public:
|
||||
twidget(const std::string& id = "") :
|
||||
id_(id),
|
||||
twidget() :
|
||||
id_(""),
|
||||
definition_("default"),
|
||||
parent_(0),
|
||||
x_(-1),
|
||||
y_(-1),
|
||||
|
@ -156,7 +157,15 @@ public:
|
|||
twidget* parent() { return parent_; }
|
||||
void set_parent(twidget* parent) { parent_ = parent; }
|
||||
|
||||
const std::string id() const { return id_; }
|
||||
const std::string& id() const { return id_; }
|
||||
void set_id(const std::string& id) { id_ = id; }
|
||||
|
||||
const std::string& definition() const { return definition_; }
|
||||
|
||||
//! This should not be changed after the widget is shown, strange things
|
||||
//! might occur.
|
||||
void set_definition(const std::string& definition)
|
||||
{ definition_ = definition; }
|
||||
|
||||
// draw event does nothing by default, maybe make pure virtual later
|
||||
// fixme add force as parameter
|
||||
|
@ -220,7 +229,17 @@ protected:
|
|||
{ return ::create_rect( x_, y_, w_, h_ ); }
|
||||
|
||||
private:
|
||||
const std::string id_;
|
||||
//! The id is the unique name of the widget in a certain context. This is
|
||||
//! needed for certain widgets so the engine knows which widget is which.
|
||||
//! Eg it knows which button is pressed and thuswhich engine action is
|
||||
//! connected to the button.
|
||||
std::string id_;
|
||||
|
||||
//! The definition is the id of that widget class. Eg for a button it
|
||||
//! [button_definition]id. A button can have multiple definitions which all
|
||||
//! look different but for the engine still is a button.
|
||||
std::string definition_;
|
||||
|
||||
twidget* parent_;
|
||||
int x_, y_, w_, h_;
|
||||
bool dirty_;
|
||||
|
|
Loading…
Add table
Reference in a new issue