Planeshift
pawsdndbutton.h
Go to the documentation of this file.
1 /*
2  * pawsdndbutton.h - Author: Joe Lyon
3  *
4  * Copyright (C) 2013 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 // pawsbutton.h: interface for the pawsDnDButton class.
20 //
22 
23 #ifndef PAWS_DND_BUTTON_HEADER
24 #define PAWS_DND_BUTTON_HEADER
25 
26 #include "paws/pawswidget.h"
27 #include "paws/pawsbutton.h"
28 #include "paws/pawsprogressbar.h"
29 #include "psslotmgr.h"
30 
31 //#include "globals.h"
32 //#include "pscelclient.h"
33 //#include "net/clientmsghandler.h"
34 //#include "net/cmdhandler.h"
35 //#include "paws/pawsnumberpromptwindow.h"
36 
37 #define DNDBUTTON_DRAGGING 9999
38 
45 class pawsDnDButton : public pawsButton
46 {
47 public:
48  pawsDnDButton();
49  virtual ~pawsDnDButton();
50 
51  virtual bool Setup(iDocumentNode* node);
52  bool SelfPopulate(iDocumentNode* node);
53 
54  virtual bool OnMouseDown(int button, int modifiers, int x, int y);
55  virtual bool OnMouseUp(int button, int modifiers, int x, int y);
56  virtual void MouseOver(bool value);
57 
58  virtual void Draw();
59  void Start(csTicks startTicks, csTicks currentTicks, csTicks duration);
60 
62 
63  void SetTextOffsetY( int offset )
64  {
65  upTextOffsetY = offset;
66  downTextOffsetY = offset;
67  }
69  {
70  return upTextOffsetY;
71  }
72  void SetTextOffsetX( int offset )
73  {
74  upTextOffsetX = offset;
75  downTextOffsetX = offset;
76  }
78  {
79  return upTextOffsetX;
80  }
81  void SetDrag(int isDragDrop)
82  {
83  dragDrop = isDragDrop;
84  }
85  bool PlaceItem(const char* imageName, const char* Name, const char* toolTip, const char* action);
86 
87  csArray<csString>* GetImageNameCallback()
88  {
89  return ImageNameCallback;
90  }
91  void SetImageNameCallback(csArray<csString>* in)
92  {
94  }
95 
96  csArray<csString>* GetNameCallback()
97  {
98  return NameCallback;
99  }
100  void SetNameCallback(csArray<csString>* in)
101  {
102  NameCallback=in;
103  }
104  const char* GetName()
105  {
106  if(GetText())
107  return GetText();
108  return NULL;
109  }
110 
111  csArray<csString>* GetActionCallback()
112  {
113  return ActionCallback;
114  }
115  void SetActionCallback(csArray<csString>* in)
116  {
117  ActionCallback=in;
118  }
119 
121  {
122  this->indexBase=indexBase;
123  }
125  {
126  return indexBase;
127  }
128 
129  void SetMaskingImage(const char* image);
130 
132  {
133  return containerID;
134  }
135 
136  void SetAction(const char* act)
137  {
138  if( act!=NULL )
139  {
140  action=new csString( act );
141  }
142  else
143  {
144  action=NULL;
145  }
146  }
147 
148  void SetAction(csString* act)
149  {
150  if(ActionCallback)
151  {
152  ActionCallback->Get(id-indexBase).Replace(act);
153  }
154  action = act;
155  }
156 
157  const char* GetAction()
158  {
159  if(action!=NULL)
160  {
161  if(!action->IsEmpty())
162  {
163  return action->GetData();
164  }
165  }
166  return NULL;
167  }
168 
169  const char* GetTooltip()
170  {
171  if(baseToolTip)
172  {
173  if(!baseToolTip.IsEmpty())
174  {
175  return baseToolTip.GetData();
176  }
177  }
178  return NULL;
179  }
180 
181  void SetIcon( const char* icon );
182  const char* GetIcon();
183  void ClearIcon();
184 
185  void SetDnDLock(bool locked)
186  {
187  DnDLock = locked;
188  }
189 
190  bool GetDnDLock()
191  {
192  return DnDLock;
193  }
194 
195  /***
196  * Remove all contents of button.
197  */
198  void Clear();
199 
200  /***
201  * Get Button index number
202  */
204  {
205  return id-indexBase;
206  }
207 
208  void SetDragDropInProgress(int val);
209  int IsDragDropInProgress();
210 
211  void DrawMask();
212 
216  char const * GetFontName()
217  {
218  return fontName;
219  }
220 
221  void EnableBackground( bool mode );
222 
223  virtual void OnUpdateData(const char* /*dataname*/, PAWSData &value);
224 
225  void SetToolTip( const char * tooltip );
226 
227  virtual void SetRelativeFrame(int x, int y, int width, int height);
228 
229  void SetWarnLevel( float val, bool low );
230  void SetDangerLevel( float val, bool low );
231  void SetFlashLevel( float val, bool low );
232  void SetWarnMode( int );
233  void SetDangerMode( int );
234  void SetFlashMode( int );
235 
236 protected:
238  int dragDrop;
240  csString* action;
243  int editMode;
245  csArray<csString>* ImageNameCallback;
246  csArray<csString>* NameCallback;
247  csArray<csString>* ActionCallback;
249  csString baseToolTip;
250 
251  float warnLevel;
252  bool warnLow;
253  int warnMode;
254 
255  float dangerLevel;
256  bool dangerLow;
258 
259  float flashLevel;
260  bool flashLow;
262 
263  virtual bool CheckKeyHandled(int keyCode);
264 
265  bool DnDLock; // true = locked, false = enabled.
267  csTicks startTime,
268  castingTime,
270 };
271 
272 //----------------------------------------------------------------------
274 
277 #endif
const char * GetAction()
iPawsImage * GetMaskingImage()
virtual void Draw()
Draws the widget and all of it&#39;s children.
csString toolTip
Tooltip to be displayed.
Definition: pawswidget.h:317
void SetAction(const char *act)
void SetDragDropInProgress(int val)
csTicks lastToolTipTime
void SetWarnMode(int)
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
virtual void OnUpdateData(const char *, PAWSData &value)
int IsDragDropInProgress()
csString baseToolTip
CREATE_PAWS_FACTORY(pawsDnDButton)
void SetTextOffsetX(int offset)
Definition: pawsdndbutton.h:72
csString fontName
Name of currently selected font.
Definition: pawswidget.h:305
csTicks startTime
int upTextOffsetX
Definition: pawsbutton.h:156
virtual bool Setup(iDocumentNode *node)
Setup this widget.
pawsProgressBar * spellProgress
virtual bool OnMouseUp(int button, int modifiers, int x, int y)
Manage mouse up event.
virtual bool CheckKeyHandled(int keyCode)
Allow pawsButton to simulate button pushes based on keypresses.
pawsWidget * Callback
int GetButtonIndex()
void SetIcon(const char *icon)
csArray< csString > * GetActionCallback()
void SetMaskingImage(const char *image)
const char * GetText()
Definition: pawsbutton.h:90
void SetAction(csString *act)
void DrawMask()
Draws the mask picture.
virtual void SetRelativeFrame(int x, int y, int width, int height)
Set the size of this widget and it&#39;s position relative to the parent.
A Drag-and-Drop capable button widget with timer.
Definition: pawsdndbutton.h:45
void SetFlashLevel(float val, bool low)
csString backgroundBackup
int GetTextOffsetY()
Definition: pawsdndbutton.h:68
int downTextOffsetY
Definition: pawsbutton.h:159
void SetWarnLevel(float val, bool low)
int GetTextOffsetX()
Definition: pawsdndbutton.h:77
void SetDrag(int isDragDrop)
Definition: pawsdndbutton.h:81
psSlotManager * mgr
const char * GetIcon()
int upTextOffsetY
Definition: pawsbutton.h:157
void SetDangerMode(int)
void SetDnDLock(bool locked)
csTicks castingTime
void SetNameCallback(csArray< csString > *in)
void SetToolTip(const char *tooltip)
virtual bool OnMouseDown(int button, int modifiers, int x, int y)
Manage mouse down event to test for and apply window changes.
Manages dragging items from one inventory slot to another and dropping them into the world...
Definition: psslotmgr.h:43
const char * GetTooltip()
csArray< csString > * GetImageNameCallback()
Definition: pawsdndbutton.h:87
csArray< csString > * NameCallback
char const * GetFontName()
return the name of the font
void ClearIcon()
virtual void MouseOver(bool value)
Sets hasMouseFocus.
A simple button widget.
Definition: pawsbutton.h:43
void SetImageNameCallback(csArray< csString > *in)
Definition: pawsdndbutton.h:91
int downTextOffsetX
Definition: pawsbutton.h:158
void Start(csTicks startTicks, csTicks currentTicks, csTicks duration)
csArray< csString > * ActionCallback
void SetActionCallback(csArray< csString > *in)
void SetIndexBase(int indexBase)
csArray< csString > * GetNameCallback()
Definition: pawsdndbutton.h:96
bool SelfPopulate(iDocumentNode *node)
This function allows a widget to fill in its own contents from an xml node supplied and calls the sam...
const char * GetName()
bool PlaceItem(const char *imageName, const char *Name, const char *toolTip, const char *action)
csString * action
void SetFlashMode(int)
csArray< csString > * ImageNameCallback
void EnableBackground(bool mode)
void SetTextOffsetY(int offset)
Definition: pawsdndbutton.h:63
virtual ~pawsDnDButton()
void SetDangerLevel(float val, bool low)