HoverRace  2.0
Display.h
Go to the documentation of this file.
1 
2 // Display.h
3 //
4 // Copyright (c) 2013-2015 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 "../Vec.h"
25 #include "Styles.h"
26 #include "UiLayoutFlags.h"
27 #include "ViewAttacher.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 ActiveText;
42  class BaseContainer;
43  class Button;
44  class ClickRegion;
45  class FillBox;
46  class KeycapIcon;
47  class Label;
48  class Picture;
49  class RuleLine;
50  class ScreenFade;
51  class Slider;
52  class SymbolIcon;
53  class TypeCase;
54  class Wallpaper;
55  }
56  namespace VideoServices {
57  class VideoBuffer;
58  }
59 }
60 
61 namespace HoverRace {
62 namespace Display {
63 
74  public ViewAttacher<ActiveText>,
75  public ViewAttacher<BaseContainer>,
76  public ViewAttacher<Button>,
77  public ViewAttacher<ClickRegion>,
78  public ViewAttacher<FillBox>,
79  public ViewAttacher<KeycapIcon>,
80  public ViewAttacher<Label>,
81  public ViewAttacher<Picture>,
82  public ViewAttacher<RuleLine>,
83  public ViewAttacher<ScreenFade>,
84  public ViewAttacher<Slider>,
85  public ViewAttacher<SymbolIcon>,
86  public ViewAttacher<Wallpaper>
87 {
88 public:
89  Display() : uiOrigin(0, 0), uiLayoutFlags(0), uiScale(1.0),
90  uiOffset(0, 0), uiScreenSize(1280, 720) { }
91  virtual ~Display() { }
92 
93 public:
99  std::shared_ptr<TypeCase> GetTypeCase(const UiFont &font);
100 
101  void CleanTypeCaseCache();
102 
103 protected:
112  virtual std::shared_ptr<TypeCase> MakeTypeCase(const UiFont &font) = 0;
113 
114 public:
124  virtual VideoServices::VideoBuffer &GetLegacyDisplay() const = 0;
125 
135  virtual void OnDesktopModeChanged(int width, int height) = 0;
136 
149  virtual void OnDisplayConfigChanged();
150 
151 public:
153  boost::signals2::signal<void(int, int)>;
154  displayConfigChangedSignal_t &GetDisplayConfigChangedSignal() { return displayConfigChangedSignal; }
155 protected:
156  void FireDisplayConfigChangedSignal(int width, int height) const;
157 
158 public:
159  using uiScaleChangedSignal_t =
160  boost::signals2::signal<void(double)>;
161  uiScaleChangedSignal_t &GetUiScaleChangedSignal() { return uiScaleChangedSignal; }
162 protected:
163  void FireUiScaleChangedSignal(double scale) const;
164 
165 public:
169  virtual void Flip() = 0;
170 
174  virtual void Screenshot() = 0;
175 
176 public:
181  const Vec2 &GetUiOrigin() const noexcept { return uiOrigin; }
182 
190  void SetUiOrigin(const Vec2 &vec) noexcept { uiOrigin = vec; }
191 
198  Vec2 AddUiOrigin(const Vec2 &vec) noexcept
199  {
200  Vec2 oldOrigin = uiOrigin;
201  uiOrigin += vec;
202  return oldOrigin;
203  }
204 
211  void SetUiLayoutFlags(uiLayoutFlags_t flags) noexcept { uiLayoutFlags = flags; }
212 
220  {
221  auto oldFlags = uiLayoutFlags;
222  uiLayoutFlags |= flags;
223  return oldFlags;
224  }
225 
226  double GetUiScale() const noexcept { return uiScale; }
227  const Vec2 &GetUiOffset() const noexcept { return uiOffset; }
228 
229  Vec2 LayoutUiPosition(const Vec2 &relPos, uiLayoutFlags_t layoutFlags = 0)
230  noexcept
231  {
232  Vec2 adjustedPos = relPos;
233  adjustedPos += GetUiOrigin();
234  if (!((layoutFlags | uiLayoutFlags) & UiLayoutFlags::UNSCALED)) {
235  adjustedPos *= GetUiScale();
236  }
237  if (!((layoutFlags | uiLayoutFlags) & UiLayoutFlags::FLOATING)) {
238  adjustedPos += GetUiOffset();
239  }
240  return adjustedPos;
241  }
242 
251  const Vec2 &GetUiScreenSize() const noexcept { return uiScreenSize; }
252 
253 private:
256  double uiScale;
259  std::unordered_map<UiFont, std::weak_ptr<TypeCase>> typeCases;
262 
263 public:
265 };
266 
267 } // namespace Display
268 } // namespace HoverRace
269 
270 #undef MR_DllDeclare
Vec2 uiOffset
Definition: Display.h:257
boost::signals2::signal< void(int, int)> displayConfigChangedSignal_t
Definition: Display.h:153
Describes a font used for the UI.
Definition: UiFont.h:44
const Vec2 & GetUiOrigin() const noexcept
Retrieve the current UI origin coordinates.
Definition: Display.h:181
Vec2 uiOrigin
Definition: Display.h:254
uiLayoutFlags_t uiLayoutFlags
Definition: Display.h:255
Shared styles for UI components.
Definition: Styles.h:45
#define MR_DllDeclare
Definition: Display.h:36
boost::signals2::signal< void(double)> uiScaleChangedSignal_t
Definition: Display.h:160
uiScaleChangedSignal_t uiScaleChangedSignal
Definition: Display.h:261
Interface for classes that can attach a view to a model.
Definition: ViewAttacher.h:43
Definition: Vec.h:38
Vec2 uiScreenSize
Definition: Display.h:258
uiScaleChangedSignal_t & GetUiScaleChangedSignal()
Definition: Display.h:161
std::unordered_map< UiFont, std::weak_ptr< TypeCase > > typeCases
Definition: Display.h:259
MR_UInt32 uiLayoutFlags_t
Definition: UiLayoutFlags.h:53
Don&#39;t scale the component to the UI viewport.
Definition: UiLayoutFlags.h:48
Base class for display managers.
Definition: Display.h:73
Video framebuffer for legacy (8-bit, palettized) rendering.
Definition: VideoBuffer.h:54
displayConfigChangedSignal_t displayConfigChangedSignal
Definition: Display.h:260
Vec2 LayoutUiPosition(const Vec2 &relPos, uiLayoutFlags_t layoutFlags=0) noexcept
Definition: Display.h:229
double GetUiScale() const noexcept
Definition: Display.h:226
const Vec2 & GetUiScreenSize() const noexcept
Retrieve the dimensions of the screen, in UI coordinates.
Definition: Display.h:251
virtual ~Display()
Definition: Display.h:91
Display()
Definition: Display.h:89
Styles styles
Definition: Display.h:264
uiLayoutFlags_t AddUiLayoutFlags(uiLayoutFlags_t flags) noexcept
Combine the current UI layout flags with new flags.
Definition: Display.h:219
displayConfigChangedSignal_t & GetDisplayConfigChangedSignal()
Definition: Display.h:154
Vec2 AddUiOrigin(const Vec2 &vec) noexcept
Shift the current UI origin coordinates by an offset.
Definition: Display.h:198
Definition: Announcement.h:24
const Vec2 & GetUiOffset() const noexcept
Definition: Display.h:227
void SetUiOrigin(const Vec2 &vec) noexcept
Explicitly set the UI origin coordinates.
Definition: Display.h:190
Use absolute (screen-space) coordinates.
Definition: UiLayoutFlags.h:49
double uiScale
Definition: Display.h:256
void SetUiLayoutFlags(uiLayoutFlags_t flags) noexcept
Explicitly set the current UI layout flags.
Definition: Display.h:211