KX_BlenderCanvas.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): none yet.
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. /** \file KX_BlenderCanvas.h
  28. * \ingroup blroutines
  29. */
  30. #ifndef __KX_BLENDERCANVAS_H__
  31. #define __KX_BLENDERCANVAS_H__
  32. #ifdef WIN32
  33. #include <windows.h>
  34. #endif
  35. #include "RAS_ICanvas.h"
  36. #include "RAS_Rect.h"
  37. #ifdef WITH_CXX_GUARDEDALLOC
  38. #include "MEM_guardedalloc.h"
  39. #endif
  40. struct ARegion;
  41. struct wmWindow;
  42. struct wmWindowManager;
  43. /**
  44. * 2D Blender device context abstraction.
  45. * The connection from 3d rendercontext to 2d Blender surface embedding.
  46. */
  47. class KX_BlenderCanvas : public RAS_ICanvas
  48. {
  49. private:
  50. /**
  51. * Rect that defines the area used for rendering,
  52. * relative to the context */
  53. RAS_Rect m_displayarea;
  54. int m_viewport[4];
  55. public:
  56. /* Construct a new canvas.
  57. *
  58. * \param area The Blender ARegion to run the game within.
  59. */
  60. KX_BlenderCanvas(struct wmWindowManager *wm, struct wmWindow* win, RAS_Rect &rect, struct ARegion* ar);
  61. ~KX_BlenderCanvas();
  62. void
  63. Init(
  64. );
  65. void
  66. SwapBuffers(
  67. );
  68. void
  69. SetSwapInterval(
  70. int interval
  71. );
  72. bool
  73. GetSwapInterval(
  74. int &intervalOut
  75. );
  76. void GetDisplayDimensions(int &width, int &height);
  77. void
  78. ResizeWindow(
  79. int width,
  80. int height
  81. );
  82. void
  83. SetFullScreen(
  84. bool enable
  85. );
  86. bool
  87. GetFullScreen();
  88. void
  89. BeginFrame(
  90. );
  91. void
  92. EndFrame(
  93. );
  94. void
  95. ClearColor(
  96. float r,
  97. float g,
  98. float b,
  99. float a
  100. );
  101. void
  102. ClearBuffer(
  103. int type
  104. );
  105. int
  106. GetWidth(
  107. ) const;
  108. int
  109. GetHeight(
  110. ) const;
  111. int
  112. GetMouseX(int x
  113. );
  114. int
  115. GetMouseY(int y
  116. );
  117. float
  118. GetMouseNormalizedX(int x
  119. );
  120. float
  121. GetMouseNormalizedY(int y
  122. );
  123. const
  124. RAS_Rect &
  125. GetDisplayArea(
  126. ) const {
  127. return m_displayarea;
  128. };
  129. void
  130. SetDisplayArea(RAS_Rect *rect
  131. ) {
  132. m_displayarea= *rect;
  133. };
  134. RAS_Rect &
  135. GetWindowArea(
  136. );
  137. void
  138. SetViewPort(
  139. int x1, int y1,
  140. int x2, int y2
  141. );
  142. void
  143. UpdateViewPort(
  144. int x1, int y1,
  145. int x2, int y2
  146. );
  147. const int*
  148. GetViewPort();
  149. void
  150. SetMouseState(
  151. RAS_MouseState mousestate
  152. );
  153. void
  154. SetMousePosition(
  155. int x,
  156. int y
  157. );
  158. void
  159. MakeScreenShot(
  160. const char* filename
  161. );
  162. bool
  163. BeginDraw(
  164. );
  165. void
  166. EndDraw(
  167. );
  168. private:
  169. /** Blender area the game engine is running within */
  170. struct wmWindowManager *m_wm;
  171. struct wmWindow* m_win;
  172. RAS_Rect m_frame_rect;
  173. RAS_Rect m_area_rect;
  174. int m_area_left;
  175. int m_area_top;
  176. #ifdef WITH_CXX_GUARDEDALLOC
  177. MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderCanvas")
  178. #endif
  179. };
  180. #endif /* __KX_BLENDERCANVAS_H__ */