Screen.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #ifndef Screen_H
  2. #define Screen_H
  3. #include <queue>
  4. #include "Array.h"
  5. #include "Critical.h"
  6. #include "MouseEvent.h"
  7. #include "Point.h"
  8. #include "KeyboardEvent.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 ZeitMesser; //! Time.h
  35. struct MausEreignis; //! MouseEvent.h
  36. struct TastaturEreignis; //! KeyboardEvent.h
  37. class ToolTip; //! Tooltip.h
  38. class PixelShader; //! Shader.h
  39. class VertexShader; //! Shader.h
  40. class Kam3D; //! Camera3D.h
  41. class Render3D; //! Render3D.h
  42. class DXVertexBuffer; //! DXBuffer.h
  43. class DXIndexBuffer; //! DXBuffer.h
  44. class Textur; //! Texture.h
  45. class TexturModel; //! 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, breite,
  59. height; //! Coordinates of the monitor and its resolution
  60. bool existiert; //! 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 deckFarbe;
  72. Drawable* onTop;
  73. bool renderOnTop;
  74. bool renderDrawables;
  75. bool rendering;
  76. ZeitMesser* renderZeit;
  77. Critical cs;
  78. RCArray<ToolTip>* tips;
  79. bool testRend;
  80. bool fill;
  81. bool rend;
  82. bool handleUserInputsOnTick;
  83. Critical queueCs;
  84. Array<MausEreignis> meQueue;
  85. Array<TastaturEreignis> teQueue;
  86. std::queue<std::function<void()>> actions;
  87. public:
  88. //! Constructor
  89. //! \param fenster The window whose content should be managed
  90. DLLEXPORT Screen(NativeWindow* fenster);
  91. //! Destructor
  92. DLLEXPORT virtual ~Screen();
  93. //! Passes a void function pointer to an action that should be executed
  94. //! once by the main thread. Called at the beginning of tick()
  95. DLLEXPORT void postAction(std::function<void()> action);
  96. //! if set to true, then maus and keyboard events are added to a queue
  97. //! and will be handled at the next call of tick. Otherwise they are
  98. //! handled by the calling thread after waiting for a lock between the
  99. //! rendering and ticks. This can lead to longer waiting times since the
  100. //! lock can not allways be aquired betwean two frames
  101. DLLEXPORT void setHandleUserInputsOnTick(bool handleOnTick);
  102. //! This is necessary if multiple threads use the screen simultaneously.
  103. //! If lock() is called by two threads, the last one waits until the
  104. //! first has called unlock().
  105. DLLEXPORT virtual void lock();
  106. //! This is necessary if multiple threads use the screen simultaneously.
  107. //! If lock() is called by two threads, the last one waits until the
  108. //! first has called unlock().
  109. DLLEXPORT virtual void unlock();
  110. //! Specifies whether the screen is refilled with a color after each
  111. //! frame (set by default) \param f 1 if the image should be reset
  112. //! before drawing
  113. DLLEXPORT virtual void setFill(bool f);
  114. //! Updates the objects that manage the graphics card
  115. DLLEXPORT virtual void update();
  116. //! Specifies whether it is checked before drawing if the image differs
  117. //! from the last one (set by default) \param tr 1 if drawing should
  118. //! only occur when necessary
  119. DLLEXPORT virtual void setTestRend(bool tr);
  120. //! Specifies whether 2D GUI drawings should be drawn
  121. //! (set by default) \param rO 1 if drawings should be drawn
  122. DLLEXPORT virtual void setRenderDrawables(bool rO);
  123. //! Specifies whether a drawing should be drawn above all other drawings
  124. //! (not set by default) \param onTop 1 if a drawing should be drawn
  125. //! above everything
  126. DLLEXPORT virtual void setOnTop(bool onTop);
  127. //! Sets the drawing to be drawn above everything, if setOnTop(1) was
  128. //! set
  129. //! \param obj The drawing
  130. DLLEXPORT virtual void setOnTopDrawable(Drawable* obj);
  131. //! Sets a color that is alpha-blended over the entire image after
  132. //! drawing, if setOnTop(1) was set. The drawing set with
  133. //! setOnTopDrawable() is not affected \param f The color in A8R8G8B8
  134. //! format
  135. DLLEXPORT virtual void setdeckFarbe(int f);
  136. //! Adds a drawing to the image that is always drawn when
  137. //! setRenderDrawables(1) was set. \param obj The drawing
  138. DLLEXPORT virtual void addMember(Drawable* obj);
  139. //! Removes a drawing from the image. Must not be called while
  140. //! doMausEreignis(), doTastaturEreignis(), tick() or render() is
  141. //! being called. \param obj The drawing (without increased reference
  142. //! counter)
  143. DLLEXPORT virtual void removeMember(Drawable* zObj);
  144. //! Draws an image and presents it on the screen
  145. DLLEXPORT virtual void render();
  146. //! Sets the color used to fill the image before drawing, if
  147. //! setFill(1) was set \param f The color in A8R8G8B8 format
  148. DLLEXPORT virtual void setFillFarbe(int f);
  149. //! Specifies whether the image should be presented in fullscreen mode.
  150. //! (not set by default) \param fullscreen 1 for fullscreen mode
  151. DLLEXPORT virtual void setVollbild(bool fullscreen);
  152. //! Processes the time elapsed since the last call of this function.
  153. //! Calls the tick functions of all drawings in the image
  154. //! \param tickval The elapsed time in seconds
  155. DLLEXPORT virtual void tick(double tickval);
  156. //! Sets the resolution of the displayed image. It is automatically
  157. //! scaled by the graphics card to fill the window
  158. //! \param breite The width of the image in pixels
  159. //! \param height The height of the image in pixels
  160. DLLEXPORT virtual void setBackBufferSize(int breite, int height);
  161. //! Sets the resolution of the displayed image. It is automatically
  162. //! scaled by the graphics card to fill the window
  163. //! \param size The width and height in pixels
  164. DLLEXPORT virtual void setBackBufferSize(Punkt& size);
  165. //! Processes a mouse event. Called automatically by the framework.
  166. //! Passes the event to all drawings in the image
  167. //! \param me The event
  168. DLLEXPORT virtual void doMausEreignis(MausEreignis& me);
  169. //! Processes a keyboard event. Called automatically by the framework.
  170. //! Passes the event to all drawings in the image
  171. //! \param te The event
  172. DLLEXPORT virtual void doTastaturEreignis(TastaturEreignis& te);
  173. //! Adds a tooltip.
  174. //! \param tip The tooltip
  175. DLLEXPORT virtual void addToolTip(ToolTip* tip);
  176. //! Returns the image into which the 2D GUI drawings of the framework
  177. //! are drawn
  178. DLLEXPORT virtual Image* getRenderImage() const;
  179. //! Returns the image without increased reference counter into which
  180. //! the 2D GUI drawings of the framework are drawn
  181. DLLEXPORT virtual Image* zRenderImage() const;
  182. //! Returns an array of 2D GUI drawings in the image
  183. DLLEXPORT virtual ArrayIterator<Drawable*> getMembers() const;
  184. //! Returns the color in A8R8G8B8 format used to fill the image
  185. //! before drawing
  186. DLLEXPORT virtual int getFillFarbe() const;
  187. //! Returns whether fullscreen mode is active
  188. DLLEXPORT virtual bool istVolbild() const;
  189. //! Returns the resolution in pixels at which drawing occurs
  190. DLLEXPORT virtual const Punkt getBackBufferSize() const;
  191. //! Waits until the current image has finished drawing
  192. DLLEXPORT virtual void warteAufRendern() const;
  193. //! Returns the time in seconds needed to draw the last image
  194. DLLEXPORT virtual double getRenderZeit() const;
  195. //! Returns the graphics API (without increased reference counter)
  196. DLLEXPORT GraphicsApi* zGraphicsApi() const;
  197. //! Returns the graphics API
  198. DLLEXPORT GraphicsApi* getGraphicsApi() const;
  199. };
  200. #ifdef WIN32
  201. //! This class manages the image on the screen without 3D elements
  202. class Screen2D : public Screen
  203. {
  204. public:
  205. //! Constructor
  206. //! \param fenster The window whose content should be managed
  207. DLLEXPORT Screen2D(NativeWindow* fenster);
  208. //! Destructor
  209. DLLEXPORT virtual ~Screen2D();
  210. //! Draws an image and presents it on the screen
  211. DLLEXPORT virtual void render();
  212. };
  213. //! This class manages the image on the screen with 3D elements
  214. class Screen3D : public Screen
  215. {
  216. private:
  217. RCArray<Kam3D>* kameras;
  218. bool rend3D;
  219. public:
  220. //! Constructor
  221. //! \param fenster The window whose content should be managed
  222. DLLEXPORT Screen3D(NativeWindow* fenster);
  223. DLLEXPORT Screen3D(NativeWindow* fenster, GraphicApiType apiTyp);
  224. DLLEXPORT Screen3D(NativeWindow* fenster, GraphicsApi* api);
  225. //! Destructor
  226. DLLEXPORT virtual ~Screen3D();
  227. //! Adds a camera to the screen
  228. //! \param obj The camera
  229. DLLEXPORT void addKamera(Kam3D* obj);
  230. //! Removes a camera from the screen
  231. DLLEXPORT void removeKamera(Kam3D* zObj);
  232. //! Processes the time elapsed since the last call of this function.
  233. //! Calls the tick functions of all drawings and cameras in the image
  234. //! \param tickval The elapsed time in seconds
  235. DLLEXPORT void tick(double tickval);
  236. //! Processes a mouse event. Called automatically by the framework.
  237. //! Passes the event to all drawings and cameras in the image
  238. //! \param me The event
  239. DLLEXPORT void doMausEreignis(MausEreignis& me);
  240. //! Processes a keyboard event. Called automatically by the framework.
  241. //! Passes the event to all drawings and cameras in the image
  242. //! \param te The event
  243. DLLEXPORT void doTastaturEreignis(TastaturEreignis& te);
  244. //! Draws an image and presents it on the screen
  245. DLLEXPORT void render();
  246. };
  247. //! Finds the position and resolution of a monitor
  248. //! \param id The ID of the monitor. If the monitor was not found,
  249. //! the existiert flag of the returned Monitor structure is 0
  250. DLLEXPORT Monitor getMonitor(int id);
  251. #endif
  252. } // namespace Framework
  253. #endif