Planeshift
pawscolorpromptwindow.h
Go to the documentation of this file.
1 /*
2  * pawsnumberpromptwindow.h - Author: Ondrej Hurt
3  *
4  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef PAWS_COLOR_PROMPT_WINDOW_HEADER
21 #define PAWS_COLOR_PROMPT_WINDOW_HEADER
22 
23 #include <csutil/list.h>
24 #include <iutil/document.h>
25 #include "pawspromptwindow.h"
26 #include "pawsbutton.h"
27 #include "pawscrollbar.h"
28 
29 class pawsButton;
30 class pawsEditTextBox;
31 class pawsScrollbar;
32 
38 {
39 public:
40  virtual void OnColorEntered(const char* name,int param,int color) = 0;
41  // can be -1
42  virtual ~iOnColorEnteredAction() {};
43 };
44 
45 class pawsColorInput : public pawsWidget
46 {
47 public:
49  {
50  SetRelativeFrameSize(140, 80);
51 
52  // we have three scroll bars, one for Red, Green and Blue and a button used for "Preview".
53  // The preview works following: As soon as the user scrolls, the buttons background colour
54  // changes to the set colour.
55  scrollBarR = new pawsScrollBar();
56  scrollBarR->SetHorizontal(true);
57  scrollBarR->SetRelativeFrame(1, 1, 110, 20);
58  scrollBarR->SetTickValue(1);
59  scrollBarR->PostSetup();
60 
61  scrollBarG = new pawsScrollBar();
62  scrollBarG->SetHorizontal(true);
63  scrollBarG->SetRelativeFrame(1, 31, 110, 20);
64  scrollBarG->SetTickValue(1);
65  scrollBarG->PostSetup();
66 
67  scrollBarB = new pawsScrollBar();
68  scrollBarB->SetHorizontal(true);
69  scrollBarB->SetRelativeFrame(1, 61, 110, 20);
70  scrollBarB->SetTickValue(1);
71  scrollBarB->PostSetup();
72 
73  buttonPreview = new pawsButton();
74  buttonPreview->SetRelativeFrame(115, 35, 20, 20);
75 
76  AddChild(scrollBarR);
77  AddChild(scrollBarG);
78  AddChild(scrollBarB);
79  AddChild(buttonPreview);
80  }
81 
82  pawsColorInput(const pawsColorInput &origin):pawsWidget(origin)
83  {
84  buttonPreview = 0;
85  scrollBarB = 0;
86  scrollBarG = 0;
87  scrollBarR = 0;
88  for(unsigned int i = 0 ; i < origin.children.GetSize(); i++)
89  {
90  if(origin.children[i] == origin.buttonPreview)
91  buttonPreview = dynamic_cast<pawsButton*>(children[i]);
92  else if(origin.children[i] == origin.scrollBarB)
93  scrollBarB = dynamic_cast<pawsScrollBar*>(children[i]);
94  else if(origin.children[i] == origin.scrollBarG)
95  scrollBarG = dynamic_cast<pawsScrollBar*>(children[i]);
96  else if(origin.children[i] == origin.scrollBarR)
97  scrollBarR = dynamic_cast<pawsScrollBar*>(children[i]);
98 
99  if(buttonPreview != 0 && scrollBarB != 0 && scrollBarG != 0 && scrollBarR != 0) break;
100  }
101  }
102 
107 };
108 
114 {
115 public:
118  //from pawsWidget:
119  virtual bool PostSetup();
120  bool OnButtonPressed(int mouseButton, int keyModifier, pawsWidget* widget);
121  virtual bool OnKeyDown(utf32_char keyCode, utf32_char keyChar, int modifiers);
122  virtual bool OnScroll(int scrollDirection, pawsScrollBar* widget);
123 
124  void Initialize(const csString &label, int color, int minColor, int maxColor,
125  iOnColorEnteredAction* action,const char* name, int param=0);
126 
127  static pawsColorPromptWindow* Create(const csString &label,
128  int color, int minColor, int maxColor,
129  iOnColorEnteredAction* action,const char* name, int param=0);
130 
131 
132 protected:
135  void SetBoundaries(int minColor, int maxColor);
136 
138  void ColorWasEntered(int color);
139 
140  int maxColor, minColor;
141 
143  csString lastValidText;
144 
148 
150 
152  csString name;
153  int param;
154 };
155 
157 
160 #endif
161 
pawsColorInput(const pawsColorInput &origin)
pawsColorPromptWindow is window that lets the user enter a color by the use of three sliders and a co...
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
pawsScrollBar * scrollBarG
An edit box widget/.
Definition: pawstextbox.h:409
pawsScrollBar * scrollBarR
pawsScrollBar * scrollBarB
pawsButton * buttonPreview
A simple scroll bar widget.
Definition: pawscrollbar.h:64
csString lastValidText
This is last valid input from user - we use it to fall back from invalid input.
void void Initialize(iObjectRegistry *object_reg)
pawsPromptWindow is the common base for windows that let the user enter one piece of information...
CREATE_PAWS_FACTORY(pawsColorInput)
A simple button widget.
Definition: pawsbutton.h:43
iOnColorEnteredAction * action
virtual void OnColorEntered(const char *name, int param, int color)=0
csArray< pawsWidget * > children
The child widgets.
Definition: pawswidget.h:160