libwallaby  v23
The wallaby standard library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
button.hpp
Go to the documentation of this file.
1 /*
2  * button.hpp
3  *
4  * Created on: Nov 12, 2015
5  * Author: Joshua Southerland
6  */
7 
8 #ifndef INCLUDE_WALLABY_BUTTON_HPP_
9 #define INCLUDE_WALLABY_BUTTON_HPP_
10 
11 #include "sensor.hpp"
12 #include "button_ids.hpp"
13 #include "export.h"
14 
15 
16 class EXPORT_SYM AbstractButton : public Sensor<bool>
17 {
18 public:
19  virtual ~AbstractButton();
20  virtual void setPressed(bool pressed) = 0;
21 
22  inline bool isPressed() const { return value(); };
23 
24  inline bool isNotPressed() const { return !isPressed(); }
25 
26  inline bool isClicked() const
27  {
28  const bool ret = isPressed();
29  waitUntilReleased();
30  return ret;
31  }
32 
33  virtual void waitUntilReleased() const;
34 
35  virtual void waitUntilPressed() const;
36 
37  virtual void waitUntilClicked() const;
38 };
39 
40 
42 {
43 public:
44  virtual ~AbstractTextButton();
45 
46  virtual void setText(const char * text) = 0;
47 
48  virtual const char * text() const = 0;
49 
50  virtual bool isTextDirty() const = 0;
51 
52  virtual void resetText() = 0;
53 };
54 
56 {
57 public:
58  IdButton(const Button::Type::Id & id, const char * defaultText);
59  ~IdButton();
60 
61  virtual void setText(const char * text);
62  virtual const char * text() const;
63  virtual bool isTextDirty() const;
64  virtual void setPressed(bool pressed);
65  virtual bool value() const;
66  virtual void resetText();
67 private:
68  Button::Type::Id m_id;
69  char * m_defaultText;
70 };
71 
73 {
74 public:
75  static void show();
76 
77  static void hide();
78 
79  static void setShown(bool shown);
80 
81  static bool isShown();
82 };
83 
84 namespace Button
85 {
86  extern EXPORT_SYM IdButton A;
87  extern EXPORT_SYM IdButton B;
88  extern EXPORT_SYM IdButton C;
89 
90  extern EXPORT_SYM IdButton X;
91  extern EXPORT_SYM IdButton Y;
92  extern EXPORT_SYM IdButton Z;
93 
94  extern EXPORT_SYM IdButton Left;
95  extern EXPORT_SYM IdButton Right;
96 
97  extern EXPORT_SYM IdButton * const all[8];
98 };
99 
100 #endif /* INCLUDE_WALLABY_BUTTON_HPP_ */
Definition: button.hpp:72
virtual void setText(const char *text)=0
Definition: sensor.hpp:17
EXPORT_SYM IdButton Left
EXPORT_SYM IdButton A
virtual bool isTextDirty() const =0
virtual void setPressed(bool pressed)=0
virtual T value() const =0
EXPORT_SYM IdButton X
EXPORT_SYM IdButton B
virtual const char * text() const =0
virtual void resetText()=0
bool isPressed() const
Definition: button.hpp:22
EXPORT_SYM IdButton Z
EXPORT_SYM IdButton Right
EXPORT_SYM IdButton Y
Definition: button.hpp:41
Definition: button.hpp:55
EXPORT_SYM IdButton C
bool isNotPressed() const
Definition: button.hpp:24
#define EXPORT_SYM
Definition: export.h:14
EXPORT_SYM IdButton *const all[8]
Definition: button.hpp:84
Id
Definition: button_ids.hpp:16
Definition: button.hpp:16
bool isClicked() const
Definition: button.hpp:26