AWind
ViewModusWindow.h
1 /*
2  AWind.h - Arduino window library support for Color TFT LCD Boards
3  Copyright (C)2015 Andrei Degtiarev. All right reserved
4 
5 
6  You can always find the latest version of the library at
7  https://github.com/AndreiDegtiarev/AWind
8 
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the CC BY-NC-SA 3.0 license.
12  Please see the included documents for further information.
13 
14  Commercial use of this library requires you to buy a license that
15  will allow commercial use. This includes using the library,
16  modified or not, as a tool to sell products.
17 
18  The license applies to all part of the library including the
19  examples and tools supplied with the library.
20 */
21 #pragma once
22 
23 #include "TextBoxString.h"
24 #include "DecoratorPrimitives.h"
25 
28 {
29 public:
30  enum Modus
31  {
32  Day,
33  Night
34  };
35 private:
36  DecoratorList _dayLightDecorator;
37  DecoratorList _dayLightSensorWndDecorator;
38  DecoratorList _nightDecorator;
39  DecoratorList _alarmDecorator;
40  DecoratorList _chartDecorator;
41  TextBoxFString *_text;
42  Modus _modus;
43 public:
45 
49  ViewModusWindow(int width,int height):MainWindow(width,height)
50  {
51  AddDecorator(new DecoratorRectFill(Color::Black));
52  _dayLightDecorator.Add(new DecoratorRectFill(Color::CadetBlue));
53  _dayLightDecorator.Add(new DecoratorColor(Color::White));
54  _dayLightSensorWndDecorator.Add(new DecoratorRectFill(Color::CadetBlue));
55  _dayLightSensorWndDecorator.Add(new Decorator3DRect(Color::White,Color::Gray));
56  _dayLightSensorWndDecorator.Add(new DecoratorColor(Color::White));
57  _nightDecorator.Add(new DecoratorRectFill(Color::Black));
58  _nightDecorator.Add(new DecoratorColor(Color::White));
59  _alarmDecorator.Add(new DecoratorRectFill(Color::Red,false));
60  _alarmDecorator.Add(new DecoratorColor(Color::White));
61  _chartDecorator.Add(new DecoratorRectFill(Color::Black,false));
62 
63  //SetBackColor(Color::Black);
64  _text=new TextBoxFString(width-100,height-45,95,35,F("Night"));
65  _text->SetFont(BigFont);
66  _text->SetMargins(12,10);
67  _modus=Day;
68  AddChild(_text);
69  this->RegisterTouchEventReceiver(this);
70  }
71  void Initialize()
72  {
73  updateBackColor();
74  }
75  DecoratorList *ChartDecorators()
76  {
77  return &_chartDecorator;
78  }
79  DecoratorList *AlarmDecorators()
80  {
81  return &_alarmDecorator;
82  }
83  DecoratorList *NormalDecorators()
84  {
85  return _modus==Day?&_dayLightDecorator:&_nightDecorator;
86  }
87  DecoratorList *NormalSensorWndDecorators()
88  {
89  return _modus==Day?&_dayLightSensorWndDecorator:&_nightDecorator;
90  }
91  void SetModus(Modus modus)
92  {
93  if(modus!=_modus)
94  NotifyTouch(NULL);
95  }
97  void NotifyTouch(Window *wnd)
98  {
99  if(_modus==Day)
100  {
101  _modus=Night;
102  _text->SetText(F("Day"));
103  }
104  else
105  {
106  _modus=Day;
107  _text->SetText(F("Night"));
108  }
109  updateBackColor();
110  Invalidate();
111  }
112 protected:
113  void updateBackColor()
114  {
115  for(int i=0;i<Children().Count();i++)
116  {
117  Children()[i]->SetDecorators(NormalDecorators());
118  _text->SetDecorators(NormalSensorWndDecorators());
119  }
120  }
121 };
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
void SetText(T *text)
Initialize window with text.
Definition: TextBoxString.h:64
void SetFont(uint8_t *font)
Sets font.
Definition: TextBox.h:64
Main window that controls child window appearance (day/night/alarm) for windows like sensor window...
Definition: ViewModusWindow.h:27
ViewModusWindow(int width, int height)
Constructor.
Definition: ViewModusWindow.h:49
LinkedList< Window > & Children()
Returns list of children window.
Definition: Window.h:223
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
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
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
void AddDecorator(Decorator *decorator)
Adds decorator to the decaorator list.
Definition: Window.h:86
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
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
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITouchEventReceiver.h:24
void NotifyTouch(Window *wnd)
Switcher for day and night modus.
Definition: ViewModusWindow.h:97
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58