mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
More window management work.
- Fix inverted mouse event hit test z-ordering. - Let the RootWidget backing store simply be the display framebuffer.
This commit is contained in:
parent
723ff8c2ab
commit
4775fd88e3
5 changed files with 41 additions and 18 deletions
|
@ -6,15 +6,30 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size)
|
||||||
return adopt(*new GraphicsBitmap(size));
|
return adopt(*new GraphicsBitmap(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, byte* data)
|
||||||
|
{
|
||||||
|
return adopt(*new GraphicsBitmap(size, data));
|
||||||
|
}
|
||||||
|
|
||||||
GraphicsBitmap::GraphicsBitmap(const Size& size)
|
GraphicsBitmap::GraphicsBitmap(const Size& size)
|
||||||
: m_size(size)
|
: m_size(size)
|
||||||
{
|
{
|
||||||
m_data = (byte*)kmalloc(size.width() * size.height() * 4);
|
m_data = (byte*)kmalloc(size.width() * size.height() * 4);
|
||||||
|
m_owned = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsBitmap::GraphicsBitmap(const Size& size, byte* data)
|
||||||
|
: m_size(size)
|
||||||
|
{
|
||||||
|
m_data = data;
|
||||||
|
m_owned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsBitmap::~GraphicsBitmap()
|
GraphicsBitmap::~GraphicsBitmap()
|
||||||
{
|
{
|
||||||
kfree(m_data);
|
if (m_owned)
|
||||||
|
kfree(m_data);
|
||||||
|
m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
dword* GraphicsBitmap::scanline(int y)
|
dword* GraphicsBitmap::scanline(int y)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
||||||
public:
|
public:
|
||||||
static RetainPtr<GraphicsBitmap> create(const Size&);
|
static RetainPtr<GraphicsBitmap> create(const Size&);
|
||||||
|
static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, byte*);
|
||||||
~GraphicsBitmap();
|
~GraphicsBitmap();
|
||||||
|
|
||||||
dword* scanline(int y);
|
dword* scanline(int y);
|
||||||
|
@ -17,7 +18,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GraphicsBitmap(const Size&);
|
explicit GraphicsBitmap(const Size&);
|
||||||
|
GraphicsBitmap(const Size&, byte*);
|
||||||
|
|
||||||
Size m_size;
|
Size m_size;
|
||||||
byte* m_data { nullptr };
|
byte* m_data { nullptr };
|
||||||
|
bool m_owned { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
#include "RootWidget.h"
|
#include "RootWidget.h"
|
||||||
#include "Painter.h"
|
#include "Painter.h"
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
|
#include "FrameBufferSDL.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
RootWidget::RootWidget()
|
RootWidget::RootWidget()
|
||||||
{
|
{
|
||||||
m_backing = GraphicsBitmap::create(AbstractScreen::the().size());
|
m_backing = GraphicsBitmap::create_wrapper(FrameBufferSDL::the().size(), (byte*)FrameBufferSDL::the().scanline(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
RootWidget::~RootWidget()
|
RootWidget::~RootWidget()
|
||||||
|
|
|
@ -58,12 +58,6 @@ WindowManager::~WindowManager()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::paintWindowFrames()
|
|
||||||
{
|
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next())
|
|
||||||
paintWindowFrame(*window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowManager::paintWindowFrame(Window& window)
|
void WindowManager::paintWindowFrame(Window& window)
|
||||||
{
|
{
|
||||||
Painter p(*m_rootWidget);
|
Painter p(*m_rootWidget);
|
||||||
|
@ -139,15 +133,17 @@ void WindowManager::repaint()
|
||||||
handlePaintEvent(*make<PaintEvent>());
|
handlePaintEvent(*make<PaintEvent>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::did_paint(Window&)
|
void WindowManager::did_paint(Window& window)
|
||||||
{
|
{
|
||||||
auto& framebuffer = FrameBufferSDL::the();
|
auto& framebuffer = FrameBufferSDL::the();
|
||||||
framebuffer.blit({ 0, 0 }, *m_rootWidget->backing());
|
if (m_windows_in_order.head() == &window) {
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
ASSERT(window.backing());
|
||||||
ASSERT(window->backing());
|
framebuffer.blit(window.position(), *window.backing());
|
||||||
framebuffer.blit(window->position(), *window->backing());
|
return;
|
||||||
}
|
}
|
||||||
framebuffer.flush();
|
|
||||||
|
// FIXME: Check if anything overlaps this window, otherwise just blit.
|
||||||
|
recompose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::removeWindow(Window& window)
|
void WindowManager::removeWindow(Window& window)
|
||||||
|
@ -237,11 +233,12 @@ void WindowManager::processMouseEvent(MouseEvent& event)
|
||||||
pos.moveBy(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y());
|
pos.moveBy(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y());
|
||||||
m_dragWindow->setPositionWithoutRepaint(pos);
|
m_dragWindow->setPositionWithoutRepaint(pos);
|
||||||
paintWindowFrame(*m_dragWindow);
|
paintWindowFrame(*m_dragWindow);
|
||||||
|
FrameBufferSDL::the().flush();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) {
|
||||||
if (titleBarRectForWindow(*window).contains(event.position())) {
|
if (titleBarRectForWindow(*window).contains(event.position())) {
|
||||||
if (event.type() == Event::MouseDown) {
|
if (event.type() == Event::MouseDown) {
|
||||||
move_to_front(*window);
|
move_to_front(*window);
|
||||||
|
@ -273,14 +270,21 @@ void WindowManager::handlePaintEvent(PaintEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_rootWidget->event(event);
|
m_rootWidget->event(event);
|
||||||
paintWindowFrames();
|
|
||||||
|
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next())
|
for (auto* window = m_windows_in_order.head(); window; window = window->next())
|
||||||
window->event(event);
|
window->event(event);
|
||||||
|
|
||||||
|
recompose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowManager::recompose()
|
||||||
|
{
|
||||||
auto& framebuffer = FrameBufferSDL::the();
|
auto& framebuffer = FrameBufferSDL::the();
|
||||||
framebuffer.blit({ 0, 0 }, *m_rootWidget->backing());
|
m_rootWidget->repaint(m_rootWidget->rect());
|
||||||
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
||||||
|
paintWindowFrame(*window);
|
||||||
|
if (m_dragWindow.ptr() == window)
|
||||||
|
continue;
|
||||||
ASSERT(window->backing());
|
ASSERT(window->backing());
|
||||||
framebuffer.blit(window->position(), *window->backing());
|
framebuffer.blit(window->position(), *window->backing());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ public:
|
||||||
static WindowManager& the();
|
static WindowManager& the();
|
||||||
void addWindow(Window&);
|
void addWindow(Window&);
|
||||||
void removeWindow(Window&);
|
void removeWindow(Window&);
|
||||||
void paintWindowFrames();
|
|
||||||
|
|
||||||
void notifyTitleChanged(Window&);
|
void notifyTitleChanged(Window&);
|
||||||
void notifyRectChanged(Window&, const Rect& oldRect, const Rect& newRect);
|
void notifyRectChanged(Window&, const Rect& oldRect, const Rect& newRect);
|
||||||
|
@ -52,6 +51,7 @@ private:
|
||||||
Color m_inactiveWindowBorderColor;
|
Color m_inactiveWindowBorderColor;
|
||||||
Color m_inactiveWindowTitleColor;
|
Color m_inactiveWindowTitleColor;
|
||||||
|
|
||||||
|
void recompose();
|
||||||
void paintWindowFrame(Window&);
|
void paintWindowFrame(Window&);
|
||||||
HashTable<Window*> m_windows;
|
HashTable<Window*> m_windows;
|
||||||
InlineLinkedList<Window> m_windows_in_order;
|
InlineLinkedList<Window> m_windows_in_order;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue