AWind
GaugesWindow.h
1 #pragma once
2 /*
3  AWind.h - Arduino window library support for Color TFT LCD Boards
4  Copyright (C)2014 Andrei Degtiarev. All right reserved
5 
6  You can find the latest version of the library at
7  https://github.com/AndreiDegtiarev/AWind
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the CC BY-NC-SA 3.0 license.
11  Please see the included documents for further information.
12 
13  Commercial use of this library requires you to buy a license that
14  will allow commercial use. This includes using the library,
15  modified or not, as a tool to sell products.
16 
17  The license applies to all part of the library including the
18  examples and tools supplied with the library.
19 */
20 #include "GaugeBar.h"
21 #include "GaugeRadialPointer.h"
22 #include "ChartWindow.h"
23 #include "Button.h"
24 #include "ButtonWindow.h"
25 #include "SensorDataBuffer.h"
26 #include "SensorManager.h"
27 #include "FakeSensor.h"
28 
30 class GaugesWindow : public MainWindow, public ITouchEventReceiver, public ISensorHasDataEventReceiver, public ISensorMeasuredEventReceiver
31 {
32  Gauge *_gaugeBar;
33  Gauge *_gaugeRadialPointer;
34  ChartWindow *_chartWindow;
35  Button *_btnFast;
36  Button *_btnSlow;
37  TextBoxNumber *_txtNumber;
38  ButtonWindow *_btnTop;
39  ButtonWindow *_btnBottom;
40  SensorManager *_sensorManager;
41  bool _isAuto;
42 public:
44 
48  GaugesWindow(int width,int height):MainWindow(width,height)
49  {
50  _sensorManager=NULL;
51  AddDecorator(new DecoratorRectFill(Color::LightGray,false));
52  _isAuto=false;
53  int x=1;
54  int szx=width/4;
55  int szy=height-2;
56  int gauge_axis_y_margins=3;
57  DecoratorAxis *gaugeAxis=new DecoratorAxis(DecoratorAxis::VerticalRight,SmallFont,szy-gauge_axis_y_margins*2,0,100,5);
58  DC dc;
59  int offsetX=gaugeAxis->EstimateRight(&dc);
60  gaugeAxis->SetOffset(szx-offsetX,gauge_axis_y_margins);
61  _gaugeBar=new GaugeBar(gaugeAxis,x,1,szx,szy);
62  _gaugeBar->SetFillColor(Color::LightGray);
63  AddChild(_gaugeBar);
64  x+=szx+3;
65  szx=width/2;
66  _gaugeRadialPointer=new GaugeRadialPointer(x,1,szx,height/2-2);
67  _gaugeRadialPointer->SetFillColor(Color::LightGray);
68  szy=height/2-4;
69  int axis_y_margins=2;
70  DecoratorAxis *chartYAxis=new DecoratorAxis(DecoratorAxis::VerticalLeft,SmallFont,szy-axis_y_margins*2,0,100,5);
71  chartYAxis->SetOffset(4,axis_y_margins);
72  _chartWindow=new ChartWindow(NULL,chartYAxis,x,height/2+2,szx,szy);
73  _chartWindow->AddDecorator(new DecoratorRectFill(Color::LightGray));
74  _chartWindow->AddDecorator(new Decorator3DRect(Color::White,Color::Gray));
75  _chartWindow->AddDecorator(new DecoratorColor(Color::Black));
76  _chartWindow->AddDecorator(chartYAxis);
77  AddChild(_gaugeRadialPointer);
78  AddChild(_chartWindow);
79  x+=szx+2;
80  szx=width/4-6;
81  int y=4;
82  szy=30;
83  _txtNumber=new TextBoxNumber(x,y,szx,szy,0);
84  initTextBox(_txtNumber);
85  y+=szy+13;
86  _btnFast=new Button(x,y,szx,szy,F("Fast"));
87  initTextBox(_btnFast);
88  y+=szy+10;
89  _btnSlow=new Button(x,y,szx,szy,F("Slow"));
90  initTextBox(_btnSlow);
91  y+=szy+10;
92  szx=szy=40;
93  _btnTop=new ButtonWindow(ButtonWindow::TriangleTop,x+15,y,szx,szy);
94  y+=szy+20;
95  _btnBottom=new ButtonWindow(ButtonWindow::TriangleBottom,x+15,y,szx,szy);
96  initButton(_btnTop);
97  initButton(_btnBottom);
98  }
100  void initTextBox(TextBox *textBox)
101  {
102  textBox->SetMargins(0,5);
103  textBox->RegisterTouchEventReceiver(this);
104  //textBox->SetBackColor(GetBackColor());
105  AddChild(textBox);
106  }
108  void initButton(ButtonWindow *button)
109  {
110  button->RegisterTouchEventReceiver(this);
111  AddChild(button);
112  }
114  void NotifyTouch(Window *window)
115  {
116  if(window==_btnFast)
117  {
118  out<<F("touch in gauges fast")<<endln;
119  if(_sensorManager!=NULL)
120  {
121  _sensorManager->SetPause(_sensorManager->GetPause()*0.9);
122  }
123  }
124  else if(window==_btnSlow)
125  {
126  out<<F("touch in gauges slow")<<endln;
127  if(_sensorManager!=NULL)
128  {
129  _sensorManager->SetPause(_sensorManager->GetPause()*1.1);
130  }
131  }
132  else if(window==_btnTop)
133  {
134  out<<F("touch in gauges top")<<endln;
135  if(_sensorManager!=NULL)
136  ((FakeSensor *)_sensorManager->Sensor())->Increase();
137  }
138  else if(window==_btnBottom)
139  {
140  out<<F("touch in gauges bottom")<<endln;
141  if(_sensorManager!=NULL)
142  ((FakeSensor *)_sensorManager->Sensor())->Decrease();
143  }
144  }
146  void NotifySensorHasData(SensorManager *sensorManager)
147  {
148  float value=sensorManager->GetData();
149  _gaugeBar->SetValue(value);
150  _gaugeRadialPointer->SetValue(value);
151  _txtNumber->SetNumber(value);
152  _sensorManager=sensorManager;
153  _chartWindow->SetBuffer(sensorManager->SecBuffer());
154  //_chartWindow->InvalidateOnlyChartArea();
155  }
157  void NotifySensorMeasured(SensorManager *sensorManager)
158  {
159  _chartWindow->InvalidateOnlyChartArea();
160  }
161 };
void initButton(ButtonWindow *button)
Initialize button windows.
Definition: GaugesWindow.h:108
void NotifyTouch(Window *window)
Events routing for gui interaction (see RegisterTouchEventReceiver and public ITouchEventReceiver dec...
Definition: GaugesWindow.h:114
int EstimateRight(DC *dc)
Estimates decorator right coordinate.
Definition: DecoratorPrimitives.h:219
void NotifySensorHasData(SensorManager *sensorManager)
Event sensor has new data. If data is the same as measured previosly. This event is not generated (se...
Definition: GaugesWindow.h:146
void RegisterTouchEventReceiver(ITouchEventReceiver *touchEventReceiver)
Registers receiver for touch event.
Definition: Window.h:102
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 pictogram buttons.
Definition: ButtonWindow.h:25
Base class for window with text content.
Definition: TextBox.h:30
void NotifySensorMeasured(SensorManager *sensorManager)
Event is generated after each measurement.
Definition: GaugesWindow.h:157
Gauge radial pointer class.
Definition: GaugeRadialPointer.h:24
Vertcal axis with the labels left to the axis.
Definition: DecoratorPrimitives.h:152
Text box for numbers.
Definition: TextBoxNumber.h:24
void SetOffset(int offsetX, int offsetY)
Sets decorator offset in the parent window coordinate system.
Definition: DecoratorPrimitives.h:188
void InvalidateOnlyChartArea()
Forces to repain only chart arey (not axises) - reduces flickering.
Definition: ChartWindow.h:60
Axis decorator primitive. It is shared between gauge and chart objects. Overriden members description...
Definition: DecoratorPrimitives.h:145
GaugesWindow(int width, int height)
Constructor.
Definition: GaugesWindow.h:48
void initTextBox(TextBox *textBox)
Initialize text box windows.
Definition: GaugesWindow.h:100
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
Chart window implement XY plots.
Definition: ChartWindow.h:30
Decorator primitive for 3D rectangle. Overriden members description see Decorator class documentation...
Definition: DecoratorPrimitives.h:130
Decorator primitive that sets current color. Overriden members description see Decorator class docume...
Definition: DecoratorPrimitives.h:24
Vertcal axis with the labels right to the axis.
Definition: DecoratorPrimitives.h:153
Main window of gauges example. Routs events between child elements.
Definition: GaugesWindow.h:30
Decorator primitive for round rect filled area. Overriden members description see Decorator class doc...
Definition: DecoratorPrimitives.h:79
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
Fake sensor. It is intended only to generate some data. Sensor value can be modified via Increase...
Definition: FakeSensor.h:22
void SetBuffer(IDataBuffer *buffer)
Sets data buffer.
Definition: ChartWindow.h:54
void SetNumber(float number)
Initialize window with number.
Definition: TextBoxNumber.h:74
void AddDecorator(Decorator *decorator)
Adds decorator to the decaorator list.
Definition: Window.h:86
Implement button control.
Definition: Button.h:24
Base class for main application window. Each application has to have one main window, which is root parent for all other application windows.
Definition: MainWindow.h:38
void SetFillColor(Color fillColor)
Sets fill color.
Definition: Gauge.h:56
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITouchEventReceiver.h:24
Bar gauge class.
Definition: GaugeBar.h:25
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58