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.
Dependencies: mbed
Fork of el17ajf by
Menus/UI/UI.cpp@17:cc448ab7266f, 2019-04-03 (annotated)
- Committer:
- el17ajf
- Date:
- Wed Apr 03 13:37:56 2019 +0000
- Revision:
- 17:cc448ab7266f
- Parent:
- 16:3f84f2d7b910
- Child:
- 18:24ce897024d0
Added UI and graphics separation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17ajf | 17:cc448ab7266f | 1 | #include "UI.h" |
el17ajf | 17:cc448ab7266f | 2 | #include "Graphics.h" |
el17ajf | 17:cc448ab7266f | 3 | |
el17ajf | 17:cc448ab7266f | 4 | UI::UI() { |
el17ajf | 17:cc448ab7266f | 5 | reset(); |
el17ajf | 17:cc448ab7266f | 6 | } |
el17ajf | 17:cc448ab7266f | 7 | |
el17ajf | 17:cc448ab7266f | 8 | void UI::reset() { |
el17ajf | 17:cc448ab7266f | 9 | buttonCurrentlySelected = 0; |
el17ajf | 17:cc448ab7266f | 10 | } |
el17ajf | 17:cc448ab7266f | 11 | |
el17ajf | 17:cc448ab7266f | 12 | UI::~UI() { |
el17ajf | 16:3f84f2d7b910 | 13 | |
el17ajf | 17:cc448ab7266f | 14 | } |
el17ajf | 17:cc448ab7266f | 15 | |
el17ajf | 17:cc448ab7266f | 16 | void UI::clear() { |
el17ajf | 17:cc448ab7266f | 17 | buttonPressedFrame = false; |
el17ajf | 17:cc448ab7266f | 18 | nextYPos = PADDING_Y; |
el17ajf | 17:cc448ab7266f | 19 | buttonCurrentlyDrawing = -1; |
el17ajf | 17:cc448ab7266f | 20 | } |
el17ajf | 17:cc448ab7266f | 21 | |
el17ajf | 17:cc448ab7266f | 22 | void UI::drawTitle(const char * text) { |
el17ajf | 17:cc448ab7266f | 23 | drawLabel(text); |
el17ajf | 17:cc448ab7266f | 24 | } |
el17ajf | 17:cc448ab7266f | 25 | |
el17ajf | 17:cc448ab7266f | 26 | void UI::drawLabel(const char * text) { |
el17ajf | 17:cc448ab7266f | 27 | Graphics::UI::drawText(PADDING_X, nextY(), text); |
el17ajf | 17:cc448ab7266f | 28 | } |
el17ajf | 17:cc448ab7266f | 29 | |
el17ajf | 17:cc448ab7266f | 30 | void UI::newLine() { |
el17ajf | 17:cc448ab7266f | 31 | nextY(); |
el17ajf | 17:cc448ab7266f | 32 | } |
el17ajf | 16:3f84f2d7b910 | 33 | |
el17ajf | 17:cc448ab7266f | 34 | bool UI::drawAndCheckButton(const char * text) { |
el17ajf | 17:cc448ab7266f | 35 | buttonCurrentlyDrawing++; |
el17ajf | 17:cc448ab7266f | 36 | |
el17ajf | 17:cc448ab7266f | 37 | int y = nextY(); |
el17ajf | 17:cc448ab7266f | 38 | |
el17ajf | 17:cc448ab7266f | 39 | Graphics::UI::drawText(PADDING_X, y, text); |
el17ajf | 17:cc448ab7266f | 40 | |
el17ajf | 17:cc448ab7266f | 41 | bool selected = buttonCurrentlyDrawing == buttonCurrentlySelected; |
el17ajf | 17:cc448ab7266f | 42 | |
el17ajf | 17:cc448ab7266f | 43 | if (selected) { |
el17ajf | 17:cc448ab7266f | 44 | Graphics::UI::drawBorder(PADDING_X - 2, y - 2, PADDING_X + 50, y + Graphics::UI::CHAR_HEIGHT + 2); |
el17ajf | 17:cc448ab7266f | 45 | } |
el17ajf | 17:cc448ab7266f | 46 | |
el17ajf | 17:cc448ab7266f | 47 | return buttonPressedFrame && selected; |
el17ajf | 17:cc448ab7266f | 48 | } |
el17ajf | 17:cc448ab7266f | 49 | |
el17ajf | 17:cc448ab7266f | 50 | void UI::selectNextButton() { |
el17ajf | 17:cc448ab7266f | 51 | if (buttonCurrentlySelected < buttonCurrentlyDrawing) { |
el17ajf | 17:cc448ab7266f | 52 | buttonCurrentlySelected++; |
el17ajf | 17:cc448ab7266f | 53 | } |
el17ajf | 17:cc448ab7266f | 54 | } |
el17ajf | 17:cc448ab7266f | 55 | |
el17ajf | 17:cc448ab7266f | 56 | void UI::selectPreviousButton() { |
el17ajf | 17:cc448ab7266f | 57 | if (buttonCurrentlySelected > 0) { |
el17ajf | 17:cc448ab7266f | 58 | buttonCurrentlySelected--; |
el17ajf | 17:cc448ab7266f | 59 | } |
el17ajf | 17:cc448ab7266f | 60 | } |
el17ajf | 17:cc448ab7266f | 61 | |
el17ajf | 17:cc448ab7266f | 62 | void UI::pressButton() { |
el17ajf | 17:cc448ab7266f | 63 | buttonPressedFrame = true; |
el17ajf | 17:cc448ab7266f | 64 | } |
el17ajf | 17:cc448ab7266f | 65 | |
el17ajf | 17:cc448ab7266f | 66 | int UI::nextY() { |
el17ajf | 17:cc448ab7266f | 67 | int currentYPos = nextYPos; |
el17ajf | 17:cc448ab7266f | 68 | nextYPos += Graphics::UI::CHAR_HEIGHT + LINE_PADDING; |
el17ajf | 17:cc448ab7266f | 69 | return currentYPos; |
el17ajf | 17:cc448ab7266f | 70 | } |