mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
Start separating out the SDL-related stuff in Widgets.
This commit is contained in:
parent
077f1007eb
commit
3e908abfca
Notes:
sideshowbarker
2024-07-19 16:05:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3e908abfca0
9 changed files with 54 additions and 34 deletions
|
@ -1,9 +1,13 @@
|
|||
#include "Color.h"
|
||||
#include "FrameBufferSDL.h"
|
||||
#include "FrameBuffer.h"
|
||||
|
||||
Color::Color(byte r, byte g, byte b)
|
||||
{
|
||||
m_value = SDL_MapRGB(FrameBufferSDL::the().surface()->format, r, g, b);
|
||||
#ifdef USE_SDL
|
||||
m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, r, g, b);
|
||||
#else
|
||||
#error FIXME: Implement
|
||||
#endif
|
||||
}
|
||||
|
||||
Color::Color(NamedColor named)
|
||||
|
@ -26,6 +30,9 @@ Color::Color(NamedColor named)
|
|||
default: ASSERT_NOT_REACHED(); break;
|
||||
}
|
||||
|
||||
m_value = SDL_MapRGB(FrameBufferSDL::the().surface()->format, rgb.r, rgb.g, rgb.g);
|
||||
|
||||
#ifdef USE_SDL
|
||||
m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, rgb.r, rgb.g, rgb.g);
|
||||
#else
|
||||
#error FIXME: Implement
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,37 +1,41 @@
|
|||
#include "FrameBufferSDL.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "GraphicsBitmap.h"
|
||||
#include <AK/Assertions.h>
|
||||
|
||||
FrameBufferSDL* s_the = nullptr;
|
||||
FrameBuffer* s_the = nullptr;
|
||||
|
||||
FrameBufferSDL& FrameBufferSDL::the()
|
||||
FrameBuffer& FrameBuffer::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
FrameBufferSDL::FrameBufferSDL(unsigned width, unsigned height)
|
||||
FrameBuffer::FrameBuffer(unsigned width, unsigned height)
|
||||
: AbstractScreen(width, height)
|
||||
{
|
||||
ASSERT(!s_the);
|
||||
s_the = this;
|
||||
#ifdef USE_SDL
|
||||
initializeSDL();
|
||||
#endif
|
||||
}
|
||||
|
||||
FrameBufferSDL::~FrameBufferSDL()
|
||||
FrameBuffer::~FrameBuffer()
|
||||
{
|
||||
#ifdef USE_SDL
|
||||
SDL_DestroyWindow(m_window);
|
||||
m_surface = nullptr;
|
||||
m_window = nullptr;
|
||||
|
||||
SDL_Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrameBufferSDL::show()
|
||||
void FrameBuffer::show()
|
||||
{
|
||||
}
|
||||
|
||||
void FrameBufferSDL::initializeSDL()
|
||||
#ifdef USE_SDL
|
||||
void FrameBuffer::initializeSDL()
|
||||
{
|
||||
if (m_window)
|
||||
return;
|
||||
|
@ -57,13 +61,16 @@ void FrameBufferSDL::initializeSDL()
|
|||
|
||||
SDL_UpdateWindowSurface(m_window);
|
||||
}
|
||||
#endif
|
||||
|
||||
dword* FrameBufferSDL::scanline(int y)
|
||||
dword* FrameBuffer::scanline(int y)
|
||||
{
|
||||
#ifdef USE_SDL
|
||||
return (dword*)(((byte*)m_surface->pixels) + (y * m_surface->pitch));
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrameBufferSDL::blit(const Point& position, GraphicsBitmap& bitmap)
|
||||
void FrameBuffer::blit(const Point& position, GraphicsBitmap& bitmap)
|
||||
{
|
||||
Rect dst_rect(position, bitmap.size());
|
||||
//printf("blit at %d,%d %dx%d\n", dst_rect.x(), dst_rect.y(), dst_rect.width(), dst_rect.height());
|
||||
|
@ -77,7 +84,9 @@ void FrameBufferSDL::blit(const Point& position, GraphicsBitmap& bitmap)
|
|||
}
|
||||
}
|
||||
|
||||
void FrameBufferSDL::flush()
|
||||
void FrameBuffer::flush()
|
||||
{
|
||||
#ifdef USE_SDL
|
||||
SDL_UpdateWindowSurface(m_window);
|
||||
#endif
|
||||
}
|
|
@ -1,21 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractScreen.h"
|
||||
|
||||
#ifdef USE_SDL
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
class GraphicsBitmap;
|
||||
|
||||
class FrameBufferSDL final : public AbstractScreen {
|
||||
class FrameBuffer final : public AbstractScreen {
|
||||
public:
|
||||
FrameBufferSDL(unsigned width, unsigned height);
|
||||
virtual ~FrameBufferSDL() override;
|
||||
FrameBuffer(unsigned width, unsigned height);
|
||||
virtual ~FrameBuffer() override;
|
||||
|
||||
void show();
|
||||
|
||||
#ifdef USE_SDL
|
||||
SDL_Surface* surface() { return m_surface; }
|
||||
SDL_Window* window() { return m_window; }
|
||||
#endif
|
||||
|
||||
static FrameBufferSDL& the();
|
||||
static FrameBuffer& the();
|
||||
|
||||
dword* scanline(int y);
|
||||
|
||||
|
@ -23,9 +27,10 @@ public:
|
|||
void flush();
|
||||
|
||||
private:
|
||||
#ifdef USE_SDL
|
||||
void initializeSDL();
|
||||
|
||||
SDL_Window* m_window { nullptr };
|
||||
SDL_Surface* m_surface { nullptr };
|
||||
#endif
|
||||
};
|
||||
|
|
@ -8,7 +8,7 @@ AK_OBJS = \
|
|||
|
||||
VFS_OBJS = \
|
||||
AbstractScreen.o \
|
||||
FrameBufferSDL.o \
|
||||
FrameBuffer.o \
|
||||
EventLoop.o \
|
||||
EventLoopSDL.o \
|
||||
Rect.o \
|
||||
|
|
|
@ -72,7 +72,7 @@ void Object::startTimer(int ms)
|
|||
printf("Object{%p} already has a timer!\n", this);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
#if USE_SDL
|
||||
#ifdef USE_SDL
|
||||
m_timerID = SDL_AddTimer(ms, sdlTimerCallback, this);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include "Painter.h"
|
||||
#include "FrameBufferSDL.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "Widget.h"
|
||||
#include "Font.h"
|
||||
#include "Window.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <SDL.h>
|
||||
|
||||
Painter::Painter(Widget& widget)
|
||||
: m_widget(widget)
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#include "RootWidget.h"
|
||||
#include "Painter.h"
|
||||
#include "WindowManager.h"
|
||||
#include "FrameBufferSDL.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include <cstdio>
|
||||
|
||||
RootWidget::RootWidget()
|
||||
{
|
||||
setWindowRelativeRect(FrameBufferSDL::the().rect());
|
||||
m_backing = GraphicsBitmap::create_wrapper(size(), (byte*)FrameBufferSDL::the().scanline(0));
|
||||
setWindowRelativeRect(FrameBuffer::the().rect());
|
||||
m_backing = GraphicsBitmap::create_wrapper(size(), (byte*)FrameBuffer::the().scanline(0));
|
||||
}
|
||||
|
||||
RootWidget::~RootWidget()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Window.h"
|
||||
#include "AbstractScreen.h"
|
||||
#include "EventLoop.h"
|
||||
#include "FrameBufferSDL.h"
|
||||
#include "FrameBuffer.h"
|
||||
|
||||
static const int windowFrameWidth = 2;
|
||||
static const int windowTitleBarHeight = 16;
|
||||
|
@ -144,7 +144,7 @@ void WindowManager::repaint()
|
|||
|
||||
void WindowManager::did_paint(Window& window)
|
||||
{
|
||||
auto& framebuffer = FrameBufferSDL::the();
|
||||
auto& framebuffer = FrameBuffer::the();
|
||||
if (m_windows_in_order.tail() == &window) {
|
||||
ASSERT(window.backing());
|
||||
framebuffer.blit(window.position(), *window.backing());
|
||||
|
@ -214,7 +214,7 @@ void WindowManager::processMouseEvent(MouseEvent& event)
|
|||
pos.moveBy(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y());
|
||||
m_dragWindow->setPositionWithoutRepaint(pos);
|
||||
paintWindowFrame(*m_dragWindow);
|
||||
FrameBufferSDL::the().flush();
|
||||
FrameBuffer::the().flush();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ void WindowManager::handlePaintEvent(PaintEvent& event)
|
|||
void WindowManager::recompose()
|
||||
{
|
||||
printf("[WM] recompose_count: %u\n", ++m_recompose_count);
|
||||
auto& framebuffer = FrameBufferSDL::the();
|
||||
auto& framebuffer = FrameBuffer::the();
|
||||
PaintEvent dummy_event(m_rootWidget->rect());
|
||||
m_rootWidget->paintEvent(dummy_event);
|
||||
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "FrameBufferSDL.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "EventLoopSDL.h"
|
||||
#include "RootWidget.h"
|
||||
#include "Label.h"
|
||||
|
@ -14,7 +14,7 @@
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FrameBufferSDL fb(800, 600);
|
||||
FrameBuffer fb(800, 600);
|
||||
fb.show();
|
||||
|
||||
EventLoopSDL loop;
|
||||
|
|
Loading…
Add table
Reference in a new issue