More refactoring, the window definition now inherits from the panel definition.

The window now uses the canvasses as defined in the control.
This commit is contained in:
Mark de Wever 2008-04-30 10:16:55 +00:00
parent a8fb9e9d9a
commit 35e48eba8a
4 changed files with 18 additions and 132 deletions

View file

@ -599,67 +599,20 @@ ttooltip_definition::tresolution::tresolution(const config& cfg) :
}
twindow_definition::twindow_definition(const config& cfg) :
tcontrol_definition(cfg)
tpanel_definition(cfg)
{
/*WIKI (FIXME cleanup)
* [window_definition]
* The definition of a normal push window.
/*WIKI
* @page = GUIToolkitWML
* @order = 1_widget_window
*
* id = (string = "") Unique id for this gui (theme).
* description = (t_string = "") Unique translatable name for this gui.
* == Window ==
*
* The definition of a window. A window is a kind of panel see the panel for
* which fields exist
*
* [resolution] The definitions of the window in various
* resolutions.
* [/window_definition]
*/
DBG_G_P << "Parsing window " << id << '\n';
load_resolutions<tresolution>(cfg.get_children("resolution"));
}
twindow_definition::tresolution::tresolution(const config& cfg) :
tresolution_definition_(cfg),
top_border(lexical_cast_default<unsigned>(cfg["top_border"])),
bottom_border(lexical_cast_default<unsigned>(cfg["bottom_border"])),
left_border(lexical_cast_default<unsigned>(cfg["left_border"])),
right_border(lexical_cast_default<unsigned>(cfg["right_border"])),
background(cfg.child("background")),
foreground(cfg.child("foreground"))
{
/*WIKI (FIXME cleanup)
* [resolution]
* 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 windows.
* min_height = (unsigned = 0) The minimum height of the windows.
*
* top_border = (unsigned = 0) The size which isn't used for the client area.
* bottom_border = (unsigned = 0)The size which isn't used for the client area.
* left_border = (unsigned = 0) The size which isn't used for the client area.
* right_border = (unsigned = 0) The size which isn't used for the client area.
*
* [background] The things drawn on the window before
* the widgets are drawn.
* [foreground] The things drawn on the window on top
* of the widgets.
*
* [/resolution]
*/
DBG_G_P << "Parsing resolution "
<< window_width << ", " << window_height << '\n';
}
twindow_definition::tresolution::tlayer::tlayer(const config* cfg) :
canvas()
{
const config* draw = cfg ? cfg->child("draw") : 0;
VALIDATE(draw, _("No layer or draw section defined."));
canvas.set_cfg(*draw);
}
tresolution_definition_* get_control(const std::string& control_type, const std::string& definition)

View file

@ -176,35 +176,9 @@ struct ttooltip_definition : public tcontrol_definition
};
};
struct twindow_definition : public tcontrol_definition
struct twindow_definition : public tpanel_definition
{
twindow_definition(const config& cfg);
struct tresolution : public tresolution_definition_
{
tresolution(const config& cfg);
unsigned top_border;
unsigned bottom_border;
unsigned left_border;
unsigned right_border;
struct tlayer
{
private:
tlayer();
public:
tlayer(const config* cfg);
tcanvas canvas;
};
tlayer background;
tlayer foreground;
};
};
struct tgui_definition

View file

@ -53,18 +53,20 @@ namespace gui2{
twindow::twindow(CVideo& video,
const int x, const int y, const int w, const int h) :
tpanel(false, 0),
tpanel(false),
tevent_handler(),
video_(video),
status_(NEW),
retval_(0),
need_layout_(true),
restorer_(),
canvas_background_(),
canvas_foreground_(),
// canvas_background_(),
// canvas_foreground_(),
tooltip_(),
help_popup_()
{
load_config();
set_x(x);
set_y(y);
set_width(w);
@ -75,21 +77,6 @@ twindow::twindow(CVideo& video,
help_popup_.set_definition("default");
help_popup_.set_visible(false);
load_config();
// FIXME hack to load config stuff here
const twindow_definition::tresolution* conf = dynamic_cast<const twindow_definition::tresolution*>(config());
assert(conf);
canvas_background_ = conf->background.canvas;
canvas_background_.set_width(get_width());
canvas_background_.set_height(get_height());
canvas_foreground_ = conf->foreground.canvas;
canvas_foreground_.set_width(get_width());
canvas_foreground_.set_height(get_height());
// End of hack
}
int twindow::show(const bool restore, void* /*flip_function*/)
@ -126,8 +113,8 @@ int twindow::show(const bool restore, void* /*flip_function*/)
screen = make_neutral_surface(restorer_);
canvas_background_.draw();
blit_surface(canvas_background_.surf(), 0, screen, 0);
canvas(0).draw();
blit_surface(canvas(0).surf(), 0, screen, 0);
}
#if 0
// Darkening for debugging redraw.
@ -145,8 +132,8 @@ int twindow::show(const bool restore, void* /*flip_function*/)
itor->draw(screen);
}
if(draw_foreground) {
canvas_foreground_.draw();
blit_surface(canvas_foreground_.surf(), 0, screen, 0);
canvas(1).draw();
blit_surface(canvas(1).surf(), 0, screen, 0);
}
if(tooltip_.dirty()) {
tooltip_.draw(screen);
@ -188,26 +175,6 @@ void twindow::layout(const SDL_Rect position)
set_client_size(position);
}
void twindow::set_width(const unsigned width)
{
canvas_background_.set_width(width);
canvas_foreground_.set_width(width);
need_layout_ = true;
// inherited
tcontrol::set_width(width);
}
void twindow::set_height(const unsigned height)
{
canvas_background_.set_height(height);
canvas_foreground_.set_height(height);
need_layout_ = true;
// inherited
tcontrol::set_height(height);
}
void twindow::flip()
{
// fixme we need to add the option to either call

View file

@ -68,10 +68,6 @@ public:
void set_retval(const int retval, const bool close_window = true)
{ retval_ = retval; if(close_window) close(); }
void set_width(const unsigned width);
void set_height(const unsigned height);
//! Inherited from tevent_handler.
twindow& get_window() { return *this; }
const twindow& get_window() const { return *this; }
@ -122,10 +118,6 @@ private:
bool need_layout_;
surface restorer_;
tcanvas
canvas_background_,
canvas_foreground_;
//! Inherited from tevent_handler.
void do_show_tooltip(const tpoint& location, const t_string& tooltip);