AWind
ButtonWindow.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 
23 #include "Window.h"
25 class ButtonWindow : public Window
26 {
27 public:
28  enum Pictogram
29  {
30  TriangleLeft,
31  TriangleRight,
32  TriangleTop,
33  TriangleBottom,
34  };
35 private:
36  Pictogram _pictogram;
37 public:
39 
46  ButtonWindow(Pictogram pictogram,int left,int top,int width,int height):Window(F("Button"),left,top,width,height)
47  {
48  _pictogram=pictogram;
49  SetDecorators(Environment::Get()->FindDecorators(F("Button")));
50 
51  }
53 
56  void OnDraw(DC *dc)
57  {
58  //dc->SetColor(_borderColor);
59  int marg=7;
60  int x1=0,x2=0,x3=0;
61  int y1=0,y2=0,y3=0;
62  int x_left=marg;
63  int x_mid=Width()/2;
64  int x_right=Width()-marg;
65  int y_mid=Height()/2;
66  int y_top=marg;
67  int y_bottom=Height()-marg;
68  switch(_pictogram)
69  {
70  case TriangleLeft:
71  x1=x_left;
72  y1=y_mid;
73  x2=x_right;
74  y2=y_top;
75  x3=x_right;
76  y3=y_bottom;
77  break;
78  case TriangleRight:
79  x1=x_left;
80  y1=y_top;
81  x2=x_right;
82  y2=y_mid;
83  x3=x_left;
84  y3=y_bottom;
85  break;
86  case TriangleTop:
87  x1=x_mid;
88  y1=y_top;
89  x2=x_right;
90  y2=y_bottom;
91  x3=x_left;
92  y3=y_bottom;
93  break;
94  case TriangleBottom:
95  x1=x_left;
96  y1=y_top;
97  x2=x_right;
98  y2=y_top;
99  x3=x_mid;
100  y3=y_bottom;
101  break;
102  }
103  dc->MoveTo(x1,y1);
104  dc->LineTo(x2,y2);
105  dc->LineTo(x3,y3);
106  dc->LineTo(x1,y1);
107  }
108 };
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
Implements pictogram buttons.
Definition: ButtonWindow.h:25
ButtonWindow(Pictogram pictogram, int left, int top, int width, int height)
Constructor.
Definition: ButtonWindow.h:46
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
Device context. Abstraction layer to the device specific drawing code. Coordinates in drawing functio...
Definition: DC.h:29
int Height()
Returns window height.
Definition: Window.h:189
void OnDraw(DC *dc)
Implements drawing code.
Definition: ButtonWindow.h:56
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
int Width()
Returns window width.
Definition: Window.h:184