mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 20:45:08 +00:00
More window manager hacking. Get rid of TerminalWidget for now.
This commit is contained in:
parent
ceb373cf71
commit
077f1007eb
7 changed files with 18 additions and 34 deletions
|
@ -2,13 +2,9 @@
|
|||
#include "Event.h"
|
||||
#include <SDL.h>
|
||||
#include "Widget.h"
|
||||
#include "TerminalWidget.h"
|
||||
#include "WindowManager.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int g_fd;
|
||||
extern TerminalWidget* g_tw;
|
||||
|
||||
EventLoopSDL::EventLoopSDL()
|
||||
{
|
||||
}
|
||||
|
@ -119,20 +115,5 @@ void EventLoopSDL::waitForEvent()
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(g_fd, &rfds);
|
||||
|
||||
struct timeval tv = { 0, 5000 };
|
||||
int rc = select(g_fd + 1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
//printf("select{%d} = %d\n", g_fd, rc);
|
||||
|
||||
if (rc > 0) {
|
||||
byte buf[1024];
|
||||
int nread = read(g_fd, buf, sizeof(buf));
|
||||
g_tw->onReceive(ByteBuffer::wrap(buf, nread));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ GraphicsBitmap::GraphicsBitmap(const Size& size)
|
|||
: m_size(size)
|
||||
{
|
||||
m_data = (byte*)kmalloc(size.width() * size.height() * 4);
|
||||
memset(m_data, 0, size.width() * size.height() * 4);
|
||||
m_owned = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ VFS_OBJS = \
|
|||
Painter.o \
|
||||
Label.o \
|
||||
Button.o \
|
||||
TerminalWidget.o \
|
||||
WindowManager.o \
|
||||
Font.o \
|
||||
Window.o \
|
||||
|
|
|
@ -102,6 +102,9 @@ void Painter::drawText(const Rect& rect, const String& text, TextAlignment align
|
|||
|
||||
if (alignment == TextAlignment::TopLeft) {
|
||||
point = rect.location();
|
||||
} else if (alignment == TextAlignment::CenterLeft) {
|
||||
int textWidth = text.length() * font().glyphWidth();
|
||||
point = { rect.x(), rect.center().y() - (font().glyphHeight() / 2) };
|
||||
} else if (alignment == TextAlignment::Center) {
|
||||
int textWidth = text.length() * font().glyphWidth();
|
||||
point = rect.center();
|
||||
|
|
|
@ -14,7 +14,7 @@ class Window;
|
|||
|
||||
class Painter {
|
||||
public:
|
||||
enum class TextAlignment { TopLeft, Center };
|
||||
enum class TextAlignment { TopLeft, CenterLeft, Center };
|
||||
explicit Painter(Widget&);
|
||||
~Painter();
|
||||
void fillRect(const Rect&, Color);
|
||||
|
|
|
@ -3,12 +3,9 @@
|
|||
#include "Widget.h"
|
||||
#include "Window.h"
|
||||
#include "AbstractScreen.h"
|
||||
#include "TerminalWidget.h"
|
||||
#include "EventLoop.h"
|
||||
#include "FrameBufferSDL.h"
|
||||
|
||||
extern TerminalWidget* g_tw;
|
||||
|
||||
static const int windowFrameWidth = 2;
|
||||
static const int windowTitleBarHeight = 16;
|
||||
|
||||
|
@ -22,6 +19,17 @@ static inline Rect titleBarRectForWindow(const Window& window)
|
|||
};
|
||||
}
|
||||
|
||||
static inline Rect titleBarTitleRectForWindow(const Window& window)
|
||||
{
|
||||
auto titleBarRect = titleBarRectForWindow(window);
|
||||
return {
|
||||
titleBarRect.x() + windowFrameWidth,
|
||||
titleBarRect.y(),
|
||||
titleBarRect.width() - windowFrameWidth * 2,
|
||||
titleBarRect.height()
|
||||
};
|
||||
}
|
||||
|
||||
static inline Rect borderRectForWindow(const Window& window)
|
||||
{
|
||||
auto titleBarRect = titleBarRectForWindow(window);
|
||||
|
@ -65,6 +73,7 @@ void WindowManager::paintWindowFrame(Window& window)
|
|||
//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);
|
||||
auto titleBarTitleRect = titleBarTitleRectForWindow(window);
|
||||
auto outerRect = outerRectForWindow(window);
|
||||
auto borderRect = borderRectForWindow(window);
|
||||
|
||||
|
@ -111,7 +120,7 @@ void WindowManager::paintWindowFrame(Window& window)
|
|||
p.fillRect(leftRect, borderColor);
|
||||
p.fillRect(rightRect, borderColor);
|
||||
|
||||
p.drawText(titleBarRect, window.title(), Painter::TextAlignment::Center, titleColor);
|
||||
p.drawText(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
|
||||
}
|
||||
|
||||
void WindowManager::addWindow(Window& window)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "RootWidget.h"
|
||||
#include "Label.h"
|
||||
#include "Button.h"
|
||||
#include "TerminalWidget.h"
|
||||
#include "WindowManager.h"
|
||||
#include "Window.h"
|
||||
#include "ClockWidget.h"
|
||||
|
@ -92,14 +91,6 @@ int main(int argc, char** argv)
|
|||
WindowManager::the().setActiveWindow(widgetTestWindow);
|
||||
}
|
||||
|
||||
auto* win = new Window;
|
||||
win->setTitle("Console");
|
||||
win->setRect({ 100, 300, 644, 254 });
|
||||
|
||||
auto* t = new TerminalWidget(nullptr);
|
||||
win->setMainWidget(t);
|
||||
t->setFocus(true);
|
||||
|
||||
#if 0
|
||||
auto* clockWin = new Window;
|
||||
clockWin->setTitle("Clock");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue