diff options
Diffstat (limited to 'plugingui/widget.cc')
-rw-r--r-- | plugingui/widget.cc | 77 |
1 files changed, 24 insertions, 53 deletions
diff --git a/plugingui/widget.cc b/plugingui/widget.cc index 05966aa..0919e22 100644 --- a/plugingui/widget.cc +++ b/plugingui/widget.cc @@ -31,7 +31,9 @@ #include <stdio.h> -GUI::Widget::Widget(Widget *parent) +namespace GUI { + +Widget::Widget(Widget *parent) : pixbuf(1, 1) { _width = _height = 10; @@ -45,38 +47,38 @@ GUI::Widget::Widget(Widget *parent) _visible = true; } -GUI::Widget::~Widget() +Widget::~Widget() { if(parent) parent->removeChild(this); } -void GUI::Widget::show() +void Widget::show() { setVisible(true); } -void GUI::Widget::hide() +void Widget::hide() { setVisible(false); } -void GUI::Widget::setVisible(bool v) +void Widget::setVisible(bool v) { _visible = v; repaintEvent(NULL); } -bool GUI::Widget::visible() +bool Widget::visible() { return _visible; } -void GUI::Widget::addChild(GUI::Widget *widget) +void Widget::addChild(Widget *widget) { children.push_back(widget); } -void GUI::Widget::removeChild(GUI::Widget *widget) +void Widget::removeChild(Widget *widget) { std::vector<Widget *>::iterator i = children.begin(); while(i != children.end()) { @@ -88,7 +90,7 @@ void GUI::Widget::removeChild(GUI::Widget *widget) } } -void GUI::Widget::resize(int width, int height) +void Widget::resize(int width, int height) { if(width < 1 || height < 1) return; _width = width; @@ -96,32 +98,32 @@ void GUI::Widget::resize(int width, int height) pixbuf.realloc(width, height); } -void GUI::Widget::move(size_t x, size_t y) +void Widget::move(size_t x, size_t y) { _x = x; _y = y; } -size_t GUI::Widget::x() { return _x; } -size_t GUI::Widget::y() { return _y; } -size_t GUI::Widget::width() { return _width; } -size_t GUI::Widget::height() { return _height; } +size_t Widget::x() { return _x; } +size_t Widget::y() { return _y; } +size_t Widget::width() { return _width; } +size_t Widget::height() { return _height; } -size_t GUI::Widget::windowX() +size_t Widget::windowX() { size_t window_x = x(); if(parent) window_x += parent->windowX(); return window_x; } -size_t GUI::Widget::windowY() +size_t Widget::windowY() { size_t window_y = y(); if(parent) window_y += parent->windowY(); return window_y; } -GUI::Widget *GUI::Widget::find(size_t x, size_t y) +Widget *Widget::find(size_t x, size_t y) { std::vector<Widget*>::reverse_iterator i = children.rbegin(); while(i != children.rend()) { @@ -138,12 +140,12 @@ GUI::Widget *GUI::Widget::find(size_t x, size_t y) return this; } -GUI::Window *GUI::Widget::window() +Window *Widget::window() { return _window; } -void GUI::Widget::repaint_r(GUI::RepaintEvent *e) +void Widget::repaint_r(RepaintEvent *e) { Painter p(this); // make sure pixbuf refcount is incremented. @@ -157,7 +159,7 @@ void GUI::Widget::repaint_r(GUI::RepaintEvent *e) } } -std::vector<GUI::PixelBufferAlpha *> GUI::Widget::getPixelBuffers() +std::vector<PixelBufferAlpha *> Widget::getPixelBuffers() { std::vector<PixelBufferAlpha *> pbs; @@ -179,40 +181,9 @@ std::vector<GUI::PixelBufferAlpha *> GUI::Widget::getPixelBuffers() return pbs; } -bool GUI::Widget::hasKeyboardFocus() +bool Widget::hasKeyboardFocus() { return window()->keyboardFocus() == this; } -#ifdef TEST_WIDGET -//deps: window.cc globalcontext.cc -//cflags: -//libs: -#include "test.h" - -#include "window.h" - -TEST_BEGIN; - -GUI::Window w1(NULL); -w1.move(0,0); -w1.resize(100, 100); - -GUI::Widget w2(&w1); -w2.resize(40,40); -w2.move(10,10); - -GUI::Widget w3(&w2); -w3.resize(20,20); -w3.move(10,10); - -TEST_EQUAL_PTR(w1.find(101,0), NULL, "Miss?"); -TEST_EQUAL_PTR(w1.find(0,0), &w1, "Hit w1?"); -TEST_EQUAL_PTR(w1.find(100,100), &w1, "Hit w1?"); -TEST_EQUAL_PTR(w1.find(0,0), &w1, "Hit w1?"); -TEST_EQUAL_PTR(w1.find(11,11), &w2, "Hit w2?"); -TEST_EQUAL_PTR(w1.find(22,22), &w3, "Hit w3?"); - -TEST_END; - -#endif/*TEST_WIDGET*/ +} // GUI:: |