--- /dev/null
+src/event.d
+src/geom.d
+src/gfx.d
+src/keyboard.d
+src/main.d
+src/mouse.d
+src/window.d
+src/winnie.d
+src/wm.d
int mouse_fd = get_mouse_fd();
for(;;) {
+ wm->process_windows();
+
fd_set read_set;
FD_ZERO(&read_set);
if(FD_ISSET(mouse_fd, &read_set)) {
process_mouse_event();
}
-
- wm->process_windows();
}
}
--- /dev/null
+#include "geom.h"
+
+static inline int min(int x, int y)
+{
+ return x < y ? x : y;
+}
+
+static inline int max(int x, int y)
+{
+ return x > y ? x : y;
+}
+
+Rect rect_union(const Rect &a, const Rect &b)
+{
+ Rect uni;
+ uni.x = min(a.x, b.x);
+ uni.y = min(a.y, b.y);
+ uni.width = max(a.x + a.width, b.x + b.width) - uni.x;
+ uni.height = max(a.y + a.height, b.y + b.height) - uni.y;
+
+ return uni;
+}
+
+Rect rect_intersection(const Rect &a, const Rect &b)
+{
+ Rect intersect;
+ intersect.x = max(a.x, b.x);
+ intersect.y = max(a.y, b.y);
+ intersect.width = max(min(a.x + a.width, b.x + b.width) - intersect.x, 0);
+ intersect.height = max(min(a.y + a.height, b.y + b.height) - intersect.y, 0);
+
+ return intersect;
+}
void fill_rect(const Rect &rect, int r, int g, int b)
{
- unsigned char *fb = framebuffer + rect.x + screen_rect.width * rect.y;
+ unsigned char *fb = framebuffer + (rect.x + screen_rect.width * rect.y) * 4;
for(int i=0; i<rect.height; i++) {
for(int j=0; j<rect.width; j++) {
- fb[j * 4] = r;
+ fb[j * 4] = b;
fb[j * 4 + 1] = g;
- fb[j * 4 + 2] = b;
+ fb[j * 4 + 2] = r;
}
fb += screen_rect.width * 4;
}
#include <stdio.h>
+#include <stdlib.h>
-#include "gfx.h"
+#include "winnie.h"
+
+static void display(Window *win);
+static void keyboard(Window *win, int key, bool pressed);
+static void cleanup();
int main()
{
- if(!init_gfx()) {
- return 1;
- }
+ winnie_init();
+ atexit(cleanup);
+
+ Window *win1 = new Window;
+ win1->set_title("title1");
+ win1->move(5, 10);
+ win1->resize(600, 800);
+ win1->set_display_callback(display);
+ win1->set_keyboard_callback(keyboard);
+
+ wm->add_window(win1);
- set_cursor_visibility(false);
-
- unsigned char* fb = get_framebuffer();
- Rect scrn_sz = get_screen_size();
-
- for(int i=0; i<scrn_sz.height; i++) {
- for(int j=0; j<scrn_sz.width; j++) {
- unsigned char color0[3] = {255, 0, 0};
- unsigned char color1[3] = {0, 0, 255};
- unsigned char* color;
-
- //red blue chessboard 16 pxls size
- if(((j >> 4) & 1) == ((i >> 4) & 1)) {
- color = color0;
- }
- else {
- color = color1;
- }
-
- *fb++ = color[0];
- *fb++ = color[1];
- *fb++ = color[2];
- fb++;
- }
+ while(1) {
+ process_events();
}
- getchar();
- clear_screen(0, 0, 0);
+ winnie_shutdown();
+}
+static void display(Window *win)
+{
+ fill_rect(win->get_rect(), 0, 0, 0);
+}
+
+static void keyboard(Window *win, int key, bool pressed)
+{
+ switch(key) {
+ case 'q':
+ exit(0);
+ }
+}
+
+static void cleanup()
+{
destroy_gfx();
}
void Window::draw()
{
+ //TODO
+ //titlebar, frame
callbacks.display(this);
dirty = false;
}
{
return get_screen_size().x;
}
+
+void Window::set_display_callback(DisplayFuncType func)
+{
+ callbacks.display = func;
+}
+
+void Window::set_keyboard_callback(KeyboardFuncType func)
+{
+ callbacks.keyboard = func;
+}
+
+void Window::set_mouse_button_callback(MouseButtonFuncType func)
+{
+ callbacks.button = func;
+}
+
+void Window::set_mouse_motion_callback(MouseMotionFuncType func)
+{
+ callbacks.motion = func;
+}
--- /dev/null
+#include "winnie.h"
+
+bool winnie_init()
+{
+ if(!init_gfx()) {
+ return false;
+ }
+
+ wm->invalidate_region(get_screen_size());
+ return true;
+}
+
+void winnie_shutdown()
+{
+ destroy_gfx();
+}
--- /dev/null
+#ifndef WINNIE_H_
+#define WINNIE_H_
+
+#include "event.h"
+#include "geom.h"
+#include "gfx.h"
+#include "window.h"
+#include "wm.h"
+
+bool winnie_init();
+void winnie_shutdown();
+
+#endif
}
}
}
+
+void WindowManager::add_window(Window *win)
+{
+ windows.push_back(win);
+}
void invalidate_region(const Rect &rect);
void process_windows();
+
+ void add_window(Window *win);
};
extern WindowManager *wm;