diff --git a/Widgets/ColorSDL.cpp b/Widgets/ColorSDL.cpp index 45c7ff5f772..dd7f5d5f798 100644 --- a/Widgets/ColorSDL.cpp +++ b/Widgets/ColorSDL.cpp @@ -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 } diff --git a/Widgets/FrameBufferSDL.cpp b/Widgets/FrameBuffer.cpp similarity index 76% rename from Widgets/FrameBufferSDL.cpp rename to Widgets/FrameBuffer.cpp index 4d3b4f6c6b4..2cfae7ac198 100644 --- a/Widgets/FrameBufferSDL.cpp +++ b/Widgets/FrameBuffer.cpp @@ -1,37 +1,41 @@ -#include "FrameBufferSDL.h" +#include "FrameBuffer.h" #include "GraphicsBitmap.h" #include -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 } diff --git a/Widgets/FrameBufferSDL.h b/Widgets/FrameBuffer.h similarity index 61% rename from Widgets/FrameBufferSDL.h rename to Widgets/FrameBuffer.h index dbad8f6ae31..7fd85346a8d 100644 --- a/Widgets/FrameBufferSDL.h +++ b/Widgets/FrameBuffer.h @@ -1,21 +1,25 @@ #pragma once #include "AbstractScreen.h" + +#ifdef USE_SDL #include +#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 }; diff --git a/Widgets/Makefile b/Widgets/Makefile index 85d88630985..3be526f0b73 100644 --- a/Widgets/Makefile +++ b/Widgets/Makefile @@ -8,7 +8,7 @@ AK_OBJS = \ VFS_OBJS = \ AbstractScreen.o \ - FrameBufferSDL.o \ + FrameBuffer.o \ EventLoop.o \ EventLoopSDL.o \ Rect.o \ diff --git a/Widgets/Object.cpp b/Widgets/Object.cpp index f5bb856be8a..3380b4faa99 100644 --- a/Widgets/Object.cpp +++ b/Widgets/Object.cpp @@ -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 } diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index 5a1a071d528..e202165b4ed 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -1,11 +1,10 @@ #include "Painter.h" -#include "FrameBufferSDL.h" +#include "FrameBuffer.h" #include "Widget.h" #include "Font.h" #include "Window.h" #include #include -#include Painter::Painter(Widget& widget) : m_widget(widget) diff --git a/Widgets/RootWidget.cpp b/Widgets/RootWidget.cpp index 0ffc1267e0a..df0d4b34f82 100644 --- a/Widgets/RootWidget.cpp +++ b/Widgets/RootWidget.cpp @@ -3,13 +3,13 @@ #include "RootWidget.h" #include "Painter.h" #include "WindowManager.h" -#include "FrameBufferSDL.h" +#include "FrameBuffer.h" #include 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() diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index df1bc47b829..b5dcdbd4293 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -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()) { diff --git a/Widgets/test.cpp b/Widgets/test.cpp index 04374b0f1a3..01f77d2d487 100644 --- a/Widgets/test.cpp +++ b/Widgets/test.cpp @@ -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;