HoverRace  2.0
Button.h
Go to the documentation of this file.
1 
2 // Button.h
3 //
4 // Copyright (c) 2013-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 "Res.h"
25 
26 #include "ClickRegion.h"
27 #include "FillBox.h"
28 
29 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
30 # ifdef MR_ENGINE
31 # define MR_DllDeclare __declspec( dllexport )
32 # else
33 # define MR_DllDeclare __declspec( dllimport )
34 # endif
35 #else
36 # define MR_DllDeclare
37 #endif
38 
39 namespace HoverRace {
40  namespace Display {
41  class BaseContainer;
42  class Display;
43  class Label;
44  class Picture;
45  class Texture;
46  }
47 }
48 
49 namespace HoverRace {
50 namespace Display {
51 
57 {
58  using SUPER = ClickRegion;
59 
60 public:
61  struct Props
62  {
63  enum
64  {
65  TEXT = SUPER::Props::NEXT_,
70  };
71  };
72 
73 public:
74  Button(Display &display, const std::string &text,
75  uiLayoutFlags_t layoutFlags = 0);
76  Button(Display &display, const Vec2 &size, const std::string &text,
77  uiLayoutFlags_t layoutFlags = 0);
78  virtual ~Button();
79 
80 private:
81  void Init(const std::string &text);
82 
83 public:
84  void AttachView(Display &disp) override { AttachViewDynamic(disp, this); }
85 
86 public:
87  bool OnNavigate(const Control::Nav &nav) override;
88 
89 public:
90  const std::string &GetText() const;
91  void SetText(const std::string &text);
92 
93  Alignment getTextAlignment() const;
94  void SetTextAlignment(Alignment textAlignment);
95 
96  Box *GetIcon() const { return icon.get(); }
97  std::shared_ptr<Box> ShareIcon() const { return icon; }
98  void SetIcon(std::shared_ptr<Box> icon);
99 
100  std::shared_ptr<Res<Texture>> ShareTexture() const;
101  void SetTexture(std::shared_ptr<Res<Texture>> image);
102 
103  void SetContents(std::shared_ptr<BaseContainer> contents);
104 
105  Box *GetBackgroundChild() const { return background.get(); }
106  Label *GetLabelChild() const { return label.get(); }
107  Box *GetIconChild() const { return icon.get(); }
108  BaseContainer *GetContentsChild() const { return contents.get(); }
109  Picture *GetPictureChild() const { return picture.get(); }
110  FillBox *GetHighlightChild() const { return highlight.get(); }
111 
112  void SetFixedWidth(double width);
113 
114 protected:
115  void Layout() override;
116 
117 public:
118  Vec3 Measure() override;
119  void FireModelUpdate(int prop) override;
120 
121 private:
122  std::unique_ptr<FillBox> background;
123  std::unique_ptr<Label> label;
124  std::shared_ptr<Box> icon;
125  std::shared_ptr<BaseContainer> contents;
126  std::unique_ptr<Picture> picture;
127  std::unique_ptr<FillBox> highlight;
128  boost::optional<double> fixedWidth;
129  double paddingTop, paddingRight, paddingBottom, paddingLeft, iconGap;
130 };
131 
132 } // namespace Display
133 } // namespace HoverRace
134 
135 #undef MR_DllDeclare
Draws a single texture.
Definition: Picture.h:52
std::unique_ptr< FillBox > highlight
Definition: Button.h:127
Box * GetIconChild() const
Definition: Button.h:107
void AttachView(Display &disp) override
Definition: Button.h:84
Box * GetBackgroundChild() const
Definition: Button.h:105
double paddingTop
Definition: Button.h:129
Definition: Button.h:61
std::unique_ptr< Label > label
Definition: Button.h:123
Base class for loadable textures.
Definition: Res.h:94
boost::optional< double > fixedWidth
Definition: Button.h:128
Alignment
Imagine the component pinned to the container with a thumbtack.
Definition: UiViewModel.h:77
MR_DllDeclare void Init()
Definition: ColorTools.cpp:142
First index for subclasses.
Definition: Button.h:69
Base class for low-level bounded widgets.
Definition: Box.h:51
Base class for widgets that contain other widgets.
Definition: BaseContainer.h:63
A static text label.
Definition: Label.h:51
Definition: Vec.h:38
Box * GetIcon() const
Definition: Button.h:96
std::unique_ptr< Picture > picture
Definition: Button.h:126
#define MR_DllDeclare
Definition: Button.h:36
MR_UInt32 uiLayoutFlags_t
Definition: UiLayoutFlags.h:53
std::shared_ptr< Box > ShareIcon() const
Definition: Button.h:97
Base class for display managers.
Definition: Display.h:73
A standard button, with a text label.
Definition: Button.h:56
std::shared_ptr< Box > icon
Definition: Button.h:124
FillBox * GetHighlightChild() const
Definition: Button.h:110
std::shared_ptr< BaseContainer > contents
Definition: Button.h:125
A navigation direction.
Definition: Nav.h:45
A colored rectangle, that&#39;s all.
Definition: FillBox.h:51
Label * GetLabelChild() const
Definition: Button.h:106
Base class for clickable areas.
Definition: ClickRegion.h:49
Picture * GetPictureChild() const
Definition: Button.h:109
Definition: Announcement.h:24
std::unique_ptr< FillBox > background
Definition: Button.h:122
Definition: Vec.h:114
BaseContainer * GetContentsChild() const
Definition: Button.h:108