Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Diff: Widgets/TextWidget.cpp
- Revision:
- 12:63db16fea709
- Parent:
- 11:b485561aa112
- Child:
- 13:6714534e7974
--- a/Widgets/TextWidget.cpp Fri Apr 22 16:12:42 2016 +0000 +++ b/Widgets/TextWidget.cpp Sun May 08 14:42:08 2016 +0000 @@ -4,49 +4,49 @@ * A basic widget implementation which just draws some text. * If the text does not fit in the bounding-box it will be clipped **/ -TextWidget::TextWidget(GUI* gui) : - Widget(gui), - _renderer(gui->fontRenderer()), - _font(gui->defaultFont()) +TextWidget::TextWidget(GraphicsContext *context) : + Widget(context), + _renderer(context->fontRenderer()), + _font(context->defaultFont()) { } -TextWidget::TextWidget(GUI* gui, FontRenderer* renderer) : - Widget(gui), +TextWidget::TextWidget(GraphicsContext *context, FontRenderer* renderer) : + Widget(context), _renderer(renderer), - _font(gui->defaultFont()) + _font(context->defaultFont()) { } -TextWidget::TextWidget(GUI* gui, FontRenderer* renderer, Font* font) : - Widget(gui), +TextWidget::TextWidget(GraphicsContext *context, FontRenderer* renderer, Font* font) : + Widget(context), _renderer(renderer), _font(font) { } -void TextWidget::setText(string text) +void TextWidget::setText(char* text) { _text = text; + dirty(); } void TextWidget::setFont(Font* font) { _font = font; + dirty(); } void TextWidget::_draw() { - _renderer->window(_x, _y, _width, _height, false); + Widget::_draw(); + + _renderer->window(_inner.x, _inner.y, _inner.width, _inner.height, false); _renderer->setForeground(_fg); _renderer->setBackground(_bg); - _gui->display()->fillrect(_x, _y, _x+_width, _y+_height, _bg); + display()->fillrect(_inner.x, _inner.y, _inner.x+_inner.width, _inner.y+_inner.height, _bg); - _renderer->puts(_text.c_str(), _gui->display(), _font); - _gui->display()->copy_to_lcd(); -} - -void TextWidget::_clear() { - _gui->display()->fillrect(_x, _y, _x+_width, _y+_height, _bg); + _renderer->puts(_text, display(), _font); + display()->copy_to_lcd(); } \ No newline at end of file