Add a tcontainer base class, tpanel could use this as base.

This commit is contained in:
Mark de Wever 2008-05-11 17:09:31 +00:00
parent cde6cce8dd
commit 723daf2ae1
6 changed files with 153 additions and 0 deletions

View File

@ -8,6 +8,7 @@ src/gui/dialogs/addon_connect.cpp
src/gui/widgets/button.cpp
src/gui/widgets/canvas.cpp
src/gui/widgets/control.cpp
gui/widgets/container.cpp
src/gui/widgets/event_handler.cpp
src/gui/widgets/grid.cpp
src/gui/widgets/helper.cpp

View File

@ -170,6 +170,7 @@ SET(wesnoth-main_SRC
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp
gui/widgets/container.cpp
gui/widgets/event_handler.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp

View File

@ -71,6 +71,7 @@ wesnoth_source = \
gui/widgets/button.cpp \
gui/widgets/canvas.cpp \
gui/widgets/control.cpp \
gui/widgets/container.cpp \
gui/widgets/event_handler.cpp \
gui/widgets/grid.cpp \
gui/widgets/helper.cpp \

View File

@ -85,6 +85,7 @@ libwesnoth_sources = Split("""
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp
gui/widgets/container.cpp
gui/widgets/event_handler.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp

View File

@ -0,0 +1,51 @@
/* $Id$ */
/*
copyright (C) 2008 by mark de wever <koraq@xs4all.nl>
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 version 2
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.
*/
#include "gui/widgets/container.hpp"
#include "log.hpp"
#define DBG_G LOG_STREAM_INDENT(debug, gui)
#define LOG_G LOG_STREAM_INDENT(info, gui)
#define WRN_G LOG_STREAM_INDENT(warn, gui)
#define ERR_G LOG_STREAM_INDENT(err, gui)
#define DBG_G_D LOG_STREAM_INDENT(debug, gui_draw)
#define LOG_G_D LOG_STREAM_INDENT(info, gui_draw)
#define WRN_G_D LOG_STREAM_INDENT(warn, gui_draw)
#define ERR_G_D LOG_STREAM_INDENT(err, gui_draw)
#define DBG_G_E LOG_STREAM_INDENT(debug, gui_event)
#define LOG_G_E LOG_STREAM_INDENT(info, gui_event)
#define WRN_G_E LOG_STREAM_INDENT(warn, gui_event)
#define ERR_G_E LOG_STREAM_INDENT(err, gui_event)
#define DBG_G_P LOG_STREAM_INDENT(debug, gui_parse)
#define LOG_G_P LOG_STREAM_INDENT(info, gui_parse)
#define WRN_G_P LOG_STREAM_INDENT(warn, gui_parse)
#define ERR_G_P LOG_STREAM_INDENT(err, gui_parse)
namespace gui2 {
void tcontainer_::draw(surface& surface)
{
// Inherited.
tcontrol::draw(surface);
grid_.draw(surface);
}
} // namespace gui2

View File

@ -0,0 +1,98 @@
/* $Id$ */
/*
copyright (C) 2008 by mark de wever <koraq@xs4all.nl>
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 version 2
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.
*/
#ifndef __GUI_WIDGETS_CONTAINER_HPP_INCLUDED__
#define __GUI_WIDGETS_CONTAINER_HPP_INCLUDED__
#include "gui/widgets/grid.hpp"
#include "gui/widgets/control.hpp"
namespace gui2 {
/**
* A generic container base class.
*
* A container is a class build with multiple items either acting as one
* widget .
*/
class tcontainer_ : public tcontrol
{
public:
tcontainer_(const unsigned canvas_count) :
tcontrol(canvas_count)
{
grid_.set_parent(this);
}
/** Inherited from twidget. */
bool dirty() const { return twidget::dirty() || grid_.dirty(); }
/** Inherited from twidget. */
twidget* get_widget(const tpoint& coordinate)
{ return grid_.get_widget(coordinate); }
/** Inherited from twidget.*/
twidget* get_widget_by_id(const std::string& id)
{
twidget* result = twidget::get_widget_by_id(id);
return result ? result : grid_.get_widget_by_id(id);
}
/** Inherited from tcontrol. */
tpoint get_minimum_size() const { return grid_.get_minimum_size(); }
/** Inherited from tcontrol. */
tpoint get_best_size() const { return grid_.get_best_size(); }
/** Inherited from tcontrol. */
void set_size(const SDL_Rect& rect)
{
tcontrol::set_size(rect);
grid_.set_size(rect);
}
/** Inherited from tcontrol. */
void draw(surface& surface);
/***** **** wrappers to the grid **** ****/
tgrid::iterator begin() { return grid_.begin(); }
tgrid::iterator end() { return grid_.end(); }
unsigned add_row(const unsigned count = 1)
{ return grid_.add_row(count); }
void set_rows(const unsigned rows) { grid_.set_rows(rows); }
unsigned int get_rows() const { return grid_.get_rows(); }
void set_cols(const unsigned cols) { grid_.set_cols(cols); }
unsigned int get_cols() const { return grid_.get_cols(); }
void set_rows_cols(const unsigned rows, const unsigned cols)
{ grid_.set_rows_cols(rows, cols); }
protected:
const tgrid& grid() const { return grid_; }
tgrid& grid() { return grid_; }
private:
tgrid grid_;
};
} // namespace gui2
#endif