All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LabelRenderer.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Labels.h"
7 #include "Text.h"
8 #include "ShapedGlyph.h"
9 #include "DebugRendering.h"
10 #include "Geometry.h"
11 #include "Camera.h"
12 #include "StencilMapLayerMask.h"
13 #include "LabelStyle.h"
14 #include "LayerIds.h"
15 #include "Rendering.h"
16 #include "Icons.h"
17 
18 #include <vector>
19 
20 
21 
22 namespace Eegeo
23 {
24  namespace Labels
25  {
26  namespace DebugDrawMode
27  {
28  enum Type
29  {
30  DrawAABB,
31  DrawOBB,
32  DrawAnchor,
33  DrawConstraints,
34  IdentifyStyle
35  };
36 
37  inline u32 ToFlag(Type debugDrawMode)
38  {
39  return 1 << debugDrawMode;
40  }
41  };
42 
44  {
45  public:
46  virtual ~ILabelRenderer() {}
47 
48  virtual void Draw() = 0;
49 
50  virtual void DrawLabelDebug(const Camera::RenderCamera& renderCamera, const LabelView& labelView, u32 debugDrawModeFlags) = 0;
51 
52  virtual std::vector<const LabelView*>& GetViewList() = 0;
53  };
54 
56  {
57  public:
58  LabelRenderer(Text::IScreenTextRenderer& screenTextRenderer,
59  Text::IWorldTextRenderer& worldTextRenderer,
60  Icons::IScreenIconRenderer& screenIconRenderer,
61  Icons::IWorldIconRenderer& worldIconRenderer,
62  DebugRendering::DebugRenderer& debugRenderer,
63  const Rendering::EnvironmentFlatteningService& environmentFlatteningService,
64  u32 mapLayersStencilMask,
65  const Rendering::LayerIds::Values renderLayer
66  );
67 
68  void Draw();
69 
70  void DrawLabelDebug(const Camera::RenderCamera& renderCamera, const LabelView& labelView, u32 debugDrawModeFlags);
71 
72  std::vector<const LabelView*>& GetViewList() { return m_viewList; }
73  private:
74 
75  enum FlattenMode
76  {
77  NotFlattened,
78  Transitioning,
79  Flattened
80  };
81 
82  void DrawLabel(const LabelView& labelView, FlattenMode flattenMode, float flattenParam);
83  void DrawTextComponent(const LabelView& labelView, FlattenMode flattenMode, float flattenParam, bool worldSpace, bool labelStyleChanged);
84  void DrawIconComponent(const LabelView& labelView, FlattenMode flattenMode, float flattenParam, bool worldSpace, bool labelStyleChanged, bool iconScaleChanged);
85 
86  void DebugDrawOBB(const Geometry::OrientedBox2& obb);
87  void DebugDrawAABB(const Geometry::AxisAlignedBox2& aabb, const v4& color);
88  void DebugDrawPoint(const v2& p);
89  void DebugDrawConstraints(const Camera::RenderCamera& renderCamera, const LabelView& labelView);
90 
91  StencilMode::Type CalcStencilMode(const LabelStyle& labelStyle, FlattenMode flattenMode);
92  v4 CalcMaskedColor(const v4& nonMaskedColor, const v4& maskedColor, StencilMode::Type stencilMode, FlattenMode flattenMode, float flattenParam) const;
93  float CalcIconAlpha(float fadeParam, float styleAlpha, float maskedStyleAlpha, StencilMode::Type stencilMode, FlattenMode flattenMode, float flattenParam) const;
94 
95  Text::IScreenTextRenderer& m_screenTextRenderer;
96  Text::IWorldTextRenderer& m_worldTextRenderer;
97 
98  Icons::IScreenIconRenderer& m_screenIconRenderer;
99  Icons::IWorldIconRenderer& m_worldIconRenderer;
100 
101  DebugRendering::DebugRenderer& m_debugRenderer;
102  const Rendering::EnvironmentFlatteningService& m_environmentFlatteningService;
103 
104  std::vector<const LabelView*> m_viewList;
105 
106  const LabelStyle* m_pPrevStyleScreen;
107  const LabelStyle* m_pPrevStyleWorld;
108  float m_prevIconScale;
109 
110  const u32 m_mapLayersStencilMask;
111  const Rendering::LayerIds::Values m_renderLayer;
112  bool m_needToFlushIconRenderer;
113  };
114  }
115 }