Screen.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #ifndef Screen_H
  2. #define Screen_H
  3. #include <queue>
  4. #include "Array.h"
  5. #include "Critical.h"
  6. #include "KeyboardEvent.h"
  7. #include "MouseEvent.h"
  8. #include "Point.h"
  9. //! DirectX 11 Types
  10. struct ID3D11Device;
  11. struct ID3D11DeviceContext;
  12. struct IDXGISwapChain;
  13. struct ID3D11Texture2D;
  14. struct ID3D11SamplerState;
  15. struct ID3D11ShaderResourceView;
  16. struct ID3D11RenderTargetView;
  17. struct ID3D11DepthStencilView;
  18. struct ID3D11DepthStencilState;
  19. struct ID3D11RasterizerState;
  20. struct ID3D11BlendState;
  21. struct D3D11_VIEWPORT;
  22. //! DirectX 9 Types
  23. struct IDirect3D9;
  24. struct IDirect3DDevice9;
  25. struct IDirect3DSurface9;
  26. struct _D3DLOCKED_RECT;
  27. namespace Framework
  28. {
  29. class Image; //! Image.h
  30. class NativeWindow; //! Window.h
  31. class Screen; //! from this file
  32. class Drawable; //! Drawing.h
  33. class Drawable3D; //! Drawing3D.h
  34. class Timer; //! Time.h
  35. struct MouseEvent; //! MouseEvent.h
  36. struct KeyboardEvent; //! KeyboardEvent.h
  37. class ToolTip; //! Tooltip.h
  38. class PixelShader; //! Shader.h
  39. class VertexShader; //! Shader.h
  40. class Cam3D; //! Camera3D.h
  41. class Render3D; //! Render3D.h
  42. class DXVertexBuffer; //! DXBuffer.h
  43. class DXIndexBuffer; //! DXBuffer.h
  44. class Texture; //! Texture.h
  45. class TextureModel; //! TextureModel.h
  46. class GraphicsApi; //! GraphicsApi.h
  47. class DirectX9; //! GraphicsApi.h
  48. enum GraphicApiType
  49. {
  50. NOT_SUPPORTED, //! no graphic api supported
  51. DIRECTX9, //! only 2d
  52. DIRECTX11, //! 3d simple phong model without shadows
  53. DIRECTX12 //! 3d phong model with raytraycing
  54. };
  55. //! A structure containing information about a monitor
  56. struct Monitor
  57. {
  58. int x, y, width,
  59. height; //! Coordinates of the monitor and its resolution
  60. bool exists; //! Stores whether the monitor really exists
  61. Text name;
  62. };
  63. //! This class manages the image on the screen
  64. class Screen : public virtual ReferenceCounter
  65. {
  66. protected:
  67. GraphicsApi* api;
  68. NativeWindow* fenster;
  69. RCArray<Drawable>* members;
  70. int fillColor;
  71. int deckColor;
  72. Drawable* onTop;
  73. bool renderOnTop;
  74. bool renderDrawables;
  75. bool rendering;
  76. Timer* renderTime;
  77. ReadWriteLock rwLock;
  78. ReadWriteLock actionsLock;
  79. RCArray<ToolTip>* tips;
  80. bool testRend;
  81. bool fill;
  82. bool rend;
  83. bool handleUserInputsOnTick;
  84. Critical queueCs;
  85. Array<MouseEvent> meQueue;
  86. Array<KeyboardEvent> teQueue;
  87. std::queue<std::function<void()>> actions;
  88. public:
  89. //! Constructor
  90. //! \param fenster The window whose content should be managed
  91. DLLEXPORT Screen(NativeWindow* fenster);
  92. //! Destructor
  93. DLLEXPORT virtual ~Screen();
  94. //! Passes a void function pointer to an action that should be executed
  95. //! once by the main thread. Called at the beginning of tick()
  96. DLLEXPORT void postAction(std::function<void()> action);
  97. //! if set to true, then mouse and keyboard events are added to a queue
  98. //! and will be handled at the next call of tick. Otherwise they are
  99. //! handled by the calling thread after waiting for a lock between the
  100. //! rendering and ticks. This can lead to longer waiting times since the
  101. //! lock can not allways be aquired betwean two frames
  102. DLLEXPORT void setHandleUserInputsOnTick(bool handleOnTick);
  103. //! Specifies whether the screen is refilled with a color after each
  104. //! frame (set by default) \param f 1 if the image should be reset
  105. //! before drawing
  106. DLLEXPORT virtual void setFill(bool f);
  107. //! Updates the objects that manage the graphics card
  108. DLLEXPORT virtual void update();
  109. //! Specifies whether it is checked before drawing if the image differs
  110. //! from the last one (set by default) \param tr 1 if drawing should
  111. //! only occur when necessary
  112. DLLEXPORT virtual void setTestRend(bool tr);
  113. //! Specifies whether 2D GUI drawings should be drawn
  114. //! (set by default) \param rO 1 if drawings should be drawn
  115. DLLEXPORT virtual void setRenderDrawables(bool rO);
  116. //! Specifies whether a drawing should be drawn above all other drawings
  117. //! (not set by default) \param onTop 1 if a drawing should be drawn
  118. //! above everything
  119. DLLEXPORT virtual void setOnTop(bool onTop);
  120. //! Sets the drawing to be drawn above everything, if setOnTop(1) was
  121. //! set
  122. //! \param obj The drawing
  123. DLLEXPORT virtual void setOnTopDrawable(Drawable* obj);
  124. //! Sets a color that is alpha-blended over the entire image after
  125. //! drawing, if setOnTop(1) was set. The drawing set with
  126. //! setOnTopDrawable() is not affected \param f The color in A8R8G8B8
  127. //! format
  128. DLLEXPORT virtual void setdeckColor(int f);
  129. //! Adds a drawing to the image that is always drawn when
  130. //! setRenderDrawables(1) was set. \param obj The drawing
  131. DLLEXPORT virtual void addMember(Drawable* obj);
  132. //! Removes a drawing from the image. Must not be called while
  133. //! doMouseEvent(), doKeyboardEvent(), tick() or render() is
  134. //! being called. \param obj The drawing (without increased reference
  135. //! counter)
  136. DLLEXPORT virtual void removeMember(Drawable* zObj);
  137. //! Draws an image and presents it on the screen
  138. DLLEXPORT virtual void render() = 0;
  139. //! Sets the color used to fill the image before drawing, if
  140. //! setFill(1) was set \param f The color in A8R8G8B8 format
  141. DLLEXPORT virtual void setFillColor(int f);
  142. //! Specifies whether the image should be presented in fullscreen mode.
  143. //! (not set by default) \param fullscreen 1 for fullscreen mode
  144. DLLEXPORT virtual void setFullscreen(bool fullscreen);
  145. //! Processes the time elapsed since the last call of this function.
  146. //! Calls the tick functions of all drawings in the image
  147. //! \param tickval The elapsed time in seconds
  148. DLLEXPORT virtual void tick(double tickval);
  149. //! Sets the resolution of the displayed image. It is automatically
  150. //! scaled by the graphics card to fill the window
  151. //! \param Width The width of the image in pixels
  152. //! \param height The height of the image in pixels
  153. DLLEXPORT virtual void setBackBufferSize(int Width, int height);
  154. //! Sets the resolution of the displayed image. It is automatically
  155. //! scaled by the graphics card to fill the window
  156. //! \param size The width and height in pixels
  157. DLLEXPORT virtual void setBackBufferSize(Point& size);
  158. //! Processes a mouse event. Called automatically by the framework.
  159. //! Passes the event to all drawings in the image
  160. //! \param me The event
  161. DLLEXPORT virtual void doMouseEvent(MouseEvent& me);
  162. //! Processes a keyboard event. Called automatically by the framework.
  163. //! Passes the event to all drawings in the image
  164. //! \param te The event
  165. DLLEXPORT virtual void doKeyboardEvent(KeyboardEvent& te);
  166. //! Adds a tooltip.
  167. //! \param tip The tooltip
  168. DLLEXPORT virtual void addToolTip(ToolTip* tip);
  169. //! Returns the image into which the 2D GUI drawings of the framework
  170. //! are drawn
  171. DLLEXPORT virtual Image* getRenderImage() const;
  172. //! Returns the image without increased reference counter into which
  173. //! the 2D GUI drawings of the framework are drawn
  174. DLLEXPORT virtual Image* zRenderImage() const;
  175. //! Returns an array of 2D GUI drawings in the image
  176. DLLEXPORT virtual ArrayIterator<Drawable*> getMembers() const;
  177. //! Returns the color in A8R8G8B8 format used to fill the image
  178. //! before drawing
  179. DLLEXPORT virtual int getFillColor() const;
  180. //! Returns whether fullscreen mode is active
  181. DLLEXPORT virtual bool isFullscreen() const;
  182. //! Returns the resolution in pixels at which drawing occurs
  183. DLLEXPORT virtual const Point getBackBufferSize() const;
  184. //! Waits until the current image has finished drawing
  185. DLLEXPORT virtual void waitForRendering() const;
  186. //! Returns the time in seconds needed to draw the last image
  187. DLLEXPORT virtual double getRenderZeit() const;
  188. //! Returns the graphics API (without increased reference counter)
  189. DLLEXPORT GraphicsApi* zGraphicsApi() const;
  190. //! Returns the graphics API
  191. DLLEXPORT GraphicsApi* getGraphicsApi() const;
  192. };
  193. #ifdef WIN32
  194. //! This class manages the image on the screen without 3D elements
  195. class Screen2D : public Screen
  196. {
  197. public:
  198. //! Constructor
  199. //! \param fenster The window whose content should be managed
  200. DLLEXPORT Screen2D(NativeWindow* fenster);
  201. //! Destructor
  202. DLLEXPORT virtual ~Screen2D();
  203. //! Draws an image and presents it on the screen
  204. DLLEXPORT virtual void render();
  205. };
  206. //! This class manages the image on the screen with 3D elements
  207. class Screen3D : public Screen
  208. {
  209. private:
  210. RCArray<Cam3D>* kameras;
  211. bool rend3D;
  212. public:
  213. //! Constructor
  214. //! \param fenster The window whose content should be managed
  215. DLLEXPORT Screen3D(NativeWindow* fenster);
  216. DLLEXPORT Screen3D(NativeWindow* fenster, GraphicApiType apiTyp);
  217. DLLEXPORT Screen3D(NativeWindow* fenster, GraphicsApi* api);
  218. //! Destructor
  219. DLLEXPORT virtual ~Screen3D();
  220. //! Adds a camera to the screen
  221. //! \param obj The camera
  222. DLLEXPORT void addKamera(Cam3D* obj);
  223. //! Removes a camera from the screen
  224. DLLEXPORT void removeKamera(Cam3D* zObj);
  225. //! Processes the time elapsed since the last call of this function.
  226. //! Calls the tick functions of all drawings and cameras in the image
  227. //! \param tickval The elapsed time in seconds
  228. DLLEXPORT void tick(double tickval);
  229. //! Processes a mouse event. Called automatically by the framework.
  230. //! Passes the event to all drawings and cameras in the image
  231. //! \param me The event
  232. DLLEXPORT void doMouseEvent(MouseEvent& me);
  233. //! Processes a keyboard event. Called automatically by the framework.
  234. //! Passes the event to all drawings and cameras in the image
  235. //! \param te The event
  236. DLLEXPORT void doKeyboardEvent(KeyboardEvent& te);
  237. //! Draws an image and presents it on the screen
  238. DLLEXPORT void render();
  239. };
  240. //! Finds the position and resolution of a monitor
  241. //! \param id The ID of the monitor. If the monitor was not found,
  242. //! the exists flag of the returned Monitor structure is 0
  243. DLLEXPORT Monitor getMonitor(int id);
  244. #endif
  245. } // namespace Framework
  246. #endif