1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:47:45 +00:00

Solitaire: Refactor painting logic to accomodate to-be-added widgets

A series of events led to this change: The goal is to add more widgets
to the Solitaire GML, such as a GUI::Statusbar. To do so without this
change, the window ends up with some black artifacts between the main
Solitaire frame and the added elements, because the GML specifies the
main widget to have fill_with_background_color=false. However, setting
that property to true results in the background color of the widget
interferring with the Solitaire frame trying to manually paint its
background green. This results in flickering and some elements in the
Solitaire frame being painted over by the main background color.

To avoid all of that behavior, this sets fill_with_background_color=true
and the Solitaire frame's background color to green in the GML. Further,
the frame now only queues a paint update on the specific Gfx::Rect areas
that need to be updated. This also means we no longer need to track if a
stack of cards is dirty, because we only trigger a paint event for dirty
stacks.
This commit is contained in:
Timothy Flynn 2021-05-05 12:19:10 -04:00 committed by Andreas Kling
parent bb7b76e505
commit 4fc9c1d710
5 changed files with 58 additions and 65 deletions

View file

@ -42,8 +42,19 @@ private:
RefPtr<Card> card() { return m_animation_card; }
void tick()
void draw(GUI::Painter& painter)
{
VERIFY(!m_animation_card.is_null());
m_animation_card->draw(painter);
m_dirty = false;
}
bool tick()
{
// Don't move the animation card until the event loop has had a chance to paint its current location.
if (m_dirty)
return false;
VERIFY(!m_animation_card.is_null());
m_y_velocity += m_gravity;
@ -54,6 +65,9 @@ private:
} else {
m_animation_card->rect().translate_by(m_x_velocity, m_y_velocity);
}
m_dirty = true;
return true;
}
private:
@ -62,6 +76,7 @@ private:
int m_x_velocity { 0 };
float m_y_velocity { 0 };
float m_bouncyness { 0 };
bool m_dirty { false };
};
enum StackLocation {
@ -110,8 +125,6 @@ private:
Gfx::IntPoint m_mouse_down_location;
bool m_mouse_down { false };
bool m_repaint_all { true };
bool m_has_to_repaint { true };
Animation m_animation;
bool m_game_over_animation { false };