ShishGL  1.0
A simple modular cross-platform graphics library
IPlatform.hpp
Go to the documentation of this file.
1 /*============================================================================*/
2 #ifndef SHISHGL_IPLATFORM_HPP
3 #define SHISHGL_IPLATFORM_HPP
4 /*============================================================================*/
5 #include <string_view>
6 
7 #include "Frame.hpp"
8 #include "Color.hpp"
9 #include "ResourceManager.hpp"
10 /*============================================================================*/
11 namespace Sh {
12 
13  class IPlatform {
14  public:
15 
16  virtual bool isRunning() = 0;
17 
18  /* Input */
19  /*--------------------------------------------------------------------*/
21  /*--------------------------------------------------------------------*/
22 
23  /* View */
24  /*--------------------------------------------------------------------*/
25  virtual void setViewport(const Frame& frame) = 0;
26 
27  virtual const Vector2<double>& getDisplaySize() = 0;
28  /*--------------------------------------------------------------------*/
29 
30  /* Draw */
31  /*--------------------------------------------------------------------*/
32  class IContext {
33  public:
34 
35  IContext() = default;
36 
37  virtual void update(const Color* data) = 0;
38 
39  virtual void updateAt(const Vector2<size_t>& pos,
40  const Color& color) = 0;
41 
42  virtual ~IContext() = default;
43 
44  };
45 
46  virtual IContext* createContext(const Vector2<size_t>& size,
47  const Color& color) = 0;
48 
49  virtual IContext* loadContextFromImage(const std::string_view& filename) = 0;
50 
51  virtual void saveContextAsImage(IContext* context, const std::string_view& filename) = 0;
52 
53  /*--------------------------------------------------------------------*/
54 
55  virtual void setColor(const Color& color) = 0;
56 
57  virtual void setTexture(const ResourceManager::Resource& texture) = 0;
58 
59  virtual void drawPoint(const Vector2<double>& pos) = 0;
60 
61  virtual void drawLine(const Vector2<double>& start,
62  const Vector2<double>& end) = 0;
63 
64  virtual void drawRectangle(const Vector2<double>& pos,
65  const Vector2<double>& size) = 0;
66 
67  virtual void drawCircle(const Vector2<double>& pos,
68  const double& radius) = 0;
69  /*--------------------------------------------------------------------*/
70 
71  /* Image */
72  /*--------------------------------------------------------------------*/
73  virtual void displayContext(const IContext* context,
74  const Vector2<double>& position) = 0;
75  /*--------------------------------------------------------------------*/
76 
77  /* Text */
78  /*--------------------------------------------------------------------*/
79  virtual void setFont(const ResourceManager::Resource& font) = 0;
80 
81  virtual void setFontSize(const size_t& font_size) = 0;
82 
83  enum Align {
86  RIGHT
87  };
88 
89  virtual void displayText(const std::string_view& text,
90  const Frame& frame,
91  Align align) = 0;
92  /*--------------------------------------------------------------------*/
93 
94  virtual ~IPlatform() = default;
95 
96  protected:
97 
98  friend class RenderSystem;
99  friend class WindowManager;
100  friend class CoreApplication;
101 
102  IPlatform() = default;
103 
104  /* Essential */
105  /*--------------------------------------------------------------------*/
106  virtual bool initDisplay(int* argc_ptr, char* argv[]) = 0;
107 
108  virtual bool closeDisplay() = 0;
109  /*--------------------------------------------------------------------*/
110 
111  /* Rendering */
112  /*--------------------------------------------------------------------*/
113  virtual void clear(const Color& color) = 0;
114 
115  virtual void display() = 0;
116  /*--------------------------------------------------------------------*/
117 
118  /* Events */
119  /*--------------------------------------------------------------------*/
120  virtual bool pollEvent() = 0;
121  /*--------------------------------------------------------------------*/
122 
123  };
124 
125 }
126 
127 /*============================================================================*/
128 #endif //SHISHGL_IPLATFORM_HPP
129 /*============================================================================*/
Sh::IPlatform::createContext
virtual IContext * createContext(const Vector2< size_t > &size, const Color &color)=0
Sh::IPlatform::pollEvent
virtual bool pollEvent()=0
Sh::RenderSystem
Definition: RenderSystem.hpp:9
Sh::IPlatform::IContext::~IContext
virtual ~IContext()=default
Sh::WindowManager
Definition: WindowManager.hpp:13
Sh::IPlatform::RIGHT
@ RIGHT
Definition: IPlatform.hpp:86
Sh::IPlatform::Align
Align
Definition: IPlatform.hpp:83
Sh::CoreApplication
Definition: CoreApplication.hpp:15
Sh::IPlatform::displayContext
virtual void displayContext(const IContext *context, const Vector2< double > &position)=0
prettify_colors.text
text
Definition: prettify_colors.py:6
Sh::Frame
Definition: Frame.hpp:9
Sh::Vector2< double >
Sh::IPlatform::CENTER
@ CENTER
Definition: IPlatform.hpp:85
Sh::IPlatform::setTexture
virtual void setTexture(const ResourceManager::Resource &texture)=0
Sh::IPlatform::setViewport
virtual void setViewport(const Frame &frame)=0
Sh::IPlatform::isRunning
virtual bool isRunning()=0
Sh::IPlatform::getMousePos
virtual Vector2< double > getMousePos()=0
Sh::IPlatform::setFont
virtual void setFont(const ResourceManager::Resource &font)=0
Sh::IPlatform::getDisplaySize
virtual const Vector2< double > & getDisplaySize()=0
Sh::IPlatform::drawPoint
virtual void drawPoint(const Vector2< double > &pos)=0
Sh::IPlatform::drawLine
virtual void drawLine(const Vector2< double > &start, const Vector2< double > &end)=0
Sh::IPlatform::setColor
virtual void setColor(const Color &color)=0
Sh::IPlatform::IPlatform
IPlatform()=default
ResourceManager.hpp
Sh::IPlatform::IContext::updateAt
virtual void updateAt(const Vector2< size_t > &pos, const Color &color)=0
Sh::IPlatform::LEFT
@ LEFT
Definition: IPlatform.hpp:84
Sh::IPlatform::drawCircle
virtual void drawCircle(const Vector2< double > &pos, const double &radius)=0
Sh
Definition: CoreApplication.hpp:10
Sh::IPlatform::closeDisplay
virtual bool closeDisplay()=0
Sh::IPlatform::saveContextAsImage
virtual void saveContextAsImage(IContext *context, const std::string_view &filename)=0
Sh::IPlatform::clear
virtual void clear(const Color &color)=0
Frame.hpp
Sh::IPlatform
Definition: IPlatform.hpp:13
Sh::Color
Definition: Color.hpp:9
Sh::IPlatform::drawRectangle
virtual void drawRectangle(const Vector2< double > &pos, const Vector2< double > &size)=0
Sh::IPlatform::displayText
virtual void displayText(const std::string_view &text, const Frame &frame, Align align)=0
Sh::IPlatform::IContext::IContext
IContext()=default
Sh::ResourceManager::Resource
Definition: ResourceManager.hpp:14
Sh::IPlatform::setFontSize
virtual void setFontSize(const size_t &font_size)=0
Color.hpp
Sh::IPlatform::display
virtual void display()=0
Sh::IPlatform::IContext
Definition: IPlatform.hpp:32
Sh::IPlatform::IContext::update
virtual void update(const Color *data)=0
Sh::IPlatform::~IPlatform
virtual ~IPlatform()=default
Sh::IPlatform::initDisplay
virtual bool initDisplay(int *argc_ptr, char *argv[])=0
Sh::IPlatform::loadContextFromImage
virtual IContext * loadContextFromImage(const std::string_view &filename)=0