Arduino style GUI
Controls/ProgressBar.cpp@4:d353b314d244, 2019-02-27 (annotated)
- Committer:
- jonebuckman
- Date:
- Wed Feb 27 22:34:06 2019 +0000
- Revision:
- 4:d353b314d244
- Parent:
- 0:90962b684403
Updated writeCommand and writeData.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jonebuckman | 0:90962b684403 | 1 | /* NeatGUI Library |
jonebuckman | 0:90962b684403 | 2 | * Copyright (c) 2014 Neil Thiessen |
jonebuckman | 0:90962b684403 | 3 | * |
jonebuckman | 0:90962b684403 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jonebuckman | 0:90962b684403 | 5 | * you may not use this file except in compliance with the License. |
jonebuckman | 0:90962b684403 | 6 | * You may obtain a copy of the License at |
jonebuckman | 0:90962b684403 | 7 | * |
jonebuckman | 0:90962b684403 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jonebuckman | 0:90962b684403 | 9 | * |
jonebuckman | 0:90962b684403 | 10 | * Unless required by applicable law or agreed to in writing, software |
jonebuckman | 0:90962b684403 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jonebuckman | 0:90962b684403 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jonebuckman | 0:90962b684403 | 13 | * See the License for the specific language governing permissions and |
jonebuckman | 0:90962b684403 | 14 | * limitations under the License. |
jonebuckman | 0:90962b684403 | 15 | */ |
jonebuckman | 0:90962b684403 | 16 | |
jonebuckman | 0:90962b684403 | 17 | #include "ProgressBar.h" |
jonebuckman | 0:90962b684403 | 18 | |
jonebuckman | 0:90962b684403 | 19 | ProgressBar::ProgressBar(int x, int y, int w, int h, Font *fnt) : Control(x, y, w, h) |
jonebuckman | 0:90962b684403 | 20 | { |
jonebuckman | 0:90962b684403 | 21 | m_Value = 0.0; |
jonebuckman | 0:90962b684403 | 22 | text(NULL); |
jonebuckman | 0:90962b684403 | 23 | font(fnt); |
jonebuckman | 0:90962b684403 | 24 | border(1); |
jonebuckman | 0:90962b684403 | 25 | padding(1); |
jonebuckman | 0:90962b684403 | 26 | foreColor(0xFFFFFFFF); |
jonebuckman | 0:90962b684403 | 27 | backColor(0xFF000000); |
jonebuckman | 0:90962b684403 | 28 | } |
jonebuckman | 0:90962b684403 | 29 | |
jonebuckman | 0:90962b684403 | 30 | float ProgressBar::value() |
jonebuckman | 0:90962b684403 | 31 | { |
jonebuckman | 0:90962b684403 | 32 | //Return the current value |
jonebuckman | 0:90962b684403 | 33 | return m_Value; |
jonebuckman | 0:90962b684403 | 34 | } |
jonebuckman | 0:90962b684403 | 35 | |
jonebuckman | 0:90962b684403 | 36 | void ProgressBar::value(float v) |
jonebuckman | 0:90962b684403 | 37 | { |
jonebuckman | 0:90962b684403 | 38 | //Update the value with range-limiting |
jonebuckman | 0:90962b684403 | 39 | if (v < 0) |
jonebuckman | 0:90962b684403 | 40 | m_Value = 0; |
jonebuckman | 0:90962b684403 | 41 | else if (v > 100) |
jonebuckman | 0:90962b684403 | 42 | m_Value = 100; |
jonebuckman | 0:90962b684403 | 43 | else |
jonebuckman | 0:90962b684403 | 44 | m_Value = v; |
jonebuckman | 0:90962b684403 | 45 | |
jonebuckman | 0:90962b684403 | 46 | //Force a repaint |
jonebuckman | 0:90962b684403 | 47 | invalidate(); |
jonebuckman | 0:90962b684403 | 48 | } |
jonebuckman | 0:90962b684403 | 49 | |
jonebuckman | 0:90962b684403 | 50 | void ProgressBar::paint(Canvas* canvas) |
jonebuckman | 0:90962b684403 | 51 | { |
jonebuckman | 0:90962b684403 | 52 | //Paint the base class |
jonebuckman | 0:90962b684403 | 53 | Control::paint(canvas); |
jonebuckman | 0:90962b684403 | 54 | |
jonebuckman | 0:90962b684403 | 55 | //Draw the progress bar |
jonebuckman | 0:90962b684403 | 56 | canvas->fillRect(contentPosX(), contentPosY(), contentWidth() * m_Value, contentHeight(), foreColor()); |
jonebuckman | 0:90962b684403 | 57 | } |