mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibGUI: Add opacity to ImageWidget
This commit is contained in:
parent
0e63141a19
commit
bf432f8a3a
2 changed files with 17 additions and 2 deletions
|
@ -128,12 +128,22 @@ void ImageWidget::paint_event(PaintEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
Painter painter(*this);
|
Painter painter(*this);
|
||||||
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
if (m_should_stretch) {
|
if (m_should_stretch) {
|
||||||
painter.draw_scaled_bitmap(frame_inner_rect(), *m_bitmap, m_bitmap->rect());
|
painter.draw_scaled_bitmap(frame_inner_rect(), *m_bitmap, m_bitmap->rect(), (float)opacity_percent() / 100.0f);
|
||||||
} else {
|
} else {
|
||||||
auto location = frame_inner_rect().center().translated(-(m_bitmap->width() / 2), -(m_bitmap->height() / 2));
|
auto location = frame_inner_rect().center().translated(-(m_bitmap->width() / 2), -(m_bitmap->height() / 2));
|
||||||
painter.blit(location, *m_bitmap, m_bitmap->rect());
|
painter.blit(location, *m_bitmap, m_bitmap->rect(), (float)opacity_percent() / 100.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageWidget::set_opacity_percent(int percent)
|
||||||
|
{
|
||||||
|
if (m_opacity_percent == percent)
|
||||||
|
return;
|
||||||
|
m_opacity_percent = percent;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,9 @@ public:
|
||||||
void animate();
|
void animate();
|
||||||
void load_from_file(const StringView&);
|
void load_from_file(const StringView&);
|
||||||
|
|
||||||
|
int opacity_percent() const { return m_opacity_percent; }
|
||||||
|
void set_opacity_percent(int percent);
|
||||||
|
|
||||||
Function<void()> on_click;
|
Function<void()> on_click;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -65,6 +68,8 @@ private:
|
||||||
size_t m_current_frame_index { 0 };
|
size_t m_current_frame_index { 0 };
|
||||||
size_t m_loops_completed { 0 };
|
size_t m_loops_completed { 0 };
|
||||||
NonnullRefPtr<Core::Timer> m_timer;
|
NonnullRefPtr<Core::Timer> m_timer;
|
||||||
|
|
||||||
|
int m_opacity_percent { 100 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue