AWind
Gauge.h
1 #pragma once
2 /*
3  AWind.h - Arduino window library support for Color TFT LCD Boards
4  Copyright (C)2015 Andrei Degtiarev. All right reserved
5 
6 
7  You can always find the latest version of the library at
8  https://github.com/AndreiDegtiarev/AWind
9 
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the CC BY-NC-SA 3.0 license.
13  Please see the included documents for further information.
14 
15  Commercial use of this library requires you to buy a license that
16  will allow commercial use. This includes using the library,
17  modified or not, as a tool to sell products.
18 
19  The license applies to all part of the library including the
20  examples and tools supplied with the library.
21 */
22 #include "Window.h"
24 class Gauge : public Window
25 {
26 public:
28  float _value;
29  float _oldValue;
30  float _minValue;
31  float _maxValue;
33 
34  static const float _sector_angle_rad;
35 
37 
44  Gauge(int left,int top,int width,int height)
45  :Window(F("gauge"),left,top,width,height),
46  _value(0),
47  _oldValue(0),
48  _minValue(0),
49  _maxValue(100),
50  _fillColor(Color::Black),
51  _drawOnlyPointer(false)
52  {
53  SetDecorators(Environment::Get()->FindDecorators(F("Gauge")));
54  }
56  void SetFillColor(Color fillColor)
57  {
58  _fillColor=fillColor;
59  }
61 
65  void SetMinMax(float minVal,float maxVal)
66  {
67  _minValue=minVal;
68  _maxValue=maxVal;
69  }
71 
75  float SetValue(float value)
76  {
77  _value=max(_minValue,value);
78  _value=min(_maxValue,_value);
79  //out<<F("Gauge value: ")<<_value<<endln;
80  _drawOnlyPointer=true;
81  if (this->IsVisible())
82  {
83  DC dc;
84  PrepareDC(&dc);
85  OnDraw(&dc);
86  }
87  _oldValue=_value;
88  _drawOnlyPointer=false;
89  }
90 };
91 const float Gauge::_sector_angle_rad = 3.14 / 2 * 0.8;
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
float SetValue(float value)
Sets display value.
Definition: Gauge.h:75
Implements definition and operations with color.
Definition: Color.h:27
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
Color _fillColor
Gauge fill color.
Definition: Gauge.h:27
void PrepareDC(DC *dc)
Setups window coordinate system. This function called by window manager right before window has to be...
Definition: Window.h:249
Gauge window class, that allows visualisaion of data in form of bar or radial pointer.
Definition: Gauge.h:24
Device context. Abstraction layer to the device specific drawing code. Coordinates in drawing functio...
Definition: DC.h:29
float _value
Current gauge value.
Definition: Gauge.h:28
float _minValue
Gauge min limit.
Definition: Gauge.h:30
bool _drawOnlyPointer
Defines whether only pointer (not scale has to be drawn)
Definition: Gauge.h:32
float _maxValue
Gauge max limit.
Definition: Gauge.h:31
virtual void OnDraw(DC *dc)
If derived class needs to draw something in window client area, this function has to be ovverriden...
Definition: Window.h:263
bool IsVisible()
Returns true if window visible and false is hidden.
Definition: Window.h:211
float _oldValue
Previos gauge value.
Definition: Gauge.h:29
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
void SetMinMax(float minVal, float maxVal)
Sets values range.
Definition: Gauge.h:65
void SetFillColor(Color fillColor)
Sets fill color.
Definition: Gauge.h:56
Gauge(int left, int top, int width, int height)
Constructor.
Definition: Gauge.h:44