2 winnie - an experimental window system
4 Copyright (C) 2013 Eleni Maria Stea
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Author: Eleni Maria Stea <elene.mst@gmail.com>
23 #include <stdio.h> //TODO
35 rect.width = rect.height = 128;
36 memset(&callbacks, 0, sizeof callbacks);
45 for(size_t i=0; i<children.size(); i++) {
46 wm->remove_window(children[i]);
53 const Rect &Window::get_rect() const
58 Rect Window::get_absolute_rect() const
65 absolute_rect = parent->get_absolute_rect();
67 absolute_rect.x += rect.x;
68 absolute_rect.y += rect.y;
69 absolute_rect.width = rect.width;
70 absolute_rect.height = rect.height;
75 bool Window::contains_point(int ptr_x, int ptr_y)
77 Rect abs_rect = get_absolute_rect();
78 return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width &&
79 ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
82 void Window::move(int x, int y)
84 invalidate(); // moved, should redraw, MUST BE CALLED FIRST
89 void Window::resize(int x, int y)
91 invalidate(); // resized, should redraw, MUST BE CALLED FIRST
96 void Window::set_title(const char *s)
100 title = new char[strlen(s) + 1];
104 const char *Window::get_title() const
109 void Window::invalidate()
112 Rect abs_rect = get_absolute_rect();
113 wm->invalidate_region(abs_rect);
116 void Window::draw(Rect *dirty_region)
118 Rect abs_rect = get_absolute_rect();
119 Rect intersect = rect_intersection(abs_rect, *dirty_region);
120 if(intersect.width && intersect.height) {
121 Rect prev_clip = get_clipping_rect();
122 set_clipping_rect(abs_rect);
124 if(callbacks.display) {
125 callbacks.display(this);
129 draw_children(abs_rect);
131 *dirty_region = rect_union(*dirty_region, abs_rect);
132 set_clipping_rect(prev_clip);
136 void Window::draw_children(const Rect &dirty_region)
138 Rect drect = dirty_region;
139 for(size_t i=0; i<children.size(); i++) {
140 children[i]->draw(&drect);
144 unsigned char *Window::get_win_start_on_fb()
146 unsigned char *fb = get_framebuffer();
147 Rect abs_rect = get_absolute_rect();
148 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
151 int Window::get_scanline_width()
153 return get_screen_size().x;
156 void Window::set_managed(bool managed)
158 this->managed = managed;
161 bool Window::get_managed() const
166 void Window::set_focusable(bool focusable)
168 this->focusable = focusable;
171 bool Window::get_focusable() const
176 bool Window::get_dirty() const
181 void Window::set_display_callback(DisplayFuncType func)
183 callbacks.display = func;
186 void Window::set_keyboard_callback(KeyboardFuncType func)
188 callbacks.keyboard = func;
191 void Window::set_mouse_button_callback(MouseButtonFuncType func)
193 callbacks.button = func;
196 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
198 callbacks.motion = func;
201 const DisplayFuncType Window::get_display_callback() const
203 return callbacks.display;
206 const KeyboardFuncType Window::get_keyboard_callback() const
208 return callbacks.keyboard;
211 const MouseButtonFuncType Window::get_mouse_button_callback() const
213 return callbacks.button;
216 const MouseMotionFuncType Window::get_mouse_motion_callback() const
218 return callbacks.motion;
221 void Window::add_child(Window *win)
223 children.push_back(win);
225 win->parent->remove_child(win);
230 void Window::remove_child(Window *win)
232 std::vector<Window*>::iterator it;
233 it = std::find(children.begin(), children.end(), win);
234 if(it != children.end()) {
240 Window **Window::get_children()
242 if(children.empty()) {
248 int Window::get_children_count() const
250 return (int)children.size();
253 const Window *Window::get_parent() const
258 Window *Window::get_parent()
263 void Window::set_state(State state)
268 Window::State Window::get_state() const