AWind
TabManual.h
1 /*
2  AWind.h - Arduino window library support for Color TFT LCD Boards
3  Copyright (C)2014 Andrei Degtiarev. All right reserved
4 
5  You can find the latest version of the library at
6  https://github.com/AndreiDegtiarev/AWind
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the CC BY-NC-SA 3.0 license.
10  Please see the included documents for further information.
11 
12  Commercial use of this library requires you to buy a license that
13  will allow commercial use. This includes using the library,
14  modified or not, as a tool to sell products.
15 
16  The license applies to all part of the library including the
17  examples and tools supplied with the library.
18 */
19 #pragma once
20 #include <Window.h>
21 #include "PumpController.h"
23 class TabManual: public Window, public ITouchEventReceiver
24 {
25  Button *_btnStart;
26  Button *_btnStop;
27  PumpController *_pumpController;
28 public:
29  TabManual(PumpController *pumpController, const __FlashStringHelper * name,int left,int top,int width,int height):Window(name,left,top,width,height)
30  {
31  _pumpController = pumpController;
32 
33  SetDecorators(Environment::Get()->FindDecorators(F("Window")));
34 
35  _btnStart = new Button(0, 0, 0, 0, F("Start"));
36  initButton(_btnStart);
37  _btnStart->SetMargins(20, 20);
38  _btnStop = new Button(0, 0, 0, 0, F("Stop"));
39  initButton(_btnStop);
40  _btnStop->SetMargins(30, 20);
41  }
42  void initButton(Button *btn)
43  {
44  btn->RegisterTouchEventReceiver(this);
45  AddChild(btn);
46  }
47  virtual void Move(int left, int top, int width, int height)
48  {
49  Window::Move(left, top, width, height);
50  _btnStart->Move(5, 70, 135, 50);
51  _btnStop->Move(172, 70, 135, 50);
52  }
54  void NotifyTouch(Window *window)
55  {
56  if (window == _btnStart)
57  {
58  _btnStart->SetDecorators(Environment::Get()->FindDecorators(F("RedRectangle")));
59  _pumpController->startPump();
60  }
61  else if (window == _btnStop)
62  {
63  _pumpController->stopPump();
64  _btnStart->SetDecorators(Environment::Get()->FindDecorators(F("Button")));
65  _btnStart->Invalidate();
66  }
67  }
68 };
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
virtual void Move(int left, int top, int width, int height)
Moves and resizes window relativly to the parent window.
Definition: TabManual.h:47
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
virtual void Move(int left, int top, int width, int height)
Moves and resizes window relativly to the parent window.
Definition: Window.h:149
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
Window(const __FlashStringHelper *name, int left, int top, int width, int height)
Constructor.
Definition: Window.h:60
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
void NotifyTouch(Window *window)
Events routing for gui interaction (see RegisterTouchEventReceiver and public ITouchEventReceiver dec...
Definition: TabManual.h:54
Implement button control.
Definition: Button.h:24
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITouchEventReceiver.h:24
Tab for manual control of the pump.
Definition: TabManual.h:23
Implements pump control logic.
Definition: PumpController.h:22
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58