Let tpanel inherit from tcontainer_ instead of tcontrol.
This commit is contained in:
parent
39e1785cf8
commit
5ed5e457d3
4 changed files with 63 additions and 106 deletions
|
@ -47,5 +47,37 @@ void tcontainer_::draw(surface& surface)
|
|||
grid_.draw(surface);
|
||||
}
|
||||
|
||||
tpoint tcontainer_::get_minimum_size() const
|
||||
{
|
||||
tpoint size = grid_.get_maximum_size();
|
||||
tpoint border_size = border_space();
|
||||
|
||||
if(size.x) {
|
||||
size.x += border_size.x;
|
||||
}
|
||||
|
||||
if(size.y) {
|
||||
size.y += border_size.y;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
tpoint tcontainer_::get_best_size() const
|
||||
{
|
||||
tpoint size = grid_.get_best_size();
|
||||
tpoint border_size = border_space();
|
||||
|
||||
if(size.x) {
|
||||
size.x += border_size.x;
|
||||
}
|
||||
|
||||
if(size.y) {
|
||||
size.y += border_size.y;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -76,18 +76,21 @@ public:
|
|||
bool has_vertical_scrollbar() const = 0;
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
tpoint get_minimum_size() const { return grid_.get_minimum_size(); }
|
||||
tpoint get_minimum_size() const;
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
tpoint get_best_size() const { return grid_.get_best_size(); }
|
||||
tpoint get_best_size() const;
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
void set_size(const SDL_Rect& rect)
|
||||
{
|
||||
tcontrol::set_size(rect);
|
||||
grid_.set_size(rect);
|
||||
set_client_size(get_client_rect());
|
||||
}
|
||||
|
||||
/** FIXME see whether needed to be exported. */
|
||||
void set_client_size(const SDL_Rect& rect) { grid_.set_size(rect); }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
void draw(surface& surface);
|
||||
|
||||
|
@ -108,6 +111,17 @@ public:
|
|||
void set_rows_cols(const unsigned rows, const unsigned cols)
|
||||
{ grid_.set_rows_cols(rows, cols); }
|
||||
|
||||
void add_child(twidget* widget, const unsigned row,
|
||||
const unsigned col, const unsigned flags, const unsigned border_size)
|
||||
{ grid_.add_child(widget, row, col, flags, border_size); }
|
||||
|
||||
void set_row_grow_factor(const unsigned row, const unsigned factor)
|
||||
{ grid_.set_row_grow_factor(row, factor); }
|
||||
|
||||
void set_col_grow_factor(const unsigned col, const unsigned factor)
|
||||
{ grid_.set_col_grow_factor(col, factor); }
|
||||
|
||||
virtual SDL_Rect get_client_rect() const { return get_rect(); }
|
||||
protected:
|
||||
const tgrid& grid() const { return grid_; }
|
||||
tgrid& grid() { return grid_; }
|
||||
|
@ -115,6 +129,9 @@ protected:
|
|||
private:
|
||||
|
||||
tgrid grid_;
|
||||
|
||||
//! Returns the space used by the border.
|
||||
virtual tpoint border_space() const { return tpoint(0, 0); }
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -38,49 +38,12 @@
|
|||
|
||||
namespace gui2 {
|
||||
|
||||
tpoint tpanel::get_minimum_size() const
|
||||
{
|
||||
const tpoint max_size = get_maximum_size();
|
||||
tpoint size = grid_.get_minimum_size() + border_space();
|
||||
|
||||
if(max_size.x) {
|
||||
size.x = minimum(size.x, max_size.x);
|
||||
}
|
||||
|
||||
if(max_size.y) {
|
||||
size.y = minimum(size.y, max_size.y);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
tpoint tpanel::get_best_size() const
|
||||
{
|
||||
const tpoint max_size = get_maximum_size();
|
||||
tpoint size = grid_.get_best_size() + border_space();
|
||||
|
||||
if(max_size.x) {
|
||||
size.x = minimum(size.x, max_size.x);
|
||||
}
|
||||
|
||||
if(max_size.y) {
|
||||
size.y = minimum(size.y, max_size.y);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void tpanel::draw(surface& surface)
|
||||
{
|
||||
// Need to preserve the state and inherited draw clear the flag.
|
||||
const bool is_dirty = dirty();
|
||||
// background.
|
||||
if(is_dirty) {
|
||||
tcontrol::draw(surface);
|
||||
}
|
||||
|
||||
// children
|
||||
grid_.draw(surface);
|
||||
tcontainer_::draw(surface);
|
||||
|
||||
// foreground
|
||||
if(is_dirty) {
|
||||
|
@ -105,13 +68,6 @@ SDL_Rect tpanel::get_client_rect() const
|
|||
return result;
|
||||
}
|
||||
|
||||
void tpanel::set_size(const SDL_Rect& rect)
|
||||
{
|
||||
tcontrol::set_size(rect);
|
||||
|
||||
grid_.set_size(get_client_rect());
|
||||
}
|
||||
|
||||
tpoint tpanel::border_space() const
|
||||
{
|
||||
const tpanel_definition::tresolution* conf =
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
#ifndef __GUI_WIDGETS_PANEL_HPP_INCLUDED__
|
||||
#define __GUI_WIDGETS_PANEL_HPP_INCLUDED__
|
||||
|
||||
#include "gui/widgets/grid.hpp"
|
||||
#include "gui/widgets/container.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
//! Visible container to hold children.
|
||||
class tpanel : public tcontrol
|
||||
class tpanel : public tcontainer_
|
||||
{
|
||||
|
||||
public:
|
||||
|
@ -28,91 +28,43 @@ public:
|
|||
//!
|
||||
//! @param canvas_count The canvas count for tcontrol.
|
||||
tpanel(const unsigned canvas_count = 2) :
|
||||
tcontrol(canvas_count),
|
||||
grid_()
|
||||
tcontainer_(canvas_count)
|
||||
{
|
||||
grid_.set_parent(this);
|
||||
}
|
||||
|
||||
/** Inherited from tcontrol, copied from container.hpp. */
|
||||
twidget* find_widget(const tpoint& coordinate, const bool must_be_active)
|
||||
{ return grid_.find_widget(coordinate, must_be_active); }
|
||||
{ return tcontainer_::find_widget(coordinate, must_be_active); }
|
||||
|
||||
/** Inherited from tcontrol, copied from container.hpp. */
|
||||
const twidget* find_widget(const tpoint& coordinate,
|
||||
const bool must_be_active) const
|
||||
{ return grid_.find_widget(coordinate, must_be_active); }
|
||||
{ return tcontainer_::find_widget(coordinate, must_be_active); }
|
||||
|
||||
/** Inherited from tcontrol, copied from container.hpp.*/
|
||||
twidget* find_widget(const std::string& id, const bool must_be_active)
|
||||
{
|
||||
twidget* result = tcontrol::find_widget(id, must_be_active);
|
||||
return result ? result : grid_.find_widget(id, must_be_active);
|
||||
}
|
||||
{ return tcontainer_::find_widget(id, must_be_active); }
|
||||
|
||||
/** Inherited from tcontrol, copied from container.hpp.*/
|
||||
const twidget* find_widget(const std::string& id,
|
||||
const bool must_be_active) const
|
||||
{
|
||||
const twidget* result = tcontrol::find_widget(id, must_be_active);
|
||||
return result ? result : grid_.find_widget(id, must_be_active);
|
||||
}
|
||||
|
||||
// Inherited from twidget.
|
||||
bool dirty() const { return twidget::dirty() || grid_.dirty(); }
|
||||
{ return tcontainer_::find_widget(id, must_be_active); }
|
||||
|
||||
bool has_vertical_scrollbar() const { return false; }
|
||||
|
||||
//! A panel is always active atm so ignore the request.
|
||||
void set_active(const bool /*active*/) {}
|
||||
bool get_active() const { return true; }
|
||||
unsigned get_state() const { return 0; }
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
tpoint get_minimum_size() const;
|
||||
tpoint get_best_size() const;
|
||||
|
||||
// get_maximum_size is inherited from tcontrol.
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
void draw(surface& surface);
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
void set_size(const SDL_Rect& rect);
|
||||
|
||||
//***** **** wrappers to the grid **** ****
|
||||
tgrid::iterator begin() { return grid_.begin(); }
|
||||
tgrid::iterator end() { return grid_.end(); }
|
||||
|
||||
SDL_Rect get_client_rect() const;
|
||||
|
||||
void set_client_size(const SDL_Rect& rect) { grid_.set_size(rect); }
|
||||
|
||||
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); }
|
||||
|
||||
void add_child(twidget* widget, const unsigned row,
|
||||
const unsigned col, const unsigned flags, const unsigned border_size)
|
||||
{ grid_.add_child(widget, row, col, flags, border_size); }
|
||||
|
||||
void set_row_grow_factor(const unsigned row, const unsigned factor)
|
||||
{ grid_.set_row_grow_factor(row, factor); }
|
||||
|
||||
void set_col_grow_factor(const unsigned col, const unsigned factor)
|
||||
{ grid_.set_col_grow_factor(col, factor); }
|
||||
|
||||
private:
|
||||
tgrid grid_;
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
const std::string& get_control_type() const
|
||||
{ static const std::string type = "panel"; return type; }
|
||||
|
||||
//! Returns the space used by the border.
|
||||
/** Inherited from tcontainer_. */
|
||||
tpoint border_space() const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue