AWind
Dialog1.h
1 #pragma once
2 /*
3  AWind.h - Arduino window library support for Color TFT LCD Boards
4  Copyright (C)2014 Andrei Degtiarev. All right reserved
5 
6  You can find the latest version of the library at
7  https://github.com/AndreiDegtiarev/AWind
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the CC BY-NC-SA 3.0 license.
11  Please see the included documents for further information.
12 
13  Commercial use of this library requires you to buy a license that
14  will allow commercial use. This includes using the library,
15  modified or not, as a tool to sell products.
16 
17  The license applies to all part of the library including the
18  examples and tools supplied with the library.
19 */
20 #include <Dialog.h>
21 #include <Label.h>
22 #include "Dialog2.h"
24 class Dialog1 : public Dialog
25 {
27  Button * _btnDlg2;
29  TextBoxNumber *_txtNumber1;
31  TextBoxNumber *_txtNumber2;
32 public:
34 
41  Dialog1(const __FlashStringHelper * caption,int left,int top,int width,int height):Dialog(caption,left,top,width,height)
42  {
43  _txtNumber1=InitNumberFields(0,F("Enter number 1:"));
44  _txtNumber1->SetIsReadOnly(false);
45  _txtNumber2=InitNumberFields(30,F(" Number 2:"));
46 
47  _btnDlg2=new Button(0,0,0,0,F("Get"));
48  InitButton(_btnDlg2,180,70,60);
49  _btnOK=new Button(0,0,0,0,F("OK"));
50  InitButton(_btnOK,60,110,60);
51  _btnCancel=new Button(0,0,0,0,F("Cancel"));
52  InitButton(_btnCancel,130,110,110);
53  }
55  void InitNumbers(float number1,float number2)
56  {
57  _txtNumber1->SetNumber(number1);
58  _txtNumber2->SetNumber(number2);
59  }
61  float GetNumber1()
62  {
63  return _txtNumber1->GetNumber();
64  }
66  float GetNumber2()
67  {
68  return _txtNumber2->GetNumber();
69  }
70 protected:
72  TextBoxNumber *InitNumberFields(int offset,const __FlashStringHelper * text)
73  {
74  Label *label=new Label(10,43+offset,150,25,text);
75  AddChild(label);
76  TextBoxNumber * txtNumber=new TextBoxNumber(130,40+offset,40,20,0);
77  AddChild(txtNumber);
78  return txtNumber;
79  }
81  void InitButton(Button *btn,int left,int top,int width)
82  {
83  btn->Move(left,top,width,25);
84  btn->SetMargins(5,5);
85  btn->RegisterTouchEventReceiver(this);
86  AddChild(btn);
87  }
89  void DoControlMessage(Window *window)
90  {
91  if(window == _btnDlg2)
92  {
93  Dialog2 *dlg=(Dialog2 *)this->FindDialog(F("Dialog2"));
94  dlg->SetNumber(_txtNumber2->GetNumber());
95  IDialogClosedEventReceiver::DialogResults dlgResults=this->DoDialog(dlg);
96  if(dlgResults == IDialogClosedEventReceiver::OK)
97  {
98  _txtNumber2->SetNumber(dlg->GetNumber());
99  }
100  }
101  //out<<F("Button pressed: ")<<sel_index<<endl;
102  }
103 };
void DoControlMessage(Window *window)
Process touch message from child controls.
Definition: Dialog1.h:89
Dialog1(const __FlashStringHelper *caption, int left, int top, int width, int height)
Constructor.
Definition: Dialog1.h:41
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
float GetNumber1()
Return value from text box 1.
Definition: Dialog1.h:61
void SetIsReadOnly(bool isReadOnly)
Defines whether window is readonly.
Definition: TextBoxNumber.h:64
float GetNumber()
Return value from text box.
Definition: Dialog2.h:51
Button * _btnCancel
Button Cancel has to be initialized in derived class.
Definition: Dialog.h:32
Button * _btnOK
Button OK has to be initialized in derived class.
Definition: Dialog.h:30
Text box for numbers.
Definition: TextBoxNumber.h:24
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 SetNumber(float number2)
Init text box value.
Definition: Dialog2.h:46
Example window with yellow background.
Definition: Dialog2.h:24
Base class for dialog objects. See Dialogs example Provides basic window functionality.
Definition: Dialog.h:25
void InitButton(Button *btn, int left, int top, int width)
Create child button.
Definition: Dialog1.h:81
void InitNumbers(float number1, float number2)
Init text box values.
Definition: Dialog1.h:55
Example Dialog with one edit, one readonly field + button that activates another dialog.
Definition: Dialog1.h:24
float GetNumber2()
Return value from text box 2.
Definition: Dialog1.h:66
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
void SetNumber(float number)
Initialize window with number.
Definition: TextBoxNumber.h:74
Implement button control.
Definition: Button.h:24
TextBoxNumber * InitNumberFields(int offset, const __FlashStringHelper *text)
create child text box fields
Definition: Dialog1.h:72
Implement Label control.
Definition: Label.h:24
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58