*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 bool Window::contains_point(int ptr_x, int ptr_y)
26 {
27         if((rect.x <= ptr_x) && ((rect.x + rect.width) >= ptr_x)) {
28                 if((rect.y <= ptr_y) && (ptr_y <= (rect.y + rect.height))) {
29                         return true;
30                 }
31         }
32
33         return false;
34 }
35
36 void Window::move(int x, int y)
37 {
38         invalidate();   // moved, should redraw, MUST BE CALLED FIRST
39         rect.x = x;
40         rect.y = y;
41 }
42
43 void Window::resize(int x, int y)
44 {
45         invalidate();   // resized, should redraw, MUST BE CALLED FIRST
46         rect.width = x;
47         rect.height = y;
48 }
49
50 void Window::set_title(const char *s)
51 {
52         delete [] title;
53
54         title = new char[strlen(s) + 1];
55         strcpy(title, s);
56 }
57
58 const char *Window::get_title() const
59 {
60         return title;
61 }
62
63 void Window::invalidate()
64 {
65         dirty = true;
66         wm->invalidate_region(rect);
67 }
68
69 void Window::draw()
70 {
71         //TODO
72         //titlebar, frame
73         callbacks.display(this);
74         dirty = false;
75 }
76
77 unsigned char *Window::get_win_start_on_fb()
78 {
79         unsigned char *fb = get_framebuffer();
80         return fb + get_color_depth() * (get_screen_size().x * rect.y + rect.x) / 8;
81 }
82
83 int Window::get_scanline_width()
84 {
85         return get_screen_size().x;
86 }
87
88 void Window::set_display_callback(DisplayFuncType func)
89 {
90         callbacks.display = func;
91 }
92
93 void Window::set_keyboard_callback(KeyboardFuncType func)
94 {
95         callbacks.keyboard = func;
96 }
97
98 void Window::set_mouse_button_callback(MouseButtonFuncType func)
99 {
100         callbacks.button = func;
101 }
102
103 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
104 {
105         callbacks.motion = func;
106 }
107
108 const DisplayFuncType Window::get_display_callback() const
109 {
110         return callbacks.display;
111 }
112
113 const KeyboardFuncType Window::get_keyboard_callback() const
114 {
115         return callbacks.keyboard;
116 }
117
118 const MouseButtonFuncType Window::get_mouse_button_callback() const
119 {
120         return callbacks.button;
121 }
122
123 const MouseMotionFuncType Window::get_mouse_motion_callback() const
124 {
125         return callbacks.motion;
126 }