mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
Mandelbrot: Only calculate the set in paint event
The set should be calculated only when there is a paint event to keep the number of times the set is calculated (which is compute expensive) to the minimum.
This commit is contained in:
parent
fa026df892
commit
0f33d2a36d
1 changed files with 7 additions and 7 deletions
|
@ -34,14 +34,12 @@ public:
|
||||||
{
|
{
|
||||||
set_view();
|
set_view();
|
||||||
correct_aspect();
|
correct_aspect();
|
||||||
calculate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(Gfx::IntSize size)
|
void resize(Gfx::IntSize size)
|
||||||
{
|
{
|
||||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size).release_value_but_fixme_should_propagate_errors();
|
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size).release_value_but_fixme_should_propagate_errors();
|
||||||
correct_aspect();
|
correct_aspect();
|
||||||
calculate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void zoom(Gfx::IntRect const& rect)
|
void zoom(Gfx::IntRect const& rect)
|
||||||
|
@ -52,7 +50,6 @@ public:
|
||||||
rect.top() * (m_y_end - m_y_start) / m_bitmap->height() + m_y_start,
|
rect.top() * (m_y_end - m_y_start) / m_bitmap->height() + m_y_start,
|
||||||
(rect.bottom() - 1) * (m_y_end - m_y_start) / m_bitmap->height() + m_y_start);
|
(rect.bottom() - 1) * (m_y_end - m_y_start) / m_bitmap->height() + m_y_start);
|
||||||
correct_aspect();
|
correct_aspect();
|
||||||
calculate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pan_by(Gfx::IntPoint delta)
|
void pan_by(Gfx::IntPoint delta)
|
||||||
|
@ -289,6 +286,9 @@ void Mandelbrot::paint_event(GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
Frame::paint_event(event);
|
Frame::paint_event(event);
|
||||||
|
|
||||||
|
if (!m_dragging && !m_panning)
|
||||||
|
m_set.calculate();
|
||||||
|
|
||||||
GUI::Painter painter(*this);
|
GUI::Painter painter(*this);
|
||||||
painter.add_clip_rect(frame_inner_rect());
|
painter.add_clip_rect(frame_inner_rect());
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
@ -305,13 +305,11 @@ void Mandelbrot::mousedown_event(GUI::MouseEvent& event)
|
||||||
m_selection_start = event.position();
|
m_selection_start = event.position();
|
||||||
m_selection_end = event.position();
|
m_selection_end = event.position();
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
} else if (event.button() == GUI::MouseButton::Middle) {
|
} else if (event.button() == GUI::MouseButton::Middle) {
|
||||||
if (!m_panning) {
|
if (!m_panning) {
|
||||||
m_last_pan_position = event.position();
|
m_last_pan_position = event.position();
|
||||||
m_panning = true;
|
m_panning = true;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,10 +345,11 @@ void Mandelbrot::mouseup_event(GUI::MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (event.button() == GUI::MouseButton::Primary) {
|
if (event.button() == GUI::MouseButton::Primary) {
|
||||||
auto selection = Gfx::IntRect::from_two_points(m_selection_start, m_selection_end);
|
auto selection = Gfx::IntRect::from_two_points(m_selection_start, m_selection_end);
|
||||||
if (selection.width() > 0 && selection.height() > 0)
|
if (selection.width() > 0 && selection.height() > 0) {
|
||||||
m_set.zoom(selection);
|
m_set.zoom(selection);
|
||||||
|
update();
|
||||||
|
}
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
update();
|
|
||||||
} else if (event.button() == GUI::MouseButton::Middle) {
|
} else if (event.button() == GUI::MouseButton::Middle) {
|
||||||
m_panning = false;
|
m_panning = false;
|
||||||
update();
|
update();
|
||||||
|
@ -374,6 +373,7 @@ void Mandelbrot::resize_event(GUI::ResizeEvent& event)
|
||||||
ErrorOr<void> Mandelbrot::export_image(Core::File& export_file, ImageType image_type)
|
ErrorOr<void> Mandelbrot::export_image(Core::File& export_file, ImageType image_type)
|
||||||
{
|
{
|
||||||
m_set.resize(Gfx::IntSize { 1920, 1080 });
|
m_set.resize(Gfx::IntSize { 1920, 1080 });
|
||||||
|
m_set.calculate();
|
||||||
ByteBuffer encoded_data;
|
ByteBuffer encoded_data;
|
||||||
switch (image_type) {
|
switch (image_type) {
|
||||||
case ImageType::BMP:
|
case ImageType::BMP:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue