Screen.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. //! Specifies whether it is checked before drawing if the image differs
  108. //! from the last one (set by default) \param tr 1 if drawing should
  109. //! only occur when necessary
  110. DLLEXPORT virtual void setTestRend(bool tr);
  111. //! Specifies whether 2D GUI drawings should be drawn
  112. //! (set by default) \param rO 1 if drawings should be drawn
  113. DLLEXPORT virtual void setRenderDrawables(bool rO);
  114. //! Specifies whether a drawing should be drawn above all other drawings
  115. //! (not set by default) \param onTop 1 if a drawing should be drawn
  116. //! above everything
  117. DLLEXPORT virtual void setOnTop(bool onTop);
  118. //! Sets the drawing to be drawn above everything, if setOnTop(1) was
  119. //! set
  120. //! \param obj The drawing
  121. DLLEXPORT virtual void setOnTopDrawable(Drawable* obj);
  122. //! Sets a color that is alpha-blended over the entire image after
  123. //! drawing, if setOnTop(1) was set. The drawing set with
  124. //! setOnTopDrawable() is not affected \param f The color in A8R8G8B8
  125. //! format
  126. DLLEXPORT virtual void setdeckColor(int f);
  127. //! Adds a drawing to the image that is always drawn when
  128. //! setRenderDrawables(1) was set. \param obj The drawing
  129. DLLEXPORT virtual void addMember(Drawable* obj);
  130. //! Removes a drawing from the image. Must not be called while
  131. //! doMouseEvent(), doKeyboardEvent(), tick() or render() is
  132. //! being called. \param obj The drawing (without increased reference
  133. //! counter)
  134. DLLEXPORT virtual void removeMember(Drawable* zObj);
  135. //! Draws an image and presents it on the screen
  136. DLLEXPORT virtual void render() = 0;
  137. //! Sets the color used to fill the image before drawing, if
  138. //! setFill(1) was set \param f The color in A8R8G8B8 format
  139. DLLEXPORT virtual void setFillColor(int f);
  140. //! Processes the time elapsed since the last call of this function.
  141. //! Calls the tick functions of all drawings in the image
  142. //! \param tickval The elapsed time in seconds
  143. DLLEXPORT virtual void tick(double tickval);
  144. //! Processes a mouse event. Called automatically by the framework.
  145. //! Passes the event to all drawings in the image
  146. //! \param me The event
  147. DLLEXPORT virtual void doMouseEvent(MouseEvent& me);
  148. //! Processes a keyboard event. Called automatically by the framework.
  149. //! Passes the event to all drawings in the image
  150. //! \param te The event
  151. DLLEXPORT virtual void doKeyboardEvent(KeyboardEvent& te);
  152. //! Adds a tooltip.
  153. //! \param tip The tooltip
  154. DLLEXPORT virtual void addToolTip(ToolTip* tip);
  155. //! Returns the image into which the 2D GUI drawings of the framework
  156. //! are drawn
  157. DLLEXPORT virtual Image* getRenderImage() const;
  158. //! Returns the image without increased reference counter into which
  159. //! the 2D GUI drawings of the framework are drawn
  160. DLLEXPORT virtual Image* zRenderImage() const;
  161. //! Returns an array of 2D GUI drawings in the image
  162. DLLEXPORT virtual ArrayIterator<Drawable*> getMembers() const;
  163. //! Returns the color in A8R8G8B8 format used to fill the image
  164. //! before drawing
  165. DLLEXPORT virtual int getFillColor() const;
  166. //! Returns whether fullscreen mode is active
  167. DLLEXPORT virtual bool isFullscreen() const;
  168. //! Returns the resolution in pixels at which drawing occurs
  169. DLLEXPORT virtual const Point getBackBufferSize() const;
  170. //! Waits until the current image has finished drawing
  171. DLLEXPORT virtual void waitForRendering() const;
  172. //! Returns the time in seconds needed to draw the last image
  173. DLLEXPORT virtual double getRenderZeit() const;
  174. //! Returns the graphics API (without increased reference counter)
  175. DLLEXPORT GraphicsApi* zGraphicsApi() const;
  176. //! Returns the graphics API
  177. DLLEXPORT GraphicsApi* getGraphicsApi() const;
  178. };
  179. #ifdef WIN32
  180. //! This class manages the image on the screen without 3D elements
  181. class Screen2D : public Screen
  182. {
  183. public:
  184. //! Constructor
  185. //! \param fenster The window whose content should be managed
  186. DLLEXPORT Screen2D(NativeWindow* fenster);
  187. //! Destructor
  188. DLLEXPORT virtual ~Screen2D();
  189. //! Draws an image and presents it on the screen
  190. DLLEXPORT virtual void render();
  191. };
  192. //! This class manages the image on the screen with 3D elements
  193. class Screen3D : public Screen
  194. {
  195. private:
  196. RCArray<Cam3D>* kameras;
  197. bool rend3D;
  198. public:
  199. //! Constructor
  200. //! \param fenster The window whose content should be managed
  201. DLLEXPORT Screen3D(NativeWindow* fenster);
  202. DLLEXPORT Screen3D(NativeWindow* fenster, GraphicApiType apiTyp);
  203. DLLEXPORT Screen3D(NativeWindow* fenster, GraphicsApi* api);
  204. //! Destructor
  205. DLLEXPORT virtual ~Screen3D();
  206. //! Adds a camera to the screen
  207. //! \param obj The camera
  208. DLLEXPORT void addKamera(Cam3D* obj);
  209. //! Removes a camera from the screen
  210. DLLEXPORT void removeKamera(Cam3D* zObj);
  211. //! Processes the time elapsed since the last call of this function.
  212. //! Calls the tick functions of all drawings and cameras in the image
  213. //! \param tickval The elapsed time in seconds
  214. DLLEXPORT void tick(double tickval);
  215. //! Processes a mouse event. Called automatically by the framework.
  216. //! Passes the event to all drawings and cameras in the image
  217. //! \param me The event
  218. DLLEXPORT void doMouseEvent(MouseEvent& me);
  219. //! Processes a keyboard event. Called automatically by the framework.
  220. //! Passes the event to all drawings and cameras in the image
  221. //! \param te The event
  222. DLLEXPORT void doKeyboardEvent(KeyboardEvent& te);
  223. //! Draws an image and presents it on the screen
  224. DLLEXPORT void render();
  225. };
  226. //! Finds the position and resolution of a monitor
  227. //! \param id The ID of the monitor. If the monitor was not found,
  228. //! the exists flag of the returned Monitor structure is 0
  229. DLLEXPORT Monitor getMonitor(int id);
  230. #endif
  231. } // namespace Framework
  232. #endif