mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 22:17:43 +00:00
So long SDL stuff. You were a nice bootstrapping environment.
This commit is contained in:
parent
0c5ecd303c
commit
bfef4afa6a
7 changed files with 0 additions and 264 deletions
|
@ -3,11 +3,8 @@
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
#include "AbstractScreen.h"
|
#include "AbstractScreen.h"
|
||||||
|
|
||||||
#ifdef SERENITY
|
|
||||||
#include "PS2MouseDevice.h"
|
#include "PS2MouseDevice.h"
|
||||||
#include "Scheduler.h"
|
#include "Scheduler.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
static EventLoop* s_mainEventLoop;
|
static EventLoop* s_mainEventLoop;
|
||||||
|
|
||||||
|
@ -34,9 +31,7 @@ EventLoop& EventLoop::main()
|
||||||
|
|
||||||
int EventLoop::exec()
|
int EventLoop::exec()
|
||||||
{
|
{
|
||||||
#ifdef SERENITY
|
|
||||||
m_server_process = current;
|
m_server_process = current;
|
||||||
#endif
|
|
||||||
m_running = true;
|
m_running = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (m_queuedEvents.is_empty())
|
if (m_queuedEvents.is_empty())
|
||||||
|
@ -73,7 +68,6 @@ void EventLoop::postEvent(Object* receiver, OwnPtr<Event>&& event)
|
||||||
m_queuedEvents.append({ receiver, move(event) });
|
m_queuedEvents.append({ receiver, move(event) });
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SERENITY
|
|
||||||
void EventLoop::waitForEvent()
|
void EventLoop::waitForEvent()
|
||||||
{
|
{
|
||||||
auto& mouse = PS2MouseDevice::the();
|
auto& mouse = PS2MouseDevice::the();
|
||||||
|
@ -99,110 +93,3 @@ void EventLoop::waitForEvent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
static inline MouseButton toMouseButton(byte sdlButton)
|
|
||||||
{
|
|
||||||
if (sdlButton == 1)
|
|
||||||
return MouseButton::Left;
|
|
||||||
if (sdlButton == 2)
|
|
||||||
return MouseButton::Middle;
|
|
||||||
if (sdlButton == 3)
|
|
||||||
return MouseButton::Right;
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
return MouseButton::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventLoop::handleKeyEvent(Event::Type type, const SDL_KeyboardEvent& sdlKey)
|
|
||||||
{
|
|
||||||
auto keyEvent = make<KeyEvent>(type, 0);
|
|
||||||
int key = 0;
|
|
||||||
|
|
||||||
switch (sdlKey.keysym.sym) {
|
|
||||||
case SDLK_LEFT: key = KeyboardKey::LeftArrow; break;
|
|
||||||
case SDLK_RIGHT: key = KeyboardKey::RightArrow; break;
|
|
||||||
case SDLK_UP: key = KeyboardKey::UpArrow; break;
|
|
||||||
case SDLK_DOWN: key = KeyboardKey::DownArrow; break;
|
|
||||||
case SDLK_BACKSPACE: key = KeyboardKey::Backspace; break;
|
|
||||||
case SDLK_RETURN: key = KeyboardKey::Return; break;
|
|
||||||
}
|
|
||||||
keyEvent->m_key = key;
|
|
||||||
|
|
||||||
if (sdlKey.keysym.sym > SDLK_UNKNOWN && sdlKey.keysym.sym <= 'z') {
|
|
||||||
char buf[] = { 0, 0 };
|
|
||||||
char& ch = buf[0];
|
|
||||||
ch = (char)sdlKey.keysym.sym;
|
|
||||||
if (sdlKey.keysym.mod & KMOD_SHIFT) {
|
|
||||||
if (ch >= 'a' && ch <= 'z') {
|
|
||||||
ch &= ~0x20;
|
|
||||||
} else {
|
|
||||||
switch (ch) {
|
|
||||||
case '1': ch = '!'; break;
|
|
||||||
case '2': ch = '@'; break;
|
|
||||||
case '3': ch = '#'; break;
|
|
||||||
case '4': ch = '$'; break;
|
|
||||||
case '5': ch = '%'; break;
|
|
||||||
case '6': ch = '^'; break;
|
|
||||||
case '7': ch = '&'; break;
|
|
||||||
case '8': ch = '*'; break;
|
|
||||||
case '9': ch = '('; break;
|
|
||||||
case '0': ch = ')'; break;
|
|
||||||
case '-': ch = '_'; break;
|
|
||||||
case '=': ch = '+'; break;
|
|
||||||
case '`': ch = '~'; break;
|
|
||||||
case ',': ch = '<'; break;
|
|
||||||
case '.': ch = '>'; break;
|
|
||||||
case '/': ch = '?'; break;
|
|
||||||
case '[': ch = '{'; break;
|
|
||||||
case ']': ch = '}'; break;
|
|
||||||
case '\\': ch = '|'; break;
|
|
||||||
case '\'': ch = '"'; break;
|
|
||||||
case ';': ch = ':'; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keyEvent->m_text = buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
keyEvent->m_shift = sdlKey.keysym.mod & KMOD_SHIFT;
|
|
||||||
keyEvent->m_ctrl = sdlKey.keysym.mod & KMOD_CTRL;
|
|
||||||
keyEvent->m_alt = sdlKey.keysym.mod & KMOD_ALT;
|
|
||||||
|
|
||||||
postEvent(&WindowManager::the(), move(keyEvent));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventLoop::waitForEvent()
|
|
||||||
{
|
|
||||||
SDL_Event sdlEvent;
|
|
||||||
while (SDL_PollEvent(&sdlEvent) != 0) {
|
|
||||||
switch (sdlEvent.type) {
|
|
||||||
case SDL_QUIT:
|
|
||||||
postEvent(nullptr, make<QuitEvent>());
|
|
||||||
return;
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
if (sdlEvent.window.event == SDL_WINDOWEVENT_EXPOSED) {
|
|
||||||
// Spam paint events whenever we get exposed.
|
|
||||||
// This is obviously not ideal, but the SDL backend here is just a prototype anyway.
|
|
||||||
postEvent(&WindowManager::the(), make<PaintEvent>());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
postEvent(&WindowManager::the(), make<MouseEvent>(Event::MouseMove, sdlEvent.motion.x, sdlEvent.motion.y));
|
|
||||||
return;
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
postEvent(&WindowManager::the(), make<MouseEvent>(Event::MouseDown, sdlEvent.button.x, sdlEvent.button.y, toMouseButton(sdlEvent.button.button)));
|
|
||||||
return;
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
postEvent(&WindowManager::the(), make<MouseEvent>(Event::MouseUp, sdlEvent.button.x, sdlEvent.button.y, toMouseButton(sdlEvent.button.button)));
|
|
||||||
return;
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
handleKeyEvent(Event::KeyDown, sdlEvent.key);
|
|
||||||
return;
|
|
||||||
case SDL_KEYUP:
|
|
||||||
handleKeyEvent(Event::KeyUp, sdlEvent.key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -4,10 +4,6 @@
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
#include <SDL.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Object;
|
class Object;
|
||||||
class Process;
|
class Process;
|
||||||
|
|
||||||
|
@ -30,10 +26,6 @@ public:
|
||||||
private:
|
private:
|
||||||
void waitForEvent();
|
void waitForEvent();
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
void handleKeyEvent(Event::Type, const SDL_KeyboardEvent&);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct QueuedEvent {
|
struct QueuedEvent {
|
||||||
Object* receiver { nullptr };
|
Object* receiver { nullptr };
|
||||||
OwnPtr<Event> event;
|
OwnPtr<Event> event;
|
||||||
|
|
|
@ -20,16 +20,11 @@ FrameBuffer::FrameBuffer(unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
ASSERT(!s_the);
|
ASSERT(!s_the);
|
||||||
s_the = this;
|
s_the = this;
|
||||||
#ifdef USE_SDL
|
|
||||||
initializeSDL();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBuffer::FrameBuffer(RGBA32* data, unsigned width, unsigned height)
|
FrameBuffer::FrameBuffer(RGBA32* data, unsigned width, unsigned height)
|
||||||
: AbstractScreen(width, height)
|
: AbstractScreen(width, height)
|
||||||
#ifdef SERENITY
|
|
||||||
, m_data(data)
|
, m_data(data)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ASSERT(!s_the);
|
ASSERT(!s_the);
|
||||||
s_the = this;
|
s_the = this;
|
||||||
|
@ -38,61 +33,14 @@ FrameBuffer::FrameBuffer(RGBA32* data, unsigned width, unsigned height)
|
||||||
|
|
||||||
FrameBuffer::~FrameBuffer()
|
FrameBuffer::~FrameBuffer()
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL
|
|
||||||
SDL_DestroyWindow(m_window);
|
|
||||||
m_surface = nullptr;
|
|
||||||
m_window = nullptr;
|
|
||||||
SDL_Quit();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBuffer::show()
|
void FrameBuffer::show()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
void FrameBuffer::initializeSDL()
|
|
||||||
{
|
|
||||||
if (m_window)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_window = SDL_CreateWindow(
|
|
||||||
"FrameBuffer",
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
width(),
|
|
||||||
height(),
|
|
||||||
SDL_WINDOW_SHOWN);
|
|
||||||
|
|
||||||
ASSERT(m_window);
|
|
||||||
|
|
||||||
m_surface = SDL_GetWindowSurface(m_window);
|
|
||||||
ASSERT(m_surface);
|
|
||||||
|
|
||||||
SDL_FillRect(m_surface, nullptr, SDL_MapRGB(m_surface->format, 0xff, 0xff, 0xff));
|
|
||||||
|
|
||||||
SDL_UpdateWindowSurface(m_window);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RGBA32* FrameBuffer::scanline(int y)
|
RGBA32* FrameBuffer::scanline(int y)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL
|
|
||||||
return reinterpret_cast<RGBA32*>(((byte*)m_surface->pixels) + (y * m_surface->pitch));
|
|
||||||
#endif
|
|
||||||
#ifdef SERENITY
|
|
||||||
unsigned pitch = sizeof(RGBA32) * width();
|
unsigned pitch = sizeof(RGBA32) * width();
|
||||||
return reinterpret_cast<RGBA32*>(((byte*)m_data) + (y * pitch));
|
return reinterpret_cast<RGBA32*>(((byte*)m_data) + (y * pitch));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
void FrameBuffer::flush()
|
|
||||||
{
|
|
||||||
SDL_UpdateWindowSurface(m_window);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
#include "AbstractScreen.h"
|
#include "AbstractScreen.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
#include <SDL.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class GraphicsBitmap;
|
class GraphicsBitmap;
|
||||||
|
|
||||||
class FrameBuffer final : public AbstractScreen {
|
class FrameBuffer final : public AbstractScreen {
|
||||||
|
@ -17,30 +13,13 @@ public:
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
SDL_Surface* surface() { return m_surface; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static FrameBuffer& the();
|
static FrameBuffer& the();
|
||||||
|
|
||||||
RGBA32* scanline(int y);
|
RGBA32* scanline(int y);
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
void flush();
|
|
||||||
#else
|
|
||||||
void flush() { }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef USE_SDL
|
|
||||||
void initializeSDL();
|
|
||||||
SDL_Window* m_window { nullptr };
|
|
||||||
SDL_Surface* m_surface { nullptr };
|
|
||||||
#endif
|
|
||||||
#ifdef SERENITY
|
|
||||||
RGBA32* m_data { nullptr };
|
RGBA32* m_data { nullptr };
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
PROGRAM = test
|
|
||||||
|
|
||||||
AK_OBJS = \
|
|
||||||
../AK/String.o \
|
|
||||||
../AK/StringImpl.o \
|
|
||||||
../AK/SimpleMalloc.o \
|
|
||||||
../AK/kmalloc.o
|
|
||||||
|
|
||||||
VFS_OBJS = \
|
|
||||||
AbstractScreen.o \
|
|
||||||
FrameBuffer.o \
|
|
||||||
EventLoop.o \
|
|
||||||
Rect.o \
|
|
||||||
Object.o \
|
|
||||||
Widget.o \
|
|
||||||
Color.o \
|
|
||||||
Painter.o \
|
|
||||||
Label.o \
|
|
||||||
Button.o \
|
|
||||||
WindowManager.o \
|
|
||||||
Font.o \
|
|
||||||
Window.o \
|
|
||||||
ClockWidget.o \
|
|
||||||
CharacterBitmap.o \
|
|
||||||
CheckBox.o \
|
|
||||||
ListBox.o \
|
|
||||||
TextBox.o \
|
|
||||||
MsgBox.o \
|
|
||||||
GraphicsBitmap.o \
|
|
||||||
test.o
|
|
||||||
|
|
||||||
OBJS = $(AK_OBJS) $(VFS_OBJS)
|
|
||||||
|
|
||||||
CXXFLAGS = -std=c++17 -O0 -W -Wall -Wextra -Wconversion -I. -I.. -ggdb3 `sdl2-config --cflags` -DUSE_SDL
|
|
||||||
|
|
||||||
LDFLAGS = `sdl2-config --libs`
|
|
||||||
|
|
||||||
#test.o: BlockDevice.h FileBackedBlockDevice.h FileSystem.h Ext2FileSystem.h VirtualFileSystem.h FileHandle.h
|
|
||||||
|
|
||||||
all: $(PROGRAM)
|
|
||||||
|
|
||||||
.cpp.o:
|
|
||||||
$(CXX) $(CXXFLAGS) -o $@ -c $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(OBJS) $(PROGRAM)
|
|
||||||
|
|
||||||
$(PROGRAM): $(OBJS)
|
|
||||||
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
#include "EventLoop.h"
|
#include "EventLoop.h"
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
#include <SDL.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Object::Object(Object* parent)
|
Object::Object(Object* parent)
|
||||||
: m_parent(parent)
|
: m_parent(parent)
|
||||||
{
|
{
|
||||||
|
@ -58,32 +54,18 @@ void Object::timerEvent(TimerEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_SDL
|
|
||||||
static dword sdlTimerCallback(dword interval, void* param)
|
|
||||||
{
|
|
||||||
EventLoop::main().postEvent(static_cast<Object*>(param), make<TimerEvent>());
|
|
||||||
return interval;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Object::startTimer(int ms)
|
void Object::startTimer(int ms)
|
||||||
{
|
{
|
||||||
if (m_timerID) {
|
if (m_timerID) {
|
||||||
printf("Object{%p} already has a timer!\n", this);
|
printf("Object{%p} already has a timer!\n", this);
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
#ifdef USE_SDL
|
|
||||||
m_timerID = SDL_AddTimer(ms, sdlTimerCallback, this);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::stopTimer()
|
void Object::stopTimer()
|
||||||
{
|
{
|
||||||
if (!m_timerID)
|
if (!m_timerID)
|
||||||
return;
|
return;
|
||||||
#ifdef USE_SDL
|
|
||||||
SDL_RemoveTimer(m_timerID);
|
|
||||||
#endif
|
|
||||||
m_timerID = 0;
|
m_timerID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,4 @@ void WindowManager::flush(const Rect& a_rect)
|
||||||
front_ptr = (RGBA32*)((byte*)front_ptr + pitch);
|
front_ptr = (RGBA32*)((byte*)front_ptr + pitch);
|
||||||
back_ptr = (const RGBA32*)((const byte*)back_ptr + pitch);
|
back_ptr = (const RGBA32*)((const byte*)back_ptr + pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_framebuffer.flush();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue