#include "Widget.h" #include "CursorTask.h" Widget::Widget( ) { } Widget::Widget( char *l, int x, int y, int w, int h, Widget *p ) { label=l; xpos=x; ypos=y; width=w; height=h; parent=p; if (parent) parent->addchild( this ); } Widget::~Widget() { children.clear(); } void Widget::logic( CursorTask *mouse ) { for (auto& c : children ) c->logic( mouse ); } void Widget::focus() { if (parent) { parent->unfocus(); } has_focus = true; } void Widget::unfocus() { has_focus = false; for (auto& c : children ) c->unfocus(); } void Widget::render( SDL_Surface *screen, nSDL_Font *currentfont ) { for (auto& c : children ) c->render( screen, currentfont ); } void Widget::enable( ) { is_enabled = true; for (auto& c : children ) c->enable( ); } void Widget::disable( ) { is_enabled = false; for (auto& c : children ) c->disable( ); } void Widget::setvisible( ) { is_visible = true; for (auto& c : children ) c->setvisible( ); } void Widget::setinvisible( ) { is_visible = false; for (auto& c : children ) c->setinvisible( ); } void Widget::addchild( Widget *child ) { children.push_back( child ); } bool Widget::cursoron( CursorTask *mouse ) { return (mouse->x >= xpos) && (mouse->y >= ypos) && (mouse->x <= xpos+width) && (mouse->y <= ypos+height); }