View.h
Go to the documentation of this file.
1 #ifndef B_VIEW_H
2 #define B_VIEW_H
3 
4 #include "OSdetect.h"
5 #include <memory>
6 #include "Renderer_GL.h"
7 #include "Logger.h"
8 #include "Configuration.h"
9 
10 #ifdef __OBJC__
11 #import "../os_specific/ios/BView.h"
12 #endif
13 
21 class View
22 {
23 public:
24 
25 #ifdef B_OS_IOS
26  /* Typedefs */
27  typedef int GLFWwindow;
28 #endif
29 #ifndef __OBJC__
30  typedef int UIView;
31  typedef int BView;
32 #endif
33 
34  /* Functions */
35 
38  View();
39 
42  virtual ~View();
43 
47  bool initView(std::string windowTitle = bRenderer::DEFAULT_WINDOW_TITLE());
48 
53  bool initView(bool fullscreen, std::string windowTitle = bRenderer::DEFAULT_WINDOW_TITLE());
54 
61  bool initView(GLint width, GLint height, bool fullscreen = false, std::string windowTitle = bRenderer::DEFAULT_WINDOW_TITLE());
62 
65  void terminateView();
66 
69  bool isInitialized();
70 
73  bool isRunning();
74 
77  bool isFullscreen();
78 
81  GLint getWidth();
82 
85  GLint getHeight();
86 
91  void getSize(GLint* width, GLint* height);
92 
95  static GLint getScreenWidth();
96 
99  static GLint getScreenHeight();
100 
105  static void getScreenSize(GLint* width, GLint* height);
106 
109  GLint getViewportWidth();
110 
113  GLint getViewportHeight();
114 
119  void getViewportSize(GLint* width, GLint* height);
120 
123  GLfloat getAspectRatio();
124 
127  GLint getPositionX();
128 
131  GLint getPositionY();
132 
137  void getPosition(GLint* x, GLint* y);
138 
145  GLFWwindow* getWindow();
146 
149  BView* getUIView();
150 
154  void attachToUIView(UIView* view);
155 
159  void setFullscreen(bool fullscreen);
160 
164  void setWidth(GLint width);
165 
169  void setHeight(GLint height);
170 
175  void setSize(GLint width, GLint height);
176 
181  void setViewportSize(GLint width, GLint height);
182 
187  void setPosition(GLint x, GLint y);
188 
191  void setContextCurrent();
192 
195  void bindFramebuffer();
196 
199  static void clearScreen();
200 
203  void presentBuffer();
204 
205 private:
206  /* Functions */
207 
213  static void windowSizeChanged(GLFWwindow* window, int width, int height);
214 
215  /* Variables */
216 
217  GLFWwindow *_window = nullptr;
218  BView *_view = nullptr;
219 
220  bool _initialized = false;
221  bool _fullscreen = false;
222 
223 };
224 
225 typedef std::shared_ptr< View > ViewPtr;
226 
227 
228 #endif /* defined(B_VIEW_H) */
GLint getHeight()
Returns the height of the view in pixels.
void terminateView()
Terminate the view.
int UIView
Definition: View.h:30
void attachToUIView(UIView *view)
Attaches (adds as a subview) the underlying UIView to a UIView of your choosing.
virtual ~View()
Virtual destructor.
void setWidth(GLint width)
Sets the width of the view in pixels.
GLint getPositionX()
Returns the x position of the view in pixels.
bool isFullscreen()
Returns true if the view runs in full screen mode.
void setSize(GLint width, GLint height)
Sets the size of the view in pixels.
GLint getPositionY()
Returns the y position of the view in pixels.
static GLint getScreenWidth()
Returns the width of the screen in pixels.
std::shared_ptr< View > ViewPtr
Definition: View.h:225
void setHeight(GLint height)
Sets the height of the view in pixels.
GLint getViewportHeight()
Returns the height of the OpenGL viewport in pixels.
void setPosition(GLint x, GLint y)
Sets the position of the upper left corner of the view.
void getViewportSize(GLint *width, GLint *height)
Gets the size of the OpenGL viewport in pixels.
void setViewportSize(GLint width, GLint height)
Sets the size of the OpenGL viewport in pixels.
bool isRunning()
Returns true if the view is running.
void setFullscreen(bool fullscreen)
Set fullscreen mode.
void bindFramebuffer()
Bind the framebuffer (on iOS only)
int BView
Definition: View.h:31
static void getScreenSize(GLint *width, GLint *height)
Gets the size of the screen in pixels.
GLint getWidth()
Returns the width of the view in pixels.
bool isInitialized()
Returns true if the view has already been initialized.
void presentBuffer()
Displays the buffer to the screen.
GLFWwindow * getWindow()
Returns the GLFW window.
static GLint getScreenHeight()
Returns the height of the screen in pixels.
std::string DEFAULT_WINDOW_TITLE()
Definition: Configuration.cpp:37
View()
Constructor.
GLint getViewportWidth()
Returns the width of the OpenGL viewport in pixels.
void getPosition(GLint *x, GLint *y)
Gets the position of the upper left corner of the view.
GLfloat getAspectRatio()
Returns the aspect ratio of the view.
An abstraction of the view the scene is drawn into.
Definition: View.h:21
static void clearScreen()
Clears the screen.
void getSize(GLint *width, GLint *height)
Gets the size of the view in pixels.
void setContextCurrent()
Sets the context of this view to be current.
BView * getUIView()
Returns the UIView on iOS (only usable in Objective C)
bool initView(std::string windowTitle=bRenderer::DEFAULT_WINDOW_TITLE())
Do all necessary initializations for the view to be ready to run (returns true in the case of success...