Added some extra set_dirty() defintions in inherited classes.

set_dirty(false) for a container should also clear the dirty flag of
its children. Before the window was redrawn every frame causing an
increased CPU usage, which has been gone with this change.
This commit is contained in:
Mark de Wever 2008-08-19 15:58:20 +00:00
parent 74d04db1e2
commit 2d805ee383
5 changed files with 41 additions and 3 deletions

View file

@ -135,5 +135,15 @@ void tcontainer_::set_active(const bool active)
set_self_active(active);
}
void tcontainer_::set_dirty(const bool dirty)
{
// Inherited.
twidget::set_dirty(dirty);
if(!dirty) {
grid_.set_dirty(dirty);
}
}
} // namespace gui2

View file

@ -139,8 +139,11 @@ public:
/** FIXME see whether needed to be exported. */
void set_client_size(const SDL_Rect& rect) { grid_.set_size(rect); }
protected:
/** Inherited from twidget. */
void set_dirty(const bool dirty = true);
protected:
/***** ***** ***** setters / getters for members ***** ****** *****/
const tgrid& grid() const { return grid_; }

View file

@ -531,6 +531,22 @@ void tgrid::set_rows_cols(const unsigned rows, const unsigned cols)
clear_cache();
}
void tgrid::set_dirty(const bool dirty)
{
// Inherited.
twidget::set_dirty(dirty);
if(!dirty) {
for(std::vector<tchild>::iterator itor = children_.begin();
itor != children_.end(); ++itor) {
if(itor->widget()) {
itor->widget()->set_dirty(dirty);
}
}
}
}
tpoint tgrid::tchild::get_best_size() const
{
if(!widget_) {

View file

@ -207,6 +207,9 @@ public:
*/
void set_rows_cols(const unsigned rows, const unsigned cols);
/** Inherited from twidget. */
void set_dirty(const bool dirty = true);
private:
/** Child item of the grid. */
class tchild

View file

@ -535,14 +535,20 @@ public:
unsigned get_width() const { return w_; }
unsigned get_height() const { return h_; }
protected:
/**
* Sets the widgets dirty state.
*
* When set to dirty it should also mark it's parents as dirty so that the
* window easily test for it's dirty state.
* When set to not dirty it should also mark it's childeren as not dirty.
* (Obviously only for container classes).
*/
virtual void set_dirty(const bool dirty = true)
{
dirty_ = dirty;
if(parent_ && dirty) parent_->set_dirty(true);
}
public:
virtual bool is_dirty() const { return dirty_; }
private: