Replace most GUI1 set_dirty() calls with queue_redraw()

This commit is contained in:
Tommy 2022-07-29 04:01:54 +12:00
parent 26072b7ab4
commit 9dd7bc886e
9 changed files with 52 additions and 57 deletions

View File

@ -242,7 +242,7 @@ void show_with_toplevel(const section &toplevel_sec,
else {
hb.show_topic(default_show_topic);
}
hb.set_dirty(true);
hb.queue_redraw();
events::raise_draw_event();
CKey key;
for (;;) {

View File

@ -82,7 +82,7 @@ void help_browser::adjust_layout()
back_button_.set_location(back_button_x, back_button_y);
forward_button_.set_location(forward_button_x, forward_button_y);
set_dirty(true);
queue_redraw();
}
void help_browser::update_location(const SDL_Rect&)

View File

@ -67,7 +67,7 @@ void help_text_area::show_topic(const topic &t)
{
shown_topic_ = &t;
set_items();
set_dirty(true);
queue_redraw();
DBG_HP << "Showing topic: " << t.id << ": " << t.title;
}
@ -570,7 +570,7 @@ void help_text_area::scroll(unsigned int)
// Nothing will be done on the actual scroll event. The scroll
// position is checked when drawing instead and things drawn
// accordingly.
set_dirty(true);
queue_redraw();
}
bool help_text_area::item_at::operator()(const item& item) const {

View File

@ -250,7 +250,7 @@ void button::set_check(bool check)
if (state_ != new_state) {
state_ = new_state;
set_dirty();
queue_redraw();
}
}
@ -258,10 +258,10 @@ void button::set_active(bool active)
{
if ((state_ == NORMAL) && active) {
state_ = ACTIVE;
set_dirty();
queue_redraw();
} else if ((state_ == ACTIVE) && !active) {
state_ = NORMAL;
set_dirty();
queue_redraw();
}
}
@ -389,7 +389,7 @@ void button::set_image(const std::string& image_file)
button_image_name_ = "buttons/" + image_file;
load_images();
set_dirty();
queue_redraw();
}
void button::set_overlay(const std::string& image_file)
@ -401,7 +401,7 @@ void button::set_overlay(const std::string& image_file)
button_overlay_image_name_ = image_file;
load_images();
set_dirty();
queue_redraw();
}
void button::set_label(const std::string& val)
@ -418,8 +418,7 @@ void button::set_label(const std::string& val)
}
calculate_size();
set_dirty(true);
queue_redraw();
}
void button::mouse_motion(const SDL_MouseMotionEvent& event)
@ -561,8 +560,9 @@ void button::handle_event(const SDL_Event& event)
}
}
if (start_state != state_)
set_dirty(true);
if (start_state != state_) {
queue_redraw();
}
}
bool button::pressed()

View File

@ -248,7 +248,7 @@ void menu::do_sort()
move_selection_to(selectid, true, NO_MOVE_VIEWPORT);
}
set_dirty();
queue_redraw();
}
void menu::recalculate_pos()
@ -345,7 +345,7 @@ void menu::change_item(int pos1, int pos2,const std::string& str)
}
items_[item_pos_[pos1]].fields[pos2] = str;
set_dirty();
queue_redraw();
}
void menu::erase_item(std::size_t index)
@ -374,7 +374,7 @@ void menu::erase_item(std::size_t index)
update_scrollbar_grip_height();
adjust_viewport_to_selection();
itemRects_.clear();
set_dirty();
queue_redraw();
}
void menu::set_heading(const std::vector<std::string>& heading)
@ -385,7 +385,7 @@ void menu::set_heading(const std::vector<std::string>& heading)
heading_ = heading;
max_items_ = -1;
set_dirty();
queue_redraw();
}
void menu::set_items(const std::vector<std::string>& items, bool strip_spaces, bool keep_viewport)
@ -416,7 +416,7 @@ void menu::set_items(const std::vector<std::string>& items, bool strip_spaces, b
if(!keep_viewport) {
adjust_viewport_to_selection();
}
set_dirty();
queue_redraw();
}
void menu::set_max_height(const int new_max_height)
@ -714,7 +714,7 @@ void menu::set_numeric_keypress_selection(bool value)
void menu::scroll(unsigned int)
{
itemRects_.clear();
set_dirty();
queue_redraw();
}
void menu::set_sorter(sorter *s)
@ -746,7 +746,7 @@ void menu::sort_by(int column)
do_sort();
itemRects_.clear();
set_dirty();
queue_redraw();
}
SDL_Rect menu::style::item_size(const std::string& item) const {

View File

@ -79,7 +79,7 @@ void scrollbar::set_position(unsigned pos)
if (pos == grip_position_)
return;
grip_position_ = pos;
set_dirty();
queue_redraw();
}
void scrollbar::adjust_position(unsigned pos)
@ -110,7 +110,7 @@ void scrollbar::set_shown_size(unsigned h)
if (at_bottom)
grip_position_ = get_max_position();
set_position(grip_position_);
set_dirty(true);
queue_redraw();
}
void scrollbar::set_full_size(unsigned h)
@ -123,7 +123,7 @@ void scrollbar::set_full_size(unsigned h)
grip_position_ = get_max_position();
set_shown_size(grip_height_);
set_position(grip_position_);
set_dirty(true);
queue_redraw();
}
void scrollbar::set_scroll_rate(unsigned r)
@ -288,8 +288,8 @@ void scrollbar::handle_event(const SDL_Event& event)
if (new_state != state_) {
set_dirty();
state_ = new_state;
queue_redraw();
}
}

View File

@ -60,7 +60,7 @@ void textbox::update_location(const SDL_Rect& rect)
{
scrollarea::update_location(rect);
update_text_cache(true);
set_dirty(true);
queue_redraw();
}
void textbox::set_inner_location(const SDL_Rect& /*rect*/)
@ -84,7 +84,7 @@ void textbox::set_text(const std::string& text, const color_t& color)
text_pos_ = 0;
selstart_ = -1;
selend_ = -1;
set_dirty(true);
queue_redraw();
update_text_cache(true, color);
handle_text_changed(text_);
}
@ -106,7 +106,7 @@ void textbox::append_text(const std::string& text, bool auto_scroll, const color
text_image_ = add_text_line(text_);
set_dirty(true);
queue_redraw();
update_text_cache(false);
const bool is_at_bottom = get_position() == get_max_position();
if(auto_scroll && is_at_bottom) scroll_to_bottom();
@ -121,7 +121,7 @@ void textbox::clear()
text_pos_ = 0;
selstart_ = -1;
selend_ = -1;
set_dirty(true);
queue_redraw();
update_text_cache(true);
handle_text_changed(text_);
}
@ -138,7 +138,7 @@ void textbox::set_selection(const int selstart, const int selend)
}
selstart_= selstart;
selend_ = selend;
set_dirty(true);
queue_redraw();
}
void textbox::set_cursor_pos(const int cursor_pos)
@ -153,7 +153,7 @@ void textbox::set_cursor_pos(const int cursor_pos)
cursor_ = cursor_pos;
update_text_cache(false);
set_dirty(true);
queue_redraw();
}
void textbox::draw_cursor(int pos) const
@ -278,14 +278,14 @@ void textbox::set_wrap(bool val)
if(wrap_ != val) {
wrap_ = val;
update_text_cache(true);
set_dirty(true);
queue_redraw();
}
}
void textbox::scroll(unsigned int pos)
{
yscroll_ = pos;
set_dirty(true);
queue_redraw();
}
texture textbox::add_text_line(const std::u32string& text, const color_t& color)
@ -695,7 +695,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
grabmouse_ = false;
}
set_dirty();
queue_redraw();
}
//if we don't have the focus, then see if we gain the focus,
@ -728,7 +728,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
handle_text_changed(text_);
}
set_dirty(true);
queue_redraw();
}
void textbox::pass_event_to_target(const SDL_Event& event)

View File

@ -82,7 +82,7 @@ void widget::set_location(const SDL_Rect& rect)
state_ = DRAWN;
rect_ = rect;
set_dirty(true);
queue_redraw();
update_location(rect);
}
@ -91,11 +91,6 @@ void widget::layout()
// this basically happens in set_location, so there's nothing to do here.
}
const SDL_Rect* widget::clip_rect() const
{
return clip_ ? &clip_rect_ : nullptr;
}
void widget::set_location(int x, int y)
{
set_location({x, y, rect_.w, rect_.h});
@ -136,7 +131,7 @@ void widget::set_focus(bool focus)
if (focus)
events::focus_handler(this);
focus_ = focus;
set_dirty(true);
queue_redraw();
}
bool widget::focus(const SDL_Event* event)
@ -153,7 +148,7 @@ void widget::hide(bool value)
state_ = HIDDEN;
} else if (state_ == HIDDEN) {
state_ = DRAWN;
set_dirty(true);
queue_redraw();
}
}
@ -161,7 +156,7 @@ void widget::set_clip_rect(const SDL_Rect& rect)
{
clip_rect_ = rect;
clip_ = true;
set_dirty(true);
queue_redraw();
}
bool widget::hidden() const
@ -174,7 +169,7 @@ void widget::enable(bool new_val)
{
if (enabled_ != new_val) {
enabled_ = new_val;
set_dirty();
queue_redraw();
}
}
@ -183,13 +178,14 @@ bool widget::enabled() const
return enabled_;
}
// TODO: draw_manager - this needs to die
void widget::set_dirty(bool dirty)
{
if ((dirty && state_ != DRAWN) || (!dirty && state_ != DIRTY))
if ((dirty && state_ != DRAWN) || (!dirty && state_ != DIRTY)) {
return;
}
state_ = dirty ? DIRTY : DRAWN;
if (dirty) {
queue_redraw();
}
@ -224,19 +220,19 @@ void widget::queue_redraw()
bool widget::expose(const SDL_Rect& region)
{
// TODO: draw_manager - draw always? or only when dirty?
//if (!dirty()) {
// return false;
//}
(void)region;
if (hidden()) { return false; }
if (!rect_.overlaps(region)) { return false; }
if (clip_ && !clip_rect_.overlaps(region)) { return false; }
draw();
return true;
}
void widget::draw()
{
if (hidden())
if (hidden()) {
return;
}
if (clip_) {
auto clipper = draw::reduce_clip(clip_rect_);

View File

@ -55,8 +55,9 @@ public:
* This is in absolute drawing coordinates, and is not clipped. */
void queue_redraw(const rect&);
void set_dirty(bool dirty=true); // TODO: draw_manager - remove
bool dirty() const; // TODO: draw_manager - remove
// Note: all that needs the dirty handling is the editor palette.
void set_dirty(bool dirty=true);
bool dirty() const;
const std::string& id() const;
void set_id(const std::string& id);
@ -89,8 +90,6 @@ protected:
virtual void draw_contents() {}
virtual void update_location(const SDL_Rect&) {};
const SDL_Rect* clip_rect() const;
virtual void handle_event(const SDL_Event&) override {};
bool focus_; // Should user input be ignored?
@ -105,7 +104,7 @@ private:
enum { UNINIT, HIDDEN, DIRTY, DRAWN } state_;
bool enabled_;
bool clip_;
SDL_Rect clip_rect_;
rect clip_rect_;
std::string help_text_;
std::string tooltip_text_;