#include #include #include "font.h" #include "widgets.h" #include "engine.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "gettext.h" mogltk::widget * mogltk::widget::focused = 0; mogltk::widget::widget(widget * _father, int _x, int _y, int _sx, int _sy, int _type, String _name, mogltk::shape * _sh) : x(_x), y(_y), sx(_sx), sy(_sy), father(_father), type(_type), name(_name), sh(_sh) { if (!father) { root = this; father = this; next = 0; x = 0; y = 0; sx = engine::base_o->GetWidth(); sy = engine::base_o->GetHeight(); } else { next = father->child; if (next) next->prev = this; father->child = this; root = father->root; } prev = 0; child = 0; computeabs(); } mogltk::widget::~widget() { while(child) delete child; if (prev) prev->next = next; else father->child = next; if (next) next->prev = prev; } void mogltk::widget::computeabs() { if (father != this) { ax = father->ax + x; ay = father->ay + y; } else { ax = x; ay = y; } ax2 = ax + sx; ay2 = ay + sy; } void mogltk::widget::move(int nx, int ny) { x = nx; y = ny; computeabs(); } void mogltk::widget::resize(int nsx, int nsy) { sx = nsx; sy = nsy; ax2 = ax + sx; ay2 = ay + sy; } int mogltk::widget::GetX() { return x; } int mogltk::widget::GetY() { return y; } int mogltk::widget::GetH() { return sx; } int mogltk::widget::GetW() { return sy; } int mogltk::widget::GetAX() { return ax; } int mogltk::widget::GetAY() { return ay; } int mogltk::widget::GetAX2() { return ax2; } int mogltk::widget::GetAY2() { return ay2; } mogltk::shape * mogltk::widget::Shaper() { return sh; } void mogltk::widget::fulldraw() { bool was2D = true; if (mogltk::engine::glbase_o) if (!(was2D = mogltk::engine::glbase_o->is2D())) mogltk::engine::glbase_o->Enter2DMode(); texture::Unbind(); mogltk::ColorP::Max = WHITE; mogltk::ColorP::Min = BLACK; mogltk::ColorP::Min.A = 0; root->idraw(); if (!was2D) mogltk::engine::glbase_o->Leave2DMode(); } void mogltk::widget::idraw() { int x1, y1, x2, y2; if (next) next->idraw(); x1 = MAX(GetAX(), father->GetAX()); y1 = MAX(GetAY(), father->GetAY()); x2 = MIN(GetAX2(), father->GetAX2()); y2 = MIN(GetAY2(), father->GetAY2()); engine::base_o->changeviewport(x1, y1, x2 - x1, y2 - y1); draw(); if (child) child->idraw(); } /* * Predefined widgets. */ /* Here is Root */ mogltk::Root::Root(mogltk::shape * sh, mogltk::drawer * _dr) : widget(0, 0, 0, 0, 0, 0, "Root", sh), dr(_dr) { if (engine::root) delete engine::root; engine::root = this; } void mogltk::Root::draw() { if (dr) dr->draw(this); else Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2()); } void mogltk::Root::setdrawer(drawer * _dr) { dr = _dr; }