AWind
Dialog.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 "Environment.h"
23 #include "Button.h"
25 class Dialog : public Window, public ITouchEventReceiver
26 {
27  IDialogClosedEventReceiver *_dialogClosedEventReceiver;
28 protected:
33 public:
35 
42  Dialog(const __FlashStringHelper * caption,int left,int top,int width,int height):Window(caption,left,top,width,height)
43  {
44  _btnOK=NULL;
45  _btnCancel=NULL;
46  _dialogClosedEventReceiver=NULL;
47  SetDecorators(Environment::Get()->FindDecorators(F("Dialog")));
48  TextBoxFString *captionText=new TextBoxFString(2,2,width-4,20,caption);
49  captionText->SetDecorators(Environment::Get()->FindDecorators(F("DialogCaption")));
50  captionText->SetFont(BigFont);
51  captionText->SetMargins(0,1);
52  AddChild(captionText);
53  }
55 
61  Dialog(int left,int top,int width,int height):Window(F("Dialog"),left,top,width,height)
62  {
63  _btnOK=NULL;
64  _btnCancel=NULL;
65  _dialogClosedEventReceiver=NULL;
66  SetDecorators(Environment::Get()->FindDecorators(F("Dialog")));
67  }
68 
71  {
72  _dialogClosedEventReceiver=receiver;
73  }
75  void NotifyTouch(Window *window)
76  {
77  if(window!=NULL && (window == _btnOK || window == _btnCancel))
78  {
79  if(_dialogClosedEventReceiver!=NULL)
80  {
81  _dialogClosedEventReceiver->NotifyDialogClosed(this,window == _btnOK?IDialogClosedEventReceiver::OK:IDialogClosedEventReceiver::Cancel);
82  }
83  }
84  else
85  DoControlMessage(window);
86  }
88  virtual void DoControlMessage(Window *window)=0;
89 };
virtual void DoControlMessage(Window *window)=0
Need to be redefinded in derived class.
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
virtual void NotifyDialogClosed(Window *window, DialogResults results)=0
Has to be implemented in target class.
void SetFont(uint8_t *font)
Sets font.
Definition: TextBox.h:64
Button * _btnCancel
Button Cancel has to be initialized in derived class.
Definition: Dialog.h:32
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
void RegisterEndDialogEventReceiver(IDialogClosedEventReceiver *receiver)
Registers extern interface that will be called if dialog is closed.
Definition: Dialog.h:70
Dialog(int left, int top, int width, int height)
Constructor for dialog without caption.
Definition: Dialog.h:61
Button * _btnOK
Button OK has to be initialized in derived class.
Definition: Dialog.h:30
Base class for dialog objects. See Dialogs example Provides basic window functionality.
Definition: Dialog.h:25
void NotifyTouch(Window *window)
Process touch notifications.
Definition: Dialog.h:75
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
Interface that provides dialog closed notifications (user closes dialog window, by pressing OK or can...
Definition: IDialogClosedEventReceiver.h:24
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
Dialog(const __FlashStringHelper *caption, int left, int top, int width, int height)
Constructor for dialog with caption.
Definition: Dialog.h:42
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
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58