76c51773ac66fd900a0db1cbe013283ef0bd1320
[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         callbacks.display(this);
61         dirty = false;
62 }
63
64 unsigned char *Window::get_win_start_on_fb()
65 {
66         unsigned char *fb = get_framebuffer();
67         return fb + get_color_depth() * (get_screen_size().x * rect.y + rect.x) / 8;
68 }
69
70 int Window::get_scanline_width()
71 {
72         return get_screen_size().x;
73 }