Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SimpleGUI by
Widgets/TextWidget.cpp@7:303850a4b30c, 2016-04-10 (annotated)
- Committer:
- duncanFrance
- Date:
- Sun Apr 10 16:48:44 2016 +0000
- Revision:
- 7:303850a4b30c
- Parent:
- 4:27546fb8b670
- Child:
- 8:a460cabc85ac
Working implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
duncanFrance | 0:0a590815d51c | 1 | #include "TextWidget.h" |
duncanFrance | 0:0a590815d51c | 2 | |
duncanFrance | 0:0a590815d51c | 3 | /** |
duncanFrance | 0:0a590815d51c | 4 | * A basic widget implementation which just draws some text. |
duncanFrance | 0:0a590815d51c | 5 | * If the text does not fit in the bounding-box it will be clipped |
duncanFrance | 0:0a590815d51c | 6 | **/ |
duncanFrance | 7:303850a4b30c | 7 | TextWidget::TextWidget(GraphicsDisplay& display, FontRenderer* renderer) : |
duncanFrance | 7:303850a4b30c | 8 | Widget(display), |
duncanFrance | 7:303850a4b30c | 9 | _renderer(renderer) |
duncanFrance | 7:303850a4b30c | 10 | { |
duncanFrance | 7:303850a4b30c | 11 | } |
duncanFrance | 0:0a590815d51c | 12 | |
duncanFrance | 1:48796b602c86 | 13 | void TextWidget::setText(char* text) |
duncanFrance | 1:48796b602c86 | 14 | { |
duncanFrance | 0:0a590815d51c | 15 | _text = text; |
duncanFrance | 0:0a590815d51c | 16 | } |
duncanFrance | 0:0a590815d51c | 17 | |
duncanFrance | 2:bb9183379488 | 18 | void TextWidget::setFont(Font* font) |
duncanFrance | 1:48796b602c86 | 19 | { |
duncanFrance | 2:bb9183379488 | 20 | _font = font; |
duncanFrance | 0:0a590815d51c | 21 | } |
duncanFrance | 0:0a590815d51c | 22 | |
duncanFrance | 3:cb004f59b715 | 23 | |
duncanFrance | 3:cb004f59b715 | 24 | void TextWidget::draw() |
duncanFrance | 3:cb004f59b715 | 25 | { |
duncanFrance | 7:303850a4b30c | 26 | _renderer->window(_x, _y, _width, _height, false); |
duncanFrance | 7:303850a4b30c | 27 | _renderer->setForeground(_fg); |
duncanFrance | 7:303850a4b30c | 28 | _renderer->setBackground(_bg); |
duncanFrance | 7:303850a4b30c | 29 | _renderer->setFont(_font); |
duncanFrance | 3:cb004f59b715 | 30 | |
duncanFrance | 3:cb004f59b715 | 31 | char c; |
duncanFrance | 3:cb004f59b715 | 32 | char *p = _text; |
duncanFrance | 3:cb004f59b715 | 33 | |
duncanFrance | 3:cb004f59b715 | 34 | while(*p != NULL) { |
duncanFrance | 3:cb004f59b715 | 35 | c = *p; |
duncanFrance | 3:cb004f59b715 | 36 | p++; |
duncanFrance | 7:303850a4b30c | 37 | _renderer->putc(c, _display); |
duncanFrance | 3:cb004f59b715 | 38 | } |
duncanFrance | 7:303850a4b30c | 39 | |
duncanFrance | 7:303850a4b30c | 40 | _display.copy_to_lcd(); |
duncanFrance | 3:cb004f59b715 | 41 | } |