Skip to content

Commit

Permalink
GUI2: removed dirty widget interface
Browse files Browse the repository at this point in the history
This is no longer needed since we redraw everything every frame. The dirty flag in the canvas remains
as that controls whether the cached texture is used or recreated.
  • Loading branch information
Vultraz committed Jul 9, 2017
1 parent b57c0db commit 25c51fe
Show file tree
Hide file tree
Showing 47 changed files with 8 additions and 410 deletions.
25 changes: 0 additions & 25 deletions src/gui/core/event/handler.cpp
Expand Up @@ -501,12 +501,6 @@ void sdl_event_handler::disconnect(dispatcher* disp)
keyboard_focus_ = nullptr;
}

/***** Set proper state for the other dispatchers. *****/
for(auto d : dispatchers_)
{
dynamic_cast<widget&>(*d).set_is_dirty(true);
}

activate();

/***** Validate post conditions. *****/
Expand Down Expand Up @@ -548,32 +542,13 @@ void sdl_event_handler::draw(const bool force)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);

/*
* In normal draw mode the first window in not forced to be drawn the
* others are. So for forced mode we only need to force the first window to
* be drawn the others are already handled.
*/
bool first = !force;

/**
* @todo Need to evaluate which windows really to redraw.
*
* For now we use a hack, but would be nice to rewrite it for 1.9/1.11.
*/
for(auto dispatcher : dispatchers_)
{
if(!first) {
/*
* This leaves glitches on window borders if the window beneath it
* has changed, on the other hand invalidating twindown::restorer_
* causes black borders around the window. So there's the choice
* between two evils.
*/
dynamic_cast<widget&>(*dispatcher).set_is_dirty(true);
} else {
first = false;
}

dispatcher->fire(DRAW, dynamic_cast<widget&>(*dispatcher));
}

Expand Down
1 change: 0 additions & 1 deletion src/gui/dialogs/debug_clock.cpp
Expand Up @@ -155,7 +155,6 @@ void debug_clock::update_time(const bool force)
canvas.set_variable("minute", wfl::variant(minute_stamp));
canvas.set_variable("second", wfl::variant(second_stamp));
}
clock_->set_is_dirty(true);
}

const std::map<std::string, std::string> tags;
Expand Down
3 changes: 0 additions & 3 deletions src/gui/dialogs/editor/custom_tod.cpp
Expand Up @@ -301,9 +301,6 @@ void custom_tod::update_tod_display(window& window)

// redraw tiles
disp->draw(false);

// NOTE: revert to invalidate_layout if necessary to display the ToD mask image.
window.set_is_dirty(true);
}

void custom_tod::update_lawful_bonus(window& window)
Expand Down
4 changes: 0 additions & 4 deletions src/gui/dialogs/lua_interpreter.cpp
Expand Up @@ -518,10 +518,6 @@ void lua_interpreter::controller::input_keypress_callback(bool& handled,
handled = true;
halt = true;

// Commands such as `wesnoth.zoom` might cause the display to redraw and leave the window half-drawn.
// This preempts that.
window.set_is_dirty(true);

LOG_LUA << "finished executing\n";
} else if(key == SDLK_TAB) { // handle tab completion
tab();
Expand Down
2 changes: 0 additions & 2 deletions src/gui/dialogs/outro.cpp
Expand Up @@ -98,8 +98,6 @@ void outro::draw_callback(window& window)
window_canvas.set_variable("fade_step", wfl::variant(fade_step_));
window_canvas.set_is_dirty(true);

window.set_is_dirty(true);

if(fading_in_) {
fade_step_ ++;
} else {
Expand Down
12 changes: 0 additions & 12 deletions src/gui/dialogs/story_viewer.cpp
Expand Up @@ -199,7 +199,6 @@ void story_viewer::display_part(window& window)

// Needed to make the background redraw correctly.
window_canvas.set_is_dirty(true);
window.set_is_dirty(true);

//
// Title
Expand Down Expand Up @@ -336,8 +335,6 @@ void story_viewer::draw_floating_image(window& window, floating_image_list::cons
window_canvas.append_cfg(cfg);
window_canvas.set_is_dirty(true);

window.set_is_dirty(true);

++image_iter;

// If a delay is specified, schedule the next image draw. This *must* be a non-repeating timer!
Expand All @@ -361,7 +358,6 @@ void story_viewer::nav_button_callback(window& window, NAV_DIRECTION direction)
// Only set full alpha if Forward was pressed.
if(direction == DIR_FORWARD) {
find_widget<scroll_label>(&window, "part_text", false).set_text_alpha(ALPHA_OPAQUE);
flag_stack_as_dirty(window);
return;
}
}
Expand Down Expand Up @@ -457,9 +453,6 @@ void story_viewer::draw_callback(window& window)
unsigned short new_alpha = utils::clamp<short>(fade_step_ * 25.5, 0, ALPHA_OPAQUE);
find_widget<scroll_label>(&window, "part_text", false).set_text_alpha(new_alpha);

// The text stack also needs to be marked dirty so the background panel redraws correctly.
flag_stack_as_dirty(window);

if(fade_state_ == FADING_IN) {
fade_step_ ++;
} else if(fade_state_ == FADING_OUT) {
Expand All @@ -469,10 +462,5 @@ void story_viewer::draw_callback(window& window)
set_next_draw();
}

void story_viewer::flag_stack_as_dirty(window& window)
{
find_widget<stacked_widget>(&window, "text_and_control_stack", false).set_is_dirty(true);
}

} // namespace dialogs
} // namespace gui2
2 changes: 0 additions & 2 deletions src/gui/dialogs/story_viewer.hpp
Expand Up @@ -74,8 +74,6 @@ class story_viewer : public modal_dialog

