AWind
GaugeBar.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 "Gauge.h"
23 #include "DecoratorPrimitives.h"
25 class GaugeBar : public Gauge
26 {
27  Color _barColor;
28 public:
30 
38  GaugeBar(DecoratorAxis *axis,int left,int top,int width,int height)
39  :Gauge(left,top,width,height),_axis(axis)
40  {
41  //Make copy of gauge decorators because of axis decorator
42  SetDecorators(new DecoratorList(*GetDecorators()));
43  AddDecorator(axis);
44  _barColor = Color::Red;
45  }
47  void SetBarColor(Color color)
48  {
49  _barColor = color;
50  }
52 
55  void OnDraw(DC *dc)
56  {
57  //out<<"value :"<<_value<<endln;
58  dc->SetFont(SmallFont);
59  //float range=_maxValue-_minValue;
60  float saling_factor=_axis->GetLength()/(_maxValue-_minValue);
61  int right_offset = _axis->EstimateLeft(dc);
62  int top = _axis->EstimateTop(dc);
63  int bottom = _axis->EstimateBottom(dc);
64  if (!_drawOnlyPointer)
65  dc->DrawRoundRect(2, 2, right_offset - 1, Height() - 2);
67  {
68  int dc_level = bottom - _value*saling_factor;
69  if (_oldValue > _value)
70  {
71  dc->SetColor(_fillColor);
72  dc->FillRoundRect(4, bottom - _oldValue*saling_factor, right_offset - 3, min(bottom, dc_level + 3));
73  }
74  dc->SetColor(_barColor);
75  dc->FillRoundRect(4, dc_level, right_offset - 3, bottom);
76  }
77  else
78  {
79  bottom = Height() - 4;
80  int dc_level = _value*saling_factor;
81  if (_oldValue > _value)
82  {
83  dc->SetColor(_fillColor);
84  dc->FillRoundRect(max(4, dc_level - 3), 4, _oldValue*saling_factor, bottom);
85  }
86  dc->SetColor(_barColor);
87  dc->FillRoundRect(4, 4, dc_level, bottom);
88  }
89  }
90 };
void SetBarColor(Color color)
Set Bar color.
Definition: GaugeBar.h:47
DecoratorList * GetDecorators()
Returns window decorators list.
Definition: Window.h:81
int GetLength()
Returns axis length.
Definition: DecoratorPrimitives.h:206
Implements definition and operations with color.
Definition: Color.h:27
int EstimateLeft(DC *dc)
Estimates decorator left coordinate.
Definition: DecoratorPrimitives.h:215
Vertcal axis with the labels left to the axis.
Definition: DecoratorPrimitives.h:152
void OnDraw(DC *dc)
Implements drawing code.
Definition: GaugeBar.h:55
Color _fillColor
Gauge fill color.
Definition: Gauge.h:27
Axis decorator primitive. It is shared between gauge and chart objects. Overriden members description...
Definition: DecoratorPrimitives.h:145
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
Orientation
Definition: DecoratorPrimitives.h:148
float _value
Current gauge value.
Definition: Gauge.h:28
int Height()
Returns window height.
Definition: Window.h:189
DecoratorAxis * _axis
Definition: GaugeBar.h:29
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
Vertcal axis with the labels right to the axis.
Definition: DecoratorPrimitives.h:153
int EstimateBottom(DC *dc)
Estimates decorator bottom coordinate.
Definition: DecoratorPrimitives.h:236
void AddDecorator(Decorator *decorator)
Adds decorator to the decaorator list.
Definition: Window.h:86
float _oldValue
Previos gauge value.
Definition: Gauge.h:29
int EstimateTop(DC *dc)
Estimates decorator top coordinate.
Definition: DecoratorPrimitives.h:232
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
void DrawRoundRect(int left, int top, int right, int bottom)
Draws rounded rectangle. Input coordinates have to be defined in the window coordinate system...
Definition: DC.h:156
GaugeBar(DecoratorAxis *axis, int left, int top, int width, int height)
Constructor.
Definition: GaugeBar.h:38
void FillRoundRect(int left, int top, int right, int bottom)
Fills rounded rectangle. Input coordinates have to be defined in the window coordinate system...
Definition: DC.h:151
Bar gauge class.
Definition: GaugeBar.h:25