A simple yet powerful library for controlling graphical displays. Multiple display controllers are supported using inheritance.

Dependents:   mbed_rifletool Hexi_Bubble_Game Hexi_Catch-the-dot_Game Hexi_Acceleromagnetic_Synth

NOTE: This library is in beta right now. As far as I know, everything here works, but there are many features that are lacking so far. Most notably containers, button handling, and display drivers other than the SSD1306.

Committer:
neilt6
Date:
Tue May 27 21:41:28 2014 +0000
Revision:
3:a8f72d4864e6
Parent:
2:bbfc18022ee5
Syntax improvements

Who changed what in which revision?

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