AWind
WindowSelector.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 "MainWindow.h"
21 #include "Button.h"
22 
25 {
26  LinkedList<Button> _listButtons; //list of buttons on the left scrren side
27  LinkedList<Window> _listWindow; //list of depended windows (
28 public:
29  WindowSelector(int wnd_width,int wnd_height):MainWindow(wnd_width,wnd_height)
30  {
31  }
33  void AddTab(const __FlashStringHelper *buttonName,Window *window)
34  {
35  int wnd_width=Width();
36  int wnd_height=Height();
37  int szx=110;
38  int szy=40;
39  int x=0;
40  int y=0;
41  Button * button=new Button(x+10,(szy+10)*(_listButtons.Count())+20,szx,szy,buttonName);
42  button->SetMargins(5,15);
43  button->RegisterTouchEventReceiver(this);
44  AddChild(button);
45  AddChild(window);
46  window->Move(szx+25,0,wnd_width-szx-25,wnd_height);
47  _listButtons.Add(button);
48  _listWindow.Add(window);
49  if(_listWindow.Count()>1)
50  window->SetVisible(false);
51  else
52  _listButtons[0]->SetDecorators(_listWindow[0]->GetDecorators());
53 
54  }
55  void Initialize()
56  {
57  AddDecorator(new DecoratorRectFill(Color::LightGray,false));
58  AddDecorator(new DecoratorColor(Color::Black));
59 
60  }
62  void NotifyTouch(Window *window)
63  {
64  int sel_index=-1;
65  for(int i=0;i<_listButtons.Count();i++)
66  {
67  if(window == _listButtons[i])
68  {
69  sel_index=i;
70  break;
71  }
72  }
73  if(sel_index >=0)
74  {
75  DecoratorList *buttonDeco=Environment::Get()->FindDecorators(F("Button"));
76  for(int i=0;i<_listButtons.Count();i++)
77  {
78  _listWindow[i]->SetVisible(i==sel_index);
79  if(i==sel_index)
80  {
81  _listWindow[i]->Invalidate();
82  _listButtons[i]->SetDecorators(_listWindow[i]->GetDecorators());
83  }
84  else
85  {
86  if(_listButtons[i]->GetDecorators()!=buttonDeco)
87  {
88  _listButtons[i]->SetDecorators(buttonDeco);
89  _listButtons[i]->Invalidate();
90  }
91  }
92  }
93  }
94  //out<<F("Window selected: ")<<sel_index<<endl;
95  }
96 };
void RegisterTouchEventReceiver(ITouchEventReceiver *touchEventReceiver)
Registers receiver for touch event.
Definition: Window.h:102
DecoratorList * GetDecorators()
Returns window decorators list.
Definition: Window.h:81
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
Window selector main window. It works as kind of tab control and can be used more or less without mod...
Definition: WindowSelector.h:24
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 NotifyTouch(Window *window)
Events routing for gui interaction (see RegisterTouchEventReceiver and public ITouchEventReceiver dec...
Definition: WindowSelector.h:62
int Height()
Returns window height.
Definition: Window.h:189
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
void SetVisible(bool isVisible)
Sets window visibility status.
Definition: Window.h:205
MainWindow(int width, int height)
Constructor.
Definition: MainWindow.h:52
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
DecoratorList * FindDecorators(const __FlashStringHelper *id)
Finds registered decorators by the name.
Definition: Environment.h:59
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITouchEventReceiver.h:24
int Width()
Returns window width.
Definition: Window.h:184
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58
void AddTab(const __FlashStringHelper *buttonName, Window *window)
Adds pair: button + corresponding window.
Definition: WindowSelector.h:33