f87b011559856e035e5d1af181e7be5bc0c57eeb
[winnie] / src / main.cc
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "winnie.h"
5
6 static void display(Window *win);
7 static void keyboard(Window *win, int key, bool pressed);
8 static void button(Window *win, int bn, bool pressed, int x, int y);
9 static void motion(Window *win, int x, int y);
10 static void cleanup();
11
12 int main()
13 {
14         winnie_init();
15         atexit(cleanup);
16
17         Window *win1 = new Window;
18         win1->set_title("title1");
19         win1->move(5, 10);
20         win1->resize(200, 300);
21         win1->set_display_callback(display);
22         win1->set_keyboard_callback(keyboard);
23         win1->set_mouse_button_callback(button);
24         win1->set_mouse_motion_callback(motion);
25
26         wm->add_window(win1);
27
28         while(1) {
29                 process_events();
30         }
31 }
32
33 static void display(Window *win)
34 {
35         if(wm->get_focused_window() != win) {
36                 fill_rect(win->get_absolute_rect(), 106, 106, 250);
37         }
38         else {
39                 fill_rect(win->get_absolute_rect(), 0, 0, 255);
40         }
41 }
42
43 static void keyboard(Window *win, int key, bool pressed)
44 {
45         switch(key) {
46         case 'q':
47                 exit(0);
48         }
49 }
50
51 static void button(Window *win, int bn, bool pressed, int x, int y)
52 {
53         printf("WINDOW(%p) button %d %s\n", (void*)win, bn, pressed ? "press" : "release");
54 }
55
56 static void motion(Window *win, int x, int y)
57 {
58         printf("WINDOW(%p) motion %d %d\n", (void*)win, x, y);
59 }
60
61 static void cleanup()
62 {
63         winnie_shutdown();
64 }