rolmodl
C++ API for the Simple Directmedia Library 2 (SDL2)
Geom.hpp
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "forwarddecl/Geom.hpp"
9 
11 namespace rolmodl {
13  namespace geom {}
14 }
15 namespace rolmodl::geom {
18  struct Pos {
19  public:
20  int x, y;
21 
22  private:
23  };
31  struct Size {
32  public:
33  int w, h;
34 
35  private:
36  };
37 
41  struct XYFloats {
42  public:
43  float x, y;
44 
45  private:
46  };
49  struct XYInt32 {
50  public:
51  int32_t x, y;
52 
53  private:
54  };
55 
59  struct RectWH {
60  public:
61  int x, y, w, h;
62 
65  constexpr RectWH(const int argX, const int argY, const int argW, const int argH) noexcept :
66  x(argX), y(argY), w(argW), h(argH)
67  {}
69  constexpr explicit RectWH(const SDL_Rect r) noexcept :
70  x(r.x), y(r.y), w(r.w), h(r.h)
71  {}
72 
74  constexpr RectXY xy() const noexcept;
76  constexpr SDL_Rect sdl() const noexcept {
77  return SDL_Rect{x, y, w, h};
78  }
79 
80  private:
81  };
87  struct RectXY {
88  public:
89  int x, y, x1, y1;
90 
93  constexpr RectXY(const int argX, const int argY, const int argX1, const int argY1) noexcept :
94  x(argX), y(argY), x1(argX1), y1(argY1)
95  {}
97  constexpr explicit RectXY(const SDL_Rect r) noexcept :
98  RectXY(RectWH(r).xy())
99  {}
100 
102  constexpr RectWH wh() const noexcept;
104  constexpr SDL_Rect sdl() const noexcept {
105  return wh().sdl();
106  }
107 
108  private:
109  };
110 
111  constexpr RectXY RectWH::xy() const noexcept {
112  return RectXY(x, y, x+w, y+h);
113  }
114  constexpr RectWH RectXY::wh() const noexcept {
115  return RectWH(x, y, x1-x, y1-y);
116  }
117 }
rolmodl::geom::XYFloats
float point data type. Used by touch events.
Definition: Geom.hpp:41
rolmodl::geom::RectWH::sdl
constexpr SDL_Rect sdl() const noexcept
Convert to an SDL_Rect.
Definition: Geom.hpp:76
rolmodl::geom::XYInt32
int32 point data type. The value is in pixels. Used by mouse events.
Definition: Geom.hpp:49
rolmodl::geom::Size
int dimensions data type. The value is in pixels. Semantically different from rolmodl::geom::Pos.
Definition: Geom.hpp:31
rolmodl::geom::RectWH::RectWH
constexpr RectWH(const SDL_Rect r) noexcept
Initialize from the given SDL_Rect.
Definition: Geom.hpp:69
rolmodl::geom::RectWH::xy
constexpr RectXY xy() const noexcept
Convert to an equivalent rolmodl::geom::RectXY.
Definition: Geom.hpp:111
rolmodl::geom::RectWH::RectWH
constexpr RectWH(const int argX, const int argY, const int argW, const int argH) noexcept
Initialize with the given top left corner x and y, width, and height.
Definition: Geom.hpp:65
rolmodl::geom::RectXY
Rectangle represented by its top left corner coordinates and its bottom right corner coordinates.
Definition: Geom.hpp:87
rolmodl::geom::RectWH
Rectangle represented by its top left corner coordinates, width, and height.
Definition: Geom.hpp:59
rolmodl::geom::RectXY::wh
constexpr RectWH wh() const noexcept
Convert to an equivalent rolmodl::geom::RectWH.
Definition: Geom.hpp:114
rolmodl
Main namespace.
Definition: Base.cpp:7
rolmodl::geom::RectXY::RectXY
constexpr RectXY(const int argX, const int argY, const int argX1, const int argY1) noexcept
Initialize with the given top left corner x and y, and the bottom right corner x and y.
Definition: Geom.hpp:93
rolmodl::geom
Geometry structures.
Definition: Geom.hpp:7
rolmodl::geom::RectXY::sdl
constexpr SDL_Rect sdl() const noexcept
Convert to an SDL_Rect width-height rectangle.
Definition: Geom.hpp:104
rolmodl::geom::Pos
int point data type. The value is in pixels. Semantically different from rolmodl::geom::Size.
Definition: Geom.hpp:18
rolmodl::geom::RectXY::RectXY
constexpr RectXY(const SDL_Rect r) noexcept
Initialize from the given SDL_Rect converted from a width-height rectangle.
Definition: Geom.hpp:97