summaryrefslogtreecommitdiff
path: root/libwinnie/src/window.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libwinnie/src/window.cc')
-rw-r--r--libwinnie/src/window.cc303
1 files changed, 170 insertions, 133 deletions
diff --git a/libwinnie/src/window.cc b/libwinnie/src/window.cc
index 22e4069..e398841 100644
--- a/libwinnie/src/window.cc
+++ b/libwinnie/src/window.cc
@@ -20,7 +20,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
#include <algorithm>
-#include <stdio.h> //TODO
+#include <stdio.h>
#include <string.h>
#include "sdl/gfx.h"
@@ -29,253 +29,290 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
Window::Window()
{
- parent = 0;
- title = 0;
- rect.x = rect.y = 0;
- rect.width = rect.height = 128;
- memset(&callbacks, 0, sizeof callbacks);
- dirty = true;
- managed = true;
- focusable = true;
- state = STATE_NORMAL;
+ parent = 0;
+ title = 0;
+ rect.x = rect.y = 0;
+ rect.width = rect.height = 128;
+ memset(&callbacks, 0, sizeof callbacks);
+ dirty = true;
+ managed = true;
+ focusable = true;
+ state = STATE_NORMAL;
}
Window::~Window()
{
- for(size_t i=0; i<children.size(); i++) {
- wm->remove_window(children[i]);
- delete children[i];
- }
+ for (size_t i = 0; i < children.size(); i++) {
+ wm->remove_window(children[i]);
+ delete children[i];
+ }
- delete [] title;
+ delete[] title;
}
-const Rect &Window::get_rect() const
+const Rect &
+Window::get_rect() const
{
- return rect;
+ return rect;
}
-Rect Window::get_absolute_rect() const
+Rect
+Window::get_absolute_rect() const
{
- if(!parent) {
- return rect;
- }
+ if (!parent) {
+ return rect;
+ }
- Rect absolute_rect;
- absolute_rect = parent->get_absolute_rect();
+ Rect absolute_rect;
+ absolute_rect = parent->get_absolute_rect();
- absolute_rect.x += rect.x;
- absolute_rect.y += rect.y;
- absolute_rect.width = rect.width;
- absolute_rect.height = rect.height;
+ absolute_rect.x += rect.x;
+ absolute_rect.y += rect.y;
+ absolute_rect.width = rect.width;
+ absolute_rect.height = rect.height;
- return absolute_rect;
+ return absolute_rect;
}
-bool Window::contains_point(int ptr_x, int ptr_y)
+bool
+Window::contains_point(int ptr_x, int ptr_y)
{
- Rect abs_rect = get_absolute_rect();
- return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width &&
- ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
+ Rect abs_rect = get_absolute_rect();
+ return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width
+ && ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
}
-void Window::move(int x, int y)
+void
+Window::move(int x, int y)
{
- invalidate(); // moved, should redraw, MUST BE CALLED FIRST
- rect.x = x;
- rect.y = y;
+ invalidate(); // moved, should redraw, MUST BE CALLED FIRST
+ rect.x = x;
+ rect.y = y;
}
-void Window::resize(int x, int y)
+void
+Window::resize(int x, int y)
{
- invalidate(); // resized, should redraw, MUST BE CALLED FIRST
- rect.width = x;
- rect.height = y;
+ invalidate(); // resized, should redraw, MUST BE CALLED FIRST
+ rect.width = x;
+ rect.height = y;
}
-void Window::set_title(const char *s)
+void
+Window::set_title(const char *s)
{
- delete [] title;
+ delete[] title;
- title = new char[strlen(s) + 1];
- strcpy(title, s);
+ title = new char[strlen(s) + 1];
+ strcpy(title, s);
}
-const char *Window::get_title() const
+const char *
+Window::get_title() const
{
- return title;
+ return title;
}
-void Window::invalidate()
+void
+Window::invalidate()
{
- dirty = true;
- Rect abs_rect = get_absolute_rect();
- wm->invalidate_region(abs_rect);
+ dirty = true;
+ Rect abs_rect = get_absolute_rect();
+ wm->invalidate_region(abs_rect);
}
-void Window::draw(Rect *dirty_region)
+void
+Window::draw(Rect *dirty_region)
{
- Rect abs_rect = get_absolute_rect();
- Rect intersect = rect_intersection(abs_rect, *dirty_region);
- if(intersect.width && intersect.height) {
- Rect prev_clip = get_clipping_rect();
- set_clipping_rect(abs_rect);
+ Rect abs_rect = get_absolute_rect();
+ Rect intersect = rect_intersection(abs_rect, *dirty_region);
+ if (intersect.width && intersect.height) {
+ Rect prev_clip = get_clipping_rect();
+ set_clipping_rect(abs_rect);
- if(callbacks.display) {
- callbacks.display(this);
- }
- dirty = false;
+ if (callbacks.display) {
+ callbacks.display(this);
+ }
+ dirty = false;
- draw_children(abs_rect);
+ draw_children(abs_rect);
- *dirty_region = rect_union(*dirty_region, abs_rect);
- set_clipping_rect(prev_clip);
- }
+ *dirty_region = rect_union(*dirty_region, abs_rect);
+ set_clipping_rect(prev_clip);
+ }
}
-void Window::draw_children(const Rect &dirty_region)
+void
+Window::draw_children(const Rect &dirty_region)
{
- Rect drect = dirty_region;
- for(size_t i=0; i<children.size(); i++) {
- children[i]->draw(&drect);
- }
+ Rect drect = dirty_region;
+ for (size_t i = 0; i < children.size(); i++) {
+ children[i]->draw(&drect);
+ }
}
-unsigned char *Window::get_win_start_on_fb()
+unsigned char *
+Window::get_win_start_on_fb()
{
- unsigned char *fb = get_framebuffer();
- Rect abs_rect = get_absolute_rect();
- return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
+ unsigned char *fb = get_framebuffer();
+ Rect abs_rect = get_absolute_rect();
+ return fb
+ + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x)
+ / 8;
}
-int Window::get_scanline_width()
+int
+Window::get_scanline_width()
{
- return get_screen_size().x;
+ return get_screen_size().x;
}
-void Window::set_managed(bool managed)
+void
+Window::set_managed(bool managed)
{
- this->managed = managed;
+ this->managed = managed;
}
-bool Window::get_managed() const
+bool
+Window::get_managed() const
{
- return managed;
+ return managed;
}
-void Window::set_focusable(bool focusable)
+void
+Window::set_focusable(bool focusable)
{
- this->focusable = focusable;
+ this->focusable = focusable;
}
-bool Window::get_focusable() const
+bool
+Window::get_focusable() const
{
- return focusable;
+ return focusable;
}
-bool Window::get_dirty() const
+bool
+Window::get_dirty() const
{
- return dirty;
+ return dirty;
}
-void Window::set_display_callback(DisplayFuncType func)
+void
+Window::set_display_callback(DisplayFuncType func)
{
- callbacks.display = func;
+ callbacks.display = func;
}
-void Window::set_keyboard_callback(KeyboardFuncType func)
+void
+Window::set_keyboard_callback(KeyboardFuncType func)
{
- callbacks.keyboard = func;
+ callbacks.keyboard = func;
}
-void Window::set_mouse_button_callback(MouseButtonFuncType func)
+void
+Window::set_mouse_button_callback(MouseButtonFuncType func)
{
- callbacks.button = func;
+ callbacks.button = func;
}
-void Window::set_mouse_motion_callback(MouseMotionFuncType func)
+void
+Window::set_mouse_motion_callback(MouseMotionFuncType func)
{
- callbacks.motion = func;
+ callbacks.motion = func;
}
-void Window::set_timer_callback(TimerFuncType func)
+void
+Window::set_timer_callback(TimerFuncType func)
{
- callbacks.timer = func;
+ callbacks.timer = func;
}
-const DisplayFuncType Window::get_display_callback() const
+const DisplayFuncType
+Window::get_display_callback() const
{
- return callbacks.display;
+ return callbacks.display;
}
-const KeyboardFuncType Window::get_keyboard_callback() const
+const KeyboardFuncType
+Window::get_keyboard_callback() const
{
- return callbacks.keyboard;
+ return callbacks.keyboard;
}
-const MouseButtonFuncType Window::get_mouse_button_callback() const
+const MouseButtonFuncType
+Window::get_mouse_button_callback() const
{
- return callbacks.button;
+ return callbacks.button;
}
-const MouseMotionFuncType Window::get_mouse_motion_callback() const
+const MouseMotionFuncType
+Window::get_mouse_motion_callback() const
{
- return callbacks.motion;
+ return callbacks.motion;
}
-const TimerFuncType Window::get_timer_callback() const
+const TimerFuncType
+Window::get_timer_callback() const
{
- return callbacks.timer;
+ return callbacks.timer;
}
-void Window::add_child(Window *win)
+void
+Window::add_child(Window *win)
{
- children.push_back(win);
- if(win->parent) {
- win->parent->remove_child(win);
- }
- win->parent = this;
+ children.push_back(win);
+ if (win->parent) {
+ win->parent->remove_child(win);
+ }
+ win->parent = this;
}
-void Window::remove_child(Window *win)
+void
+Window::remove_child(Window *win)
{
- std::vector<Window*>::iterator it;
- it = std::find(children.begin(), children.end(), win);
- if(it != children.end()) {
- children.erase(it);
- win->parent = 0;
- }
+ std::vector<Window *>::iterator it;
+ it = std::find(children.begin(), children.end(), win);
+ if (it != children.end()) {
+ children.erase(it);
+ win->parent = 0;
+ }
}
-Window **Window::get_children()
+Window **
+Window::get_children()
{
- if(children.empty()) {
- return 0;
- }
- return &children[0];
+ if (children.empty()) {
+ return 0;
+ }
+ return &children[0];
}
-int Window::get_children_count() const
+int
+Window::get_children_count() const
{
- return (int)children.size();
+ return (int) children.size();
}
-const Window *Window::get_parent() const
+const Window *
+Window::get_parent() const
{
- return parent;
+ return parent;
}
-Window *Window::get_parent()
+Window *
+Window::get_parent()
{
- return parent;
+ return parent;
}
-void Window::set_state(State state)
+void
+Window::set_state(State state)
{
- this->state = state;
+ this->state = state;
}
-Window::State Window::get_state() const
+Window::State
+Window::get_state() const
{
- return state;
+ return state;
}