AWind
DecoratorPrimitives.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 "AHelper.h"
24 class DecoratorColor : public Decorator
25 {
26  Color _color;
27 public:
29 
32  DecoratorColor(Color color):_color(color)
33  {
34 
35  }
36  void Draw(DC *dc,int left,int top,int width,int height)
37  {
38  dc->SetColor(_color);
39  }
40 };
43 {
44 public:
45  enum Position
46  {
47  Left,
48  Top,
49  Right,
50  Bottom,
51  };
52 private:
53  Position _position;
54 public:
55  DecoratorBoundaryLine(Position position) :_position(position)
56  {
57 
58  }
59  void Draw(DC *dc, int left, int top, int width, int height)
60  {
61  switch (_position)
62  {
63  case Left:
64  dc->Line(0, 0,0, height);
65  break;
66  case Right:
67  dc->Line(width, 0, width, height);
68  break;
69  case Top:
70  dc->Line(0, 0, width, 0);
71  break;
72  case Bottom:
73  dc->Line(0, height, width, height);
74  break;
75  }
76  }
77 };
80 {
81  Color _color;
82  bool _isRound;
83 public:
84  DecoratorRectFill(Color color,bool isRound=true):_color(color),_isRound(isRound)
85  {
86 
87  }
88  void Draw(DC *dc,int left,int top,int width,int height)
89  {
90  dc->SetBackColor(_color);
91  if(_isRound)
92  dc->FillRoundRect (left, top, left+width, top+height);
93  else
94  dc->FillRect (left, top, left+width, top+height);
95  }
96 };
99 {
100  Color _color1;
101  Color _color2;
102 public:
103  DecoratorRectGradientFill(Color color1,Color color2):_color1(color1),_color2(color2)
104  {
105 
106  }
107  void Draw(DC *dc,int left,int top,int width,int height)
108  {
109  //dc->FillGradientRect (left, top, left+width, top+height/2,_color1,_color2);
110  //dc->FillGradientRect (left, top+height/2, left+width, top+height,_color2,_color1);
111  dc->FillGradientRect (left, top, left+width, top+height,_color2,_color1);
112  }
113 };
116 {
117  Color _color;
118 public:
119  DecoratorRoundRect(Color color):_color(color)
120  {
121 
122  }
123  void Draw(DC *dc,int left,int top,int width,int height)
124  {
125  dc->SetColor(_color);
126  dc->DrawRoundRect (left, top, width+left, height+top);
127  }
128 };
131 {
132  Color _color1;
133  Color _color2;
134 public:
135  Decorator3DRect(Color color1,Color color2):_color1(color1),_color2(color2)
136  {
137 
138  }
139  void Draw(DC *dc,int left,int top,int width,int height)
140  {
141  dc->Rectangle3D(left, top, left+width, top+height,_color1,_color2);
142  }
143 };
145 class DecoratorAxis : public Decorator
146 {
147 public:
149  {
153  VerticalRight
154  };
155 private:
156  Orientation _orientation;
157  uint8_t *_font;
158  int _offsetX;
159  int _offsetY;
160  int _length;
161  float _minValue;
162  float _maxValue;
163  int _numTicks;
164  static const int _tick_length=5;
165 public:
167 
175  DecoratorAxis(Orientation orientation,uint8_t *font,int length,float minValue,float maxValue,int nTicks):
176  _orientation(orientation),
177  _font(font),
178  _offsetX(0),
179  _offsetY(0),
180  _length(length),
181  _minValue(minValue),
182  _maxValue(maxValue),
183  _numTicks(nTicks)
184  {
185 
186  }
188  void SetOffset(int offsetX,int offsetY)
189  {
190  _offsetX=offsetX;
191  _offsetY=offsetY;
192  }
194  void GetMinMax(float &minVal,float &maxVal)
195  {
196  minVal=_minValue;
197  maxVal=_maxValue;
198  }
200  void SetMinMax(float minVal,float maxVal)
201  {
202  _minValue=minVal;
203  _maxValue=maxVal;
204  }
206  int GetLength()
207  {
208  return _length;
209  }
210  //Returns axis orientation
212  {
213  return _orientation;
214  }
215  int EstimateLeft(DC *dc)
216  {
217  return _offsetX;
218  }
219  int EstimateRight(DC *dc)
220  {
221  dc->SetFont(_font);
222  switch(_orientation)
223  {
224  case VerticalRight:
225  case VerticalLeft:
226  return (AHelper::GetNumberLength(max(_minValue,_maxValue),1)*dc->FontWidth()+_tick_length)+_offsetX;
227  case HorizontalTop:
228  case HorizontalBottom:
229  return _length+_offsetX;
230  }
231  }
232  int EstimateTop(DC *dc)
233  {
234  return _offsetY;
235  }
237  {
238  dc->SetFont(_font);
239  switch(_orientation)
240  {
241  case VerticalRight:
242  case VerticalLeft:
243  return _length+_offsetY;
244  case HorizontalTop:
245  case HorizontalBottom:
246  return _offsetY+dc->FontHeight()+_tick_length;
247  }
248  }
249  void Draw(DC *dc,int left,int top,int width,int height)
250  {
251  dc->SetFont(_font);
252  float range=_maxValue-_minValue;
253  float step_val=(range)/(_numTicks-1);
254  switch(_orientation)
255  {
256  case VerticalLeft:
257  case VerticalRight:
258  {
259  int y;
260  float scale_step=_length/(_numTicks-1.0);
261  int axis_right=EstimateRight(dc);
262  for(int i=0;i<_numTicks;i++)
263  {
264  y=_length+_offsetY-scale_step*i;
265  float value=_minValue+i*step_val;
266  if(_orientation == VerticalRight)
267  {
268  dc->MoveTo(_offsetX,y);
269  dc->LineTo(_offsetX+_tick_length,y);
270  dc->DrawNumber(value,1,_offsetX+_tick_length,y-(dc->FontHeight()*(i==_numTicks-1?0:1)));
271  }
272  else
273  {
274  dc->MoveTo(axis_right,y);
275  dc->LineTo(axis_right-_tick_length,y);
276  int val_width=AHelper::GetNumberLength(value,1)*dc->FontWidth();
277  dc->DrawNumber(value,1,axis_right-val_width,y-(dc->FontHeight()*(i==_numTicks-1?0:1)));
278  }
279  }
280  }
281  }
282  }
283 };
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:123
int EstimateRight(DC *dc)
Estimates decorator right coordinate.
Definition: DecoratorPrimitives.h:219
int GetLength()
Returns axis length.
Definition: DecoratorPrimitives.h:206
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:88
Implements definition and operations with color.
Definition: Color.h:27
Not implemented yet.
Definition: DecoratorPrimitives.h:151
int EstimateLeft(DC *dc)
Estimates decorator left coordinate.
Definition: DecoratorPrimitives.h:215
int FontHeight()
Returns symbol jeight for the current font.
Definition: DC.h:211
void FillRect(int left, int top, int right, int bottom)
Fills rectangle. Input coordinates have to be defined in the window coordinate system.
Definition: DC.h:116
Vertcal axis with the labels left to the axis.
Definition: DecoratorPrimitives.h:152
Decorator primitive for boundary lines. Overriden members description see Decorator class documentati...
Definition: DecoratorPrimitives.h:42
void DrawNumber(int number, int x, int y)
Draws integer number. Input coordinates have to be defined in the window coordinate system...
Definition: DC.h:161
void SetOffset(int offsetX, int offsetY)
Sets decorator offset in the parent window coordinate system.
Definition: DecoratorPrimitives.h:188
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:36
Axis decorator primitive. It is shared between gauge and chart objects. Overriden members description...
Definition: DecoratorPrimitives.h:145
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:249
Device context. Abstraction layer to the device specific drawing code. Coordinates in drawing functio...
Definition: DC.h:29
Orientation
Definition: DecoratorPrimitives.h:148
int FontWidth()
Returns symbol width for the current font.
Definition: DC.h:206
Decorator primitive for round rect filled area. Overriden members description see Decorator class doc...
Definition: DecoratorPrimitives.h:98
Base class for window decorators. This concept allows sharing of drawing setting among more than one ...
Definition: Decorator.h:24
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:107
Decorator primitive for 3D rectangle. Overriden members description see Decorator class documentation...
Definition: DecoratorPrimitives.h:130
virtual int EstimateRight(DC *dc)
Estimates decorator right coordinate.
Definition: Decorator.h:33
Decorator primitive that sets current color. Overriden members description see Decorator class docume...
Definition: DecoratorPrimitives.h:24
int EstimateBottom(DC *dc)
Estimates decorator bottom coordinate.
Definition: DecoratorPrimitives.h:236
Decorator primitive for round rect filled area. Overriden members description see Decorator class doc...
Definition: DecoratorPrimitives.h:79
DecoratorColor(Color color)
Constructor.
Definition: DecoratorPrimitives.h:32
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:139
void Draw(DC *dc, int left, int top, int width, int height)
Drawing code implementation.
Definition: DecoratorPrimitives.h:59
void SetMinMax(float minVal, float maxVal)
Sets min and max for label values.
Definition: DecoratorPrimitives.h:200
Not implemented yet.
Definition: DecoratorPrimitives.h:150
int EstimateTop(DC *dc)
Estimates decorator top coordinate.
Definition: DecoratorPrimitives.h:232
void Rectangle3D(int left, int top, int right, int bottom, Color color1, Color color2)
Draws rectangle with 3D border. Input coordinates have to be defined in the window coordinate system...
Definition: DC.h:105
void GetMinMax(float &minVal, float &maxVal)
Return min and max label values.
Definition: DecoratorPrimitives.h:194
DecoratorAxis(Orientation orientation, uint8_t *font, int length, float minValue, float maxValue, int nTicks)
Constructor.
Definition: DecoratorPrimitives.h:175
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
void FillGradientRect(int left, int top, int right, int bottom, Color color1, Color color2)
Fills rectangle with gradient color. Input coordinates have to be defined in the window coordinate sy...
Definition: DC.h:121
Decorator primitive for round rectangle. Overriden members description see Decorator class documentat...
Definition: DecoratorPrimitives.h:115
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