Rose
AntiAliasedDrawing.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "Color.h"
11 #include "Math.h"
12 #include "Surface.h"
13 #include "Texture.h"
14 #include "Math.h"
15 #include "GraphicsModel.h"
16 
17 namespace rose {
18 
24  public:
29  enum DrawingType {
32  };
33 
34  protected:
35  DrawingType mDrawingType{SimpleLine};
36 
37  color::RGBA mColor{color::RGBA::OpaqueBlack};
38  int mWidth{1};
39  gm::Texture mTexture{};
40  Size mWidgetSize{};
41 
42  public:
43  AntiAliasedDrawing() = default;
44  ~AntiAliasedDrawing() = default;
45 
52  AntiAliasedDrawing(gm::Context &context, DrawingType drawingType);
53 
60  void setWidthColor(gm::Context &context, int width, color::RGBA rgba, Size& widgetSize);
61 
67  void setColor(gm::Context &context, color::RGBA rgba, Size& widgetSize) {
68  setWidthColor(context, mWidth, rgba, widgetSize);
69  }
70 
80  void drawLine(gm::Context &context, Position<float> p0, Position<float> p1, int interiorWidth = 0);
81 
89  template<typename T>
90  bool renderLine(gm::Context &context, Position<T> p0, Position<T> p1) {
91  switch (mDrawingType) {
92  case SimpleLine: {
93  gm::DrawColorGuard drawColorGuard{context, mColor};
94  if constexpr (std::is_integral_v<T>)
95  return SDL_RenderDrawLine(context.get(), p0.x, p0.y, p1.x, p1.y) == 0;
96  else
97  return SDL_RenderDrawLineF(context.get(), p0.x, p0.y, p1.x, p1.y) == 0;
98  }
99  case AntiAliased: {
100  if constexpr (std::is_integral_v<T>)
101  drawLine(context, p0.template as<float>(), p1.template as<float>(), mWidth);
102  else
103  drawLine(context, p0, p1, mWidth);
104  return true;
105  }
106  }
107  return false;
108  }
109  };
110 }
111 
void setWidthColor(gm::Context &context, int width, color::RGBA rgba, Size &widgetSize)
Set the width and colour of a line to be drawn.
Definition: AntiAliasedDrawing.cpp:16
void setColor(gm::Context &context, color::RGBA rgba, Size &widgetSize)
Set the colour of the line to be drawn.
Definition: AntiAliasedDrawing.h:67
Red Green Blue Alpha representation of a color.
Definition: Color.h:64
Definition: AntiAliasedDrawing.h:23
Simple lines, no anti-aliasing.
Definition: AntiAliasedDrawing.h:30
Modified Wu&#39;s algorithm anti-aliaseing.
Definition: AntiAliasedDrawing.h:31
Abstraction of SDL_Texture.
Definition: Texture.h:46
Context
Definition: GraphicsModel.h:76
Abstraction of the graphics model.
void drawLine(gm::Context &context, Position< float > p0, Position< float > p1, int interiorWidth=0)
Implement a modified Xiaolin Wu anti aliasing algorithm.
Definition: AntiAliasedDrawing.cpp:22
bool renderLine(gm::Context &context, Position< T > p0, Position< T > p1)
Draw an anti-aliased line.
Definition: AntiAliasedDrawing.h:90
Store the current draw color replacing it with a new draw color.
Definition: GraphicsModel.h:292
A size in integer dimensions.
Definition: Types.h:230
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
DrawingType
The drawing style used by the drawing engine.
Definition: AntiAliasedDrawing.h:29
auto get() const
Get an opaque pointer for API calls.
Definition: GraphicsModel.h:118