From da9beb729c58ca2d91f67ab85a6728b628c27cf2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 5 Oct 2008 19:03:25 +0000 Subject: user interface library --- src/ui/window.cc | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/ui/window.cc (limited to 'src/ui/window.cc') diff --git a/src/ui/window.cc b/src/ui/window.cc new file mode 100644 index 0000000..8763b53 --- /dev/null +++ b/src/ui/window.cc @@ -0,0 +1,68 @@ +/* + ui/window.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "ui/window.h" +#include "render/primitives.h" + +namespace ui { + +Window::Window(Window *parent) : Widget(static_cast(parent)) +{ + set_label("window"); + set_border(true); + + if (parent) { + parent->add_window(this); + } +} + +Window::~Window() +{ + if (parent()) { + static_cast(parent())->remove_window(this); + } + window_children.clear(); +} + +void Window::draw_border() +{ + if (!border()) + return; + + if (palette()) + render::gl::color(palette()->foreground()); + math::Vector2f v(to_global(location())); + render::primitives::border(v, size()); +} + +Window::Windows::iterator Window::find_window(Window *window) +{ + Windows::iterator it; + for (it = window_children.begin(); it != window_children.end(); it++) { + if ((*it) == window) + return it; + } + + return it; +} + +void Window::add_window(Window *window) +{ + Windows::iterator it = find_window(window); + if (it == window_children.end()) { + window_children.push_back(window); + } +} + +void Window::remove_window(Window *window) +{ + + Windows::iterator it = find_window(window); + if (it != window_children.end()) { + window_children.erase(it); + } +} +} -- cgit v1.2.3