void draw_callback(window& window);

void flag_stack_as_dirty(window& window);

storyscreen::controller controller_;

int part_index_;
Expand Down
9 changes: 0 additions & 9 deletions src/gui/dialogs/title_screen.cpp
Expand Up @@ -512,15 +512,6 @@ void title_screen::update_tip(window& win, const bool previous)
}

tips.select_page(page);

/**
* @todo Look for a proper fix.
*
* This dirtying is required to avoid the blurring to be rendered wrong.
* Not entirely sure why, but since we plan to move to SDL2 that change
* will probably fix this issue automatically.
*/
win.set_is_dirty(true);
}

void title_screen::show_debug_clock_window(CVideo& video)
Expand Down
1 change: 0 additions & 1 deletion src/gui/widgets/button.cpp
Expand Up @@ -76,7 +76,6 @@ void button::set_state(const state_t state)
{
if(state != state_) {
state_ = state;
set_is_dirty(true);
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/gui/widgets/container_base.cpp
Expand Up @@ -208,14 +208,6 @@ void container_base::layout_children()
grid_.layout_children();
}

void
container_base::child_populate_dirty_list(window& caller,
const std::vector<widget*>& call_stack)
{
std::vector<widget*> child_call_stack = call_stack;
grid_.populate_dirty_list(caller, child_call_stack);
}

widget* container_base::find_at(const point& coordinate,
const bool must_be_active)
{
Expand Down Expand Up @@ -251,8 +243,6 @@ void container_base::set_active(const bool active)
return;
}

set_is_dirty(true);

set_self_active(active);
}

Expand Down
5 changes: 0 additions & 5 deletions src/gui/widgets/container_base.hpp
Expand Up @@ -111,11 +111,6 @@ class container_base : public styled_widget
/** See @ref widget::layout_children. */
virtual void layout_children() override;

/** See @ref widget::child_populate_dirty_list. */
virtual void
child_populate_dirty_list(window& caller,
const std::vector<widget*>& call_stack) override;

public:
/** See @ref widget::find_at. */
virtual widget* find_at(const point& coordinate,
Expand Down
8 changes: 0 additions & 8 deletions src/gui/widgets/generator.hpp
Expand Up @@ -286,14 +286,6 @@ class generator_base : public widget
int x_offset,
int y_offset) override = 0;

protected:
/** See @ref widget::child_populate_dirty_list. */
virtual void
child_populate_dirty_list(window& caller,
const std::vector<widget*>& call_stack) override
= 0;

public:
/** See @ref widget::find_at. */
virtual widget* find_at(const point& coordinate,
const bool must_be_active) override = 0;
Expand Down
13 changes: 0 additions & 13 deletions src/gui/widgets/generator_private.hpp
Expand Up @@ -859,18 +859,6 @@ class generator : public minimum_selection,
}
}

/** See @ref widget::child_populate_dirty_list. */
virtual void
child_populate_dirty_list(window& caller,
const std::vector<widget*>& call_stack) override
{
for(auto& item : items_)
{
std::vector<widget*> child_call_stack = call_stack;
item->child_grid.populate_dirty_list(caller, child_call_stack);
}
}

/** See @ref widget::find_at. */
virtual widget* find_at(const point& coordinate,
const bool must_be_active) override
Expand Down Expand Up @@ -1004,7 +992,6 @@ class generator : public minimum_selection,
{
order_func_ = order;
order_dirty_ = true;
this->set_is_dirty(true);
}

struct calculate_order_helper
Expand Down
17 changes: 0 additions & 17 deletions src/gui/widgets/grid.cpp
Expand Up @@ -636,21 +636,6 @@ void grid::layout_children()
}
}

void grid::child_populate_dirty_list(window& caller,
const std::vector<widget*>& call_stack)
{
assert(!call_stack.empty() && call_stack.back() == this);

for(auto & child : children_)
{

assert(child.get_widget());

std::vector<widget*> child_call_stack = call_stack;
child.get_widget()->populate_dirty_list(caller, child_call_stack);
}
}

widget* grid::find_at(const point& coordinate, const bool must_be_active)
{
return grid_implementation::find_at<widget>(
Expand Down Expand Up @@ -1015,7 +1000,6 @@ void grid::impl_draw_children(surface& frame_buffer, int x_offset, int y_offset)
*/

assert(get_visible() == widget::visibility::visible);
set_is_dirty(false);

for(auto & child : children_)
{
Expand All @@ -1034,7 +1018,6 @@ void grid::impl_draw_children(surface& frame_buffer, int x_offset, int y_offset)
widget->draw_background(frame_buffer, x_offset, y_offset);
widget->draw_children(frame_buffer, x_offset, y_offset);
widget->draw_foreground(frame_buffer, x_offset, y_offset);
widget->set_is_dirty(false);
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/gui/widgets/grid.hpp
Expand Up @@ -79,7 +79,6 @@ class grid : public widget
{
assert(row < row_grow_factor_.size());
row_grow_factor_[row] = factor;
set_is_dirty(true);
}

/**
Expand All @@ -94,7 +93,6 @@ class grid : public widget
{
assert(column < col_grow_factor_.size());
col_grow_factor_[column] = factor;
set_is_dirty(true);
}

/***** ***** ***** ***** CHILD MANIPULATION ***** ***** ***** *****/
Expand Down Expand Up @@ -264,11 +262,6 @@ class grid : public widget
/** See @ref widget::layout_children. */
virtual void layout_children() override;

/** See @ref widget::child_populate_dirty_list. */
virtual void
child_populate_dirty_list(window& caller,
const std::vector<widget*>& call_stack) override;

/** See @ref widget::find_at. */
virtual widget* find_at(const point& coordinate,
const bool must_be_active) override;
Expand Down
5 changes: 0 additions & 5 deletions src/gui/widgets/label.cpp
Expand Up @@ -81,8 +81,6 @@ void label::set_text_alpha(unsigned short alpha)
for(auto& tmp : get_canvases()) {
tmp.set_variable("text_alpha", wfl::variant(text_alpha_));
}

set_is_dirty(true);
}

void label::set_active(const bool active)
Expand Down Expand Up @@ -120,7 +118,6 @@ void label::set_link_aware(bool link_aware)

link_aware_ = link_aware;
update_canvas();
set_is_dirty(true);
}

void label::set_link_color(const color_t& color)
Expand All @@ -130,14 +127,12 @@ void label::set_link_color(const color_t& color)
}
link_color_ = color;
update_canvas();
set_is_dirty(true);
}

void label::set_state(const state_t state)
{
if(state != state_) {
state_ = state;
set_is_dirty(true);
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/gui/widgets/list.cpp
Expand Up @@ -193,7 +193,6 @@ void list_view::set_row_shown(const unsigned row, const bool shown)
window->invalidate_layout();
} else {
// get_grid().set_visible_rectangle(content_visible_rectangle());
set_is_dirty(true);
}

if(selected_row != get_selected_row()) {
Expand Down Expand Up @@ -227,7 +226,6 @@ void list_view::set_row_shown(const boost::dynamic_bitset<>& shown)
window->invalidate_layout();
} else {
// content_grid_->set_visible_rectangle(content_visible_rectangle());
set_is_dirty(true);
}

if(selected_row != get_selected_row()) {
Expand Down Expand Up @@ -312,10 +310,7 @@ void list_view::resize_content(

// Set status.
need_layout_ = true;
// If the content grows assume it "overwrites" the old content.
if(width_modification < 0 || height_modification < 0) {
set_is_dirty(true);
}

DBG_GUI_L << LOG_HEADER << " succeeded.\n";
} else {
DBG_GUI_L << LOG_HEADER << " failed.\n";
Expand Down Expand Up @@ -370,7 +365,6 @@ void list_view::layout_children(const bool force)
get_grid().set_visible_rectangle(content_visible_area_);
*/
need_layout_ = false;
set_is_dirty(true);
}
}

Expand Down

0 comments on commit 25c51fe

Please sign in to comment.