*work in progress*
[winnie] / src / window.cc
1 #include <string.h>
2 #include "gfx.h"
3 #include "window.h"
4 #include "wm.h"
5
6 Window::Window()
7 {
8         title = 0;
9         rect.x = rect.y = 0;
10         rect.width = rect.height = 128;
11         memset(&callbacks, 0, sizeof callbacks);
12         dirty = true;
13 }
14
15 Window::~Window()
16 {
17         delete [] title;
18 }
19
20 const Rect &Window::get_rect() const
21 {
22         return rect;
23 }
24
25 void Window::move(int x, int y)
26 {
27         invalidate();   // moved, should redraw, MUST BE CALLED FIRST
28         rect.x = x;
29         rect.y = y;
30 }
31
32 void Window::resize(int x, int y)
33 {
34         invalidate();   // resized, should redraw, MUST BE CALLED FIRST
35         rect.width = x;
36         rect.height = y;
37 }
38
39 void Window::set_title(const char *s)
40 {
41         delete [] title;
42
43         title = new char[strlen(s) + 1];
44         strcpy(title, s);
45 }
46
47 const char *Window::get_title() const
48 {
49         return title;
50 }
51
52 void Window::invalidate()
53 {
54         dirty = true;
55         wm->invalidate_region(rect);
56 }
57
58 void Window::draw()
59 {
60         //TODO
61         //titlebar, frame
62         callbacks.display(this);
63         dirty = false;
64 }
65
66 unsigned char *Window::get_win_start_on_fb()
67 {
68         unsigned char *fb = get_framebuffer();
69         return fb + get_color_depth() * (get_screen_size().x * rect.y + rect.x) / 8;
70 }
71
72 int Window::get_scanline_width()
73 {
74         return get_screen_size().x;
75 }
76
77 void Window::set_display_callback(DisplayFuncType func)
78 {
79         callbacks.display = func;
80 }
81
82 void Window::set_keyboard_callback(KeyboardFuncType func)
83 {
84         callbacks.keyboard = func;
85 }
86
87 void Window::set_mouse_button_callback(MouseButtonFuncType func)
88 {
89         callbacks.button = func;
90 }
91
92 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
93 {
94         callbacks.motion = func;
95 }