|
@@ -5,15 +5,12 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <fcntl.h>
|
|
|
#include <assert.h>
|
|
|
-#include <Kernel/GUITypes.h>
|
|
|
#include <Kernel/Syscall.h>
|
|
|
-#include <AK/StdLibExtras.h>
|
|
|
+#include <Widgets/GraphicsBitmap.h>
|
|
|
+#include <Widgets/Painter.h>
|
|
|
+#include "gui.h"
|
|
|
|
|
|
-int gui_invalidate_window(int window_id)
|
|
|
-{
|
|
|
- int rc = syscall(SC_gui_invalidate_window, window_id);
|
|
|
- __RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
-}
|
|
|
+static void paint(GraphicsBitmap& bitmap, int width, int height);
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
{
|
|
@@ -21,7 +18,7 @@ int main(int argc, char** argv)
|
|
|
wparams.rect = { { 200, 200 }, { 300, 200 } };
|
|
|
wparams.background_color = 0xffc0c0;
|
|
|
strcpy(wparams.title, "GUI test app");
|
|
|
- int window_id = syscall(SC_gui_create_window, &wparams);
|
|
|
+ int window_id = gui_create_window(&wparams);
|
|
|
if (window_id < 0) {
|
|
|
perror("gui_create_window");
|
|
|
return 1;
|
|
@@ -34,15 +31,17 @@ int main(int argc, char** argv)
|
|
|
}
|
|
|
|
|
|
GUI_WindowBackingStoreInfo backing;
|
|
|
- int rc = syscall(SC_gui_get_window_backing_store, window_id, &backing);
|
|
|
+ int rc = gui_get_window_backing_store(window_id, &backing);
|
|
|
if (rc < 0) {
|
|
|
perror("gui_get_window_backing_store");
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- sys_printf("(Client) window backing %ux%u @ %p\n", backing.size.width, backing.size.height, backing.pixels);
|
|
|
+ auto bitmap = GraphicsBitmap::create_wrapper(backing.size, backing.pixels);
|
|
|
+
|
|
|
+ dbgprintf("(Client) window backing %ux%u @ %p\n", backing.size.width, backing.size.height, backing.pixels);
|
|
|
|
|
|
- fast_dword_fill(backing.pixels, 0x00ff00, backing.size.width * backing.size.height);
|
|
|
+ paint(*bitmap, backing.size.width, backing.size.height);
|
|
|
|
|
|
rc = gui_invalidate_window(window_id);
|
|
|
if (rc < 0) {
|
|
@@ -59,21 +58,28 @@ int main(int argc, char** argv)
|
|
|
}
|
|
|
assert(nread == sizeof(event));
|
|
|
switch (event.type) {
|
|
|
- case GUI_Event::Type::Paint: sys_printf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); break;
|
|
|
- case GUI_Event::Type::MouseDown: sys_printf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
|
|
- case GUI_Event::Type::MouseUp: sys_printf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
|
|
- case GUI_Event::Type::MouseMove: sys_printf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
|
|
+ case GUI_Event::Type::Paint: dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); break;
|
|
|
+ case GUI_Event::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
|
|
+ case GUI_Event::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
|
|
+ case GUI_Event::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
|
|
}
|
|
|
|
|
|
if (event.type == GUI_Event::Type::MouseDown) {
|
|
|
- byte r = rand() % 255;
|
|
|
- byte g = rand() % 255;
|
|
|
- byte b = rand() % 255;
|
|
|
- Color color(r, g, b);
|
|
|
- fast_dword_fill(backing.pixels, color.value(), backing.size.width * backing.size.height);
|
|
|
+ paint(*bitmap, backing.size.width, backing.size.height);
|
|
|
gui_invalidate_window(window_id);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+void paint(GraphicsBitmap& bitmap, int width, int height)
|
|
|
+{
|
|
|
+ byte r = rand() % 255;
|
|
|
+ byte g = rand() % 255;
|
|
|
+ byte b = rand() % 255;
|
|
|
+ Color color(r, g, b);
|
|
|
+ Painter painter(bitmap);
|
|
|
+ painter.fill_rect({0, 0, width, height}, color);
|
|
|
+ painter.draw_text({0, 0, width, height}, "Hello World!", Painter::TextAlignment::Center, Color::Black);
|
|
|
+}
|