libwallaby  v24
The wallaby standard library
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_ */
Button
Definition: button.hpp:84
Button::A
EXPORT_SYM IdButton A
Button::Left
EXPORT_SYM IdButton Left
button_ids.hpp
AbstractTextButton::text
virtual const char * text() const =0
Button::B
EXPORT_SYM IdButton B
AbstractTextButton::resetText
virtual void resetText()=0
Button::Right
EXPORT_SYM IdButton Right
Button::X
EXPORT_SYM IdButton X
ExtraButtons
Definition: button.hpp:72
IdButton
Definition: button.hpp:55
Button::Type::Id
Id
Definition: button_ids.hpp:16
Sensor::value
virtual T value() const =0
AbstractTextButton::setText
virtual void setText(const char *text)=0
AbstractButton::isNotPressed
bool isNotPressed() const
Definition: button.hpp:24
Button::all
EXPORT_SYM IdButton *const all[8]
AbstractButton::isPressed
bool isPressed() const
Definition: button.hpp:22
sensor.hpp
AbstractButton
Definition: button.hpp:16
AbstractTextButton
Definition: button.hpp:41
Button::Z
EXPORT_SYM IdButton Z
AbstractTextButton::isTextDirty
virtual bool isTextDirty() const =0
EXPORT_SYM
#define EXPORT_SYM
Definition: export.h:14
Button::Y
EXPORT_SYM IdButton Y
Button::C
EXPORT_SYM IdButton C
Sensor
Definition: sensor.hpp:17
AbstractButton::setPressed
virtual void setPressed(bool pressed)=0
AbstractButton::isClicked
bool isClicked() const
Definition: button.hpp:26
export.h