HoverRace  2.0
SdlBoxView.h
Go to the documentation of this file.
1 
2 // SdlBoxView.h
3 //
4 // Copyright (c) 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 "SdlView.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  namespace SDL {
39  class SdlDisplay;
40  }
41  }
42 }
43 
44 namespace HoverRace {
45 namespace Display {
46 namespace SDL {
47 
52 template<class T>
53 class MR_DllDeclare SdlBoxView : public SdlView<T>
54 {
55  using SUPER = SdlView<T>;
56 
57 public:
58  SdlBoxView(SdlDisplay &disp, T &model) :
59  SUPER(disp, model), screenPos(0, 0), screenSize(0, 0) { }
60  virtual ~SdlBoxView() { }
61 
62 public:
63  Vec2 GetScreenPos() const override { return screenPos; }
64  Vec2 GetScreenSize() const override { return screenSize; }
65 
66 protected:
71  {
72  const Vec2 &size = this->model.GetSize();
73  double w = size.x;
74  double h = size.y;
75 
76  screenPos = this->display.LayoutUiPosition(
77  this->model.GetAlignedPos(w, h),
78  this->model.GetLayoutFlags());
79 
80  if (!this->model.IsLayoutUnscaled()) {
81  double uiScale = this->display.GetUiScale();
82  w *= uiScale;
83  h *= uiScale;
84  }
85  screenSize.x = w;
86  screenSize.y = h;
87  }
88 
89 protected:
92 };
93 
94 } // namespace SDL
95 } // namespace Display
96 } // namespace HoverRace
97 
98 #undef MR_DllDeclare
Vec2 GetScreenPos() const override
Retrieve the screen-space position, if available.
Definition: SdlBoxView.h:63
Vec2 screenSize
Definition: SdlBoxView.h:91
void CalcScreenBounds()
Update the screen-space bounds from the UI-space bounds.
Definition: SdlBoxView.h:70
virtual ~SdlBoxView()
Definition: SdlBoxView.h:60
double y
Definition: Vec.h:45
Vec2 screenPos
Definition: SdlBoxView.h:90
Base class for FillBox views.
Definition: SdlBoxView.h:53
Definition: Vec.h:38
double x
Definition: Vec.h:44
SdlBoxView(SdlDisplay &disp, T &model)
Definition: SdlBoxView.h:58
Vec2 GetScreenSize() const override
Retrieve the screen-space size, if available.
Definition: SdlBoxView.h:64
Definition: Announcement.h:24
#define MR_DllDeclare
Definition: SdlBoxView.h:33
Base class for views that use SDL for rendering.
Definition: SdlView.h:54
SDL-based software rendering.
Definition: SdlDisplay.h:60