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