mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
Keep back and front painters around in WindowManager.
The internal state never changes in some meaningful way for these (at this time.)
This commit is contained in:
parent
0ead888821
commit
cc0be2e78a
3 changed files with 26 additions and 28 deletions
|
@ -61,7 +61,7 @@ void AbstractScreen::on_receive_mouse_data(int dx, int dy, bool left_button, boo
|
||||||
EventLoop::main().postEvent(&WindowManager::the(), move(event));
|
EventLoop::main().postEvent(&WindowManager::the(), move(event));
|
||||||
}
|
}
|
||||||
if (m_cursor_location != prev_location || prev_left_button != left_button)
|
if (m_cursor_location != prev_location || prev_left_button != left_button)
|
||||||
WindowManager::the().redraw_cursor();
|
WindowManager::the().draw_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractScreen::on_key_pressed(Keyboard::Key key)
|
void AbstractScreen::on_key_pressed(Keyboard::Key key)
|
||||||
|
|
|
@ -113,6 +113,9 @@ WindowManager::WindowManager()
|
||||||
auto* region = current->allocate_region(LinearAddress(), size.width() * size.height() * sizeof(RGBA32), "BackBitmap", true, true, true);
|
auto* region = current->allocate_region(LinearAddress(), size.width() * size.height() * sizeof(RGBA32), "BackBitmap", true, true, true);
|
||||||
m_back_bitmap = GraphicsBitmap::create_wrapper(m_screen_rect.size(), (RGBA32*)region->linearAddress.get());
|
m_back_bitmap = GraphicsBitmap::create_wrapper(m_screen_rect.size(), (RGBA32*)region->linearAddress.get());
|
||||||
|
|
||||||
|
m_front_painter = make<Painter>(*m_front_bitmap);
|
||||||
|
m_back_painter = make<Painter>(*m_back_bitmap);
|
||||||
|
|
||||||
m_activeWindowBorderColor = Color(0, 64, 192);
|
m_activeWindowBorderColor = Color(0, 64, 192);
|
||||||
m_activeWindowTitleColor = Color::White;
|
m_activeWindowTitleColor = Color::White;
|
||||||
|
|
||||||
|
@ -132,8 +135,6 @@ WindowManager::~WindowManager()
|
||||||
|
|
||||||
void WindowManager::paintWindowFrame(Window& window)
|
void WindowManager::paintWindowFrame(Window& window)
|
||||||
{
|
{
|
||||||
Painter p(*m_back_bitmap);
|
|
||||||
|
|
||||||
//printf("[WM] paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height());
|
//printf("[WM] paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height());
|
||||||
|
|
||||||
auto titleBarRect = titleBarRectForWindow(window.rect());
|
auto titleBarRect = titleBarRectForWindow(window.rect());
|
||||||
|
@ -151,14 +152,11 @@ void WindowManager::paintWindowFrame(Window& window)
|
||||||
auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor;
|
auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor;
|
||||||
auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor;
|
auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor;
|
||||||
|
|
||||||
p.draw_rect(borderRect, Color::MidGray);
|
m_back_painter->draw_rect(borderRect, Color::MidGray);
|
||||||
p.draw_rect(outerRect, borderColor);
|
m_back_painter->draw_rect(outerRect, borderColor);
|
||||||
|
m_back_painter->fill_rect(titleBarRect, borderColor);
|
||||||
p.fill_rect(titleBarRect, borderColor);
|
m_back_painter->draw_rect(inner_border_rect, borderColor);
|
||||||
|
m_back_painter->draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
|
||||||
p.draw_rect(inner_border_rect, borderColor);
|
|
||||||
|
|
||||||
p.draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::addWindow(Window& window)
|
void WindowManager::addWindow(Window& window)
|
||||||
|
@ -280,39 +278,36 @@ void WindowManager::compose()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
Painter painter(*m_back_bitmap);
|
|
||||||
{
|
for (auto& r : m_invalidated_rects) {
|
||||||
for (auto& r : m_invalidated_rects) {
|
if (any_window_contains_rect(r))
|
||||||
if (any_window_contains_rect(r))
|
continue;
|
||||||
continue;
|
//dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
|
||||||
//dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
|
m_back_painter->fill_rect(r, Color(0, 72, 96));
|
||||||
painter.fill_rect(r, Color(0, 72, 96));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
||||||
if (!window->backing())
|
if (!window->backing())
|
||||||
continue;
|
continue;
|
||||||
paintWindowFrame(*window);
|
paintWindowFrame(*window);
|
||||||
painter.blit(window->position(), *window->backing());
|
m_back_painter->blit(window->position(), *window->backing());
|
||||||
}
|
}
|
||||||
for (auto& r : m_invalidated_rects)
|
for (auto& r : m_invalidated_rects)
|
||||||
flush(r);
|
flush(r);
|
||||||
redraw_cursor();
|
draw_cursor();
|
||||||
m_invalidated_rects.clear_with_capacity();
|
m_invalidated_rects.clear_with_capacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::redraw_cursor()
|
void WindowManager::draw_cursor()
|
||||||
{
|
{
|
||||||
auto cursor_location = m_framebuffer.cursor_location();
|
auto cursor_location = m_framebuffer.cursor_location();
|
||||||
Painter painter(*m_front_bitmap);
|
|
||||||
Rect cursor_rect { cursor_location.x(), cursor_location.y(), (int)m_cursor_bitmap_inner->width(), (int)m_cursor_bitmap_inner->height() };
|
Rect cursor_rect { cursor_location.x(), cursor_location.y(), (int)m_cursor_bitmap_inner->width(), (int)m_cursor_bitmap_inner->height() };
|
||||||
flush(m_last_cursor_rect.united(cursor_rect));
|
flush(m_last_cursor_rect.united(cursor_rect));
|
||||||
Color inner_color = Color::White;
|
Color inner_color = Color::White;
|
||||||
Color outer_color = Color::Black;
|
Color outer_color = Color::Black;
|
||||||
if (m_framebuffer.left_mouse_button_pressed())
|
if (m_framebuffer.left_mouse_button_pressed())
|
||||||
swap(inner_color, outer_color);
|
swap(inner_color, outer_color);
|
||||||
painter.draw_bitmap(cursor_location, *m_cursor_bitmap_inner, inner_color);
|
m_front_painter->draw_bitmap(cursor_location, *m_cursor_bitmap_inner, inner_color);
|
||||||
painter.draw_bitmap(cursor_location, *m_cursor_bitmap_outer, outer_color);
|
m_front_painter->draw_bitmap(cursor_location, *m_cursor_bitmap_outer, outer_color);
|
||||||
m_last_cursor_rect = cursor_rect;
|
m_last_cursor_rect = cursor_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,8 +397,7 @@ void WindowManager::flush(const Rect& a_rect)
|
||||||
size_t pitch = m_back_bitmap->pitch();
|
size_t pitch = m_back_bitmap->pitch();
|
||||||
|
|
||||||
#ifdef DEBUG_FLUSH_YELLOW
|
#ifdef DEBUG_FLUSH_YELLOW
|
||||||
Painter p(*m_front_bitmap);
|
m_front_painter->fill_rect(rect, Color::Yellow);
|
||||||
p.fill_rect(rect, Color::Yellow);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int y = 0; y < rect.height(); ++y) {
|
for (int y = 0; y < rect.height(); ++y) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include "Rect.h"
|
#include "Rect.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
#include "Painter.h"
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/InlineLinkedList.h>
|
#include <AK/InlineLinkedList.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
|
@ -35,7 +36,7 @@ public:
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
|
||||||
void redraw_cursor();
|
void draw_cursor();
|
||||||
|
|
||||||
void invalidate(const Window&);
|
void invalidate(const Window&);
|
||||||
void invalidate(const Rect&);
|
void invalidate(const Rect&);
|
||||||
|
@ -89,4 +90,7 @@ private:
|
||||||
|
|
||||||
RetainPtr<CharacterBitmap> m_cursor_bitmap_inner;
|
RetainPtr<CharacterBitmap> m_cursor_bitmap_inner;
|
||||||
RetainPtr<CharacterBitmap> m_cursor_bitmap_outer;
|
RetainPtr<CharacterBitmap> m_cursor_bitmap_outer;
|
||||||
|
|
||||||
|
OwnPtr<Painter> m_back_painter;
|
||||||
|
OwnPtr<Painter> m_front_painter;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue