Planeshift
pawsbutton.h
Go to the documentation of this file.
1 /*
2  * pawsbutton.h - Author: Andrew Craig
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 // pawsbutton.h: interface for the pawsButton class.
20 //
22 
23 #ifndef PAWS_BUTTON_HEADER
24 #define PAWS_BUTTON_HEADER
25 
26 #include "pawswidget.h"
27 
32 /* Types of flash buttons, used in chat window */
34 {
38 };
39 
40 
43 class pawsButton : public pawsWidget
44 {
45 public:
46  pawsButton();
47  pawsButton(const pawsButton &pb);
48  virtual ~pawsButton();
49 
50  virtual bool Setup(iDocumentNode* node);
51  bool SelfPopulate(iDocumentNode* node);
52 
53  void SetUpImage(const csString &image);
54  void SetDownImage(const csString &image);
55  void SetGreyUpImage(const csString &greyUpImage);
56  void SetGreyDownImage(const csString &greyDownImage);
57 
58  /* Specify the image to use for special flashing in chat window */
59  void SetOnSpecialImage(const csString &image);
60 
61  void SetSound(const char* sound);
62 
63  virtual void Draw();
64 
65  virtual bool OnMouseEnter();
66  virtual bool OnMouseExit();
67  virtual bool OnMouseDown(int button, int modifiers, int x, int y);
68  virtual bool OnMouseUp(int button, int modifiers, int x, int y);
69  virtual bool OnKeyDown(utf32_char keyCode, utf32_char key, int modifiers);
70 
71  virtual bool IsDown()
72  {
73  return down;
74  }
75  virtual void SetState(bool isDown, bool publish=true);
76  virtual bool GetState()
77  {
78  return down;
79  }
81  virtual void SetToggle(bool t)
82  {
83  toggle = t;
84  }
85  virtual void SetEnabled(bool enabled);
86  virtual bool IsEnabled() const;
87  virtual void SetNotify(pawsWidget* widget);
88 
89  void SetText(const char* text);
90  const char* GetText()
91  {
92  return buttonLabel.GetData();
93  }
94 
95  /* Button flashing used mainly in chatwindow */
96  virtual void Flash(bool state, FLASH_STATE type = FLASH_REGULAR)
97  {
98  if(state && !down)
99  {
100  flash = 1;
101  }
102  else
103  {
104  flash = 0;
107  }
108  flashtype = type;
109  }
110 
111 
112 protected:
113 
114  virtual bool CheckKeyHandled(int keyCode);
115 
117  bool down;
118 
120  csRef<iPawsImage> pressedImage;
121 
123  csRef<iPawsImage> releasedImage;
124 
125  csRef<iPawsImage> greyUpImage;
126  csRef<iPawsImage> greyDownImage;
127 
129  csRef<iPawsImage> specialFlashImage;
130 
132  bool toggle;
133 
135  csString buttonLabel;
136 
139 
142 
144  int style;
145 
146  bool enabled;
147 
149  int flash;
150 
153 
155  csString sound_click;
160 
163 
166 };
167 
168 //----------------------------------------------------------------------
170 
173 #endif
pawsWidget * notify
Widget to which event notifications are sent. If NULL, notifications go to parent.
Definition: pawsbutton.h:141
virtual void Draw()
Draws the widget and all of it&#39;s children.
virtual bool OnKeyDown(utf32_char keyCode, utf32_char key, int modifiers)
Process keydown messages.
void SetGreyUpImage(const csString &greyUpImage)
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
virtual bool GetState()
Definition: pawsbutton.h:76
FLASH_STATE
Definition: pawsbutton.h:33
virtual bool IsDown()
Definition: pawsbutton.h:71
virtual void SetNotify(pawsWidget *widget)
virtual ~pawsButton()
CREATE_PAWS_FACTORY(pawsButton)
int upTextOffsetX
Definition: pawsbutton.h:156
char keybinding
Keyboard equivalent of clicking on this button.
Definition: pawsbutton.h:138
csString sound_click
Button can trigger sound effects with this.
Definition: pawsbutton.h:155
virtual bool CheckKeyHandled(int keyCode)
Allow pawsButton to simulate button pushes based on keypresses.
const char * GetText()
Definition: pawsbutton.h:90
csRef< iPawsImage > pressedImage
Image to draw when button is pressed or when the mouse enters.
Definition: pawsbutton.h:120
virtual void SetEnabled(bool enabled)
int originalFontColour
Used when restoring from highlight state.
Definition: pawsbutton.h:162
bool toggle
Check to see if this is a toggle button.
Definition: pawsbutton.h:132
int downTextOffsetY
Definition: pawsbutton.h:159
bool down
Track to see if the button is down.
Definition: pawsbutton.h:117
virtual bool OnMouseUp(int button, int modifiers, int x, int y)
Manage mouse up event.
bool SelfPopulate(iDocumentNode *node)
This function allows a widget to fill in its own contents from an xml node supplied and calls the sam...
void SetUpImage(const csString &image)
void SetText(const char *text)
int upTextOffsetY
Definition: pawsbutton.h:157
virtual bool OnMouseExit()
Called whenever the mouse leaves this widget.
virtual void Flash(bool state, FLASH_STATE type=FLASH_REGULAR)
Definition: pawsbutton.h:96
void SetGreyDownImage(const csString &greyDownImage)
csRef< iPawsImage > releasedImage
Image to draw when button is released or when the mouse exits.
Definition: pawsbutton.h:123
FLASH_STATE flashtype
Type of flash (regular/special)
Definition: pawsbutton.h:152
virtual bool OnMouseDown(int button, int modifiers, int x, int y)
Manage mouse down event to test for and apply window changes.
virtual bool IsEnabled() const
int style
Style – right now only ShadowText supported.
Definition: pawsbutton.h:144
void SetDownImage(const csString &image)
A simple button widget.
Definition: pawsbutton.h:43
int downTextOffsetX
Definition: pawsbutton.h:158
csRef< iPawsImage > greyUpImage
Definition: pawsbutton.h:125
bool enabled
Definition: pawsbutton.h:146
virtual bool Setup(iDocumentNode *node)
Setup this widget.
bool changeOnMouseOver
Whether or not to change image on mouse enter/exit.
Definition: pawsbutton.h:165
virtual void SetState(bool isDown, bool publish=true)
virtual void SetToggle(bool t)
Set the toggle attribute. To change toggle state use SetState.
Definition: pawsbutton.h:81
virtual bool OnMouseEnter()
Called whenever the mouse enters this widget.
csRef< iPawsImage > greyDownImage
Definition: pawsbutton.h:126
void SetSound(const char *sound)
csRef< iPawsImage > specialFlashImage
Image to draw when button is released.
Definition: pawsbutton.h:129
int flash
The state if the button is flashing, 0 is no flashing.
Definition: pawsbutton.h:149
void SetOnSpecialImage(const csString &image)
csString buttonLabel
Text shown in button.
Definition: pawsbutton.h:135
void SetColour(int newColour=-2)
Set text color.