JNR
uiButton.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
31 
32 
40 
41 class uiButton :
42  public uiLabel
43 {
44 private:
45  // Window to redirect commands to (if any)
46  uiWindow* pReceiver;
47 
48  // Textures
49  laTexture texbtn_n;
50  laTexture texbtn_p;
51  laTexture texbtn;
52 
53  // Image button flag and texture
54  bool m_bImageButton;
55  laTexture m_uImg;
56 
57  // Persistent mode flag (stay pressed untli clicked again)
58  M_BOOL _bPersistent;
59 
60  // Repetitive informer (send messages while pressed, not just once)
61  M_BOOL _bRepetitiveInformer;
62 
63 protected:
64 
66  void _drawButton();
67 
68 public:
70  // @{
71  uiButton(void);
72  ~uiButton(void);
73  // @}
74 
76  // @{
77  virtual void create(laPoint3 pos, laPoint3 size);
78  void kill();
79  // @}
80 
82  // @{
83  void togglePersistent(M_BOOL bEnable){ _bPersistent=bEnable; }
84  void toggleRepetitive(M_BOOL bEnable){ _bRepetitiveInformer=bEnable; }
85  // @}
86 
88  // @{
89  M_BOOL isPressed() { return (texbtn.id() == texbtn_p.id())? M_TRUE : M_FALSE; }
90  void press() { texbtn = texbtn_p; }
91  void unpress() { texbtn = texbtn_n; }
92  // @}
93 
95  void setReceiver(uiWindow* pWnd) { pReceiver=pWnd; };
96 
98  void setImage(laTexture img)
99  {
100  m_bImageButton=true;
101  m_uImg=img;
102  };
103 
105  // @{
106  void draw();
107  void reply();
108  // @}
109 
111  // @{
112  virtual void onDown(unsigned nButton);
113  virtual void onUp(unsigned nButton);
114  virtual void onMouseOut();
115  // @}
116 
117  //Load form a template file
118  /*virtual void load(class laFileParser *fp) { uiLabel::load(fp); _nAlignH = M_AC; }*/
119 
120 };
121 
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiButton.cpp:55
void reply()
Handle input message.
Definition: uiButton.cpp:139
void draw()
Draw event.
Definition: uiButton.cpp:93
GUI Push-button.
Definition: uiButton.h:41
void setReceiver(uiWindow *pWnd)
Set receiver window (fires onCommand when the button is clicked)
Definition: uiButton.h:95
uiButton(void)
Bla.
Definition: uiButton.cpp:39
void kill()
Discard window and all children.
Definition: uiButton.cpp:66
2D Texture
Definition: laTexture.h:45
void _drawButton()
Draw button outline.
Definition: uiButton.cpp:72
Base class for GUI windows.
Definition: uiWindow.h:45
Text Label.
Definition: uiLabel.h:41
void setImage(laTexture img)
Set image.
Definition: uiButton.h:98