HoverRace  2.0
StateButton.h
Go to the documentation of this file.
1 
2 // StateButton.h
3 //
4 // Copyright (c) 2014, 2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "Button.h"
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37  namespace Display {
38  class Display;
39  class Box;
40  }
41 }
42 
43 namespace HoverRace {
44 namespace Display {
45 
51 {
52  using SUPER = Button;
53 
54 public:
55  struct Props
56  {
57  enum {
58  CHECKED = SUPER::Props::NEXT_,
60  };
61  };
62 
63 public:
64  StateButton(Display &display, const std::string &text,
65  uiLayoutFlags_t layoutFlags = 0);
66  StateButton(Display &display, const Vec2 &size, const std::string &text,
67  uiLayoutFlags_t layoutFlags = 0);
68  virtual ~StateButton();
69 
70 public:
71  bool IsChecked() const { return checked; }
72  void SetChecked(bool checked);
73 
74 protected:
81  void SetStateIcon(bool enabled, bool checked,
82  std::shared_ptr<Box> icon)
83  {
84  icons[{enabled, checked}] = std::move(icon);
85  if (enabled == IsEnabled() && checked == IsChecked()) {
86  UpdateIcon();
87  }
88  }
89 
91  void UpdateIcon();
92 
93 public:
94  void FireModelUpdate(int prop) override;
95 
96 private:
97  bool checked;
98 
99  using iconsKey_t = std::pair<bool, bool>;
100  using iconsVal_t = std::shared_ptr<Box>;
101  using icons_t = std::map<iconsKey_t, iconsVal_t>;
103 };
104 
105 } // namespace Display
106 } // namespace HoverRace
107 
108 #undef MR_DllDeclare
std::pair< bool, bool > iconsKey_t
enabled, checked
Definition: StateButton.h:99
First index for subclasses.
Definition: StateButton.h:59
bool IsChecked() const
Definition: StateButton.h:71
std::map< iconsKey_t, iconsVal_t > icons_t
Definition: StateButton.h:101
#define MR_DllDeclare
Definition: StateButton.h:33
icons_t icons
Definition: StateButton.h:102
Definition: Vec.h:38
MR_UInt32 uiLayoutFlags_t
Definition: UiLayoutFlags.h:53
Base class for display managers.
Definition: Display.h:73
A standard button, with a text label.
Definition: Button.h:56
void SetStateIcon(bool enabled, bool checked, std::shared_ptr< Box > icon)
Sets the icon for a button state.
Definition: StateButton.h:81
Base class for clickable areas.
Definition: ClickRegion.h:49
bool checked
Definition: StateButton.h:97
Definition: Announcement.h:24
Definition: StateButton.h:55
Base class for buttons with state (i.e.
Definition: StateButton.h:50
std::shared_ptr< Box > iconsVal_t
Definition: StateButton.h:100