enginewindow.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #ifndef _enginewindow_h_
  2. #define _enginewindow_h_
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // A window with an associated engine object
  6. //
  7. //////////////////////////////////////////////////////////////////////////////
  8. class EngineWindow :
  9. public Window,
  10. public IKeyboardInput,
  11. public ICaptionSite,
  12. public ButtonEvent::Sink
  13. {
  14. protected:
  15. //////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Types
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. class ModeData {
  21. public:
  22. WinPoint m_size;
  23. bool m_bStretch;
  24. ModeData(const WinPoint& size, bool bStretch) :
  25. m_size(size),
  26. m_bStretch(bStretch)
  27. {
  28. }
  29. ModeData(const ModeData& data) :
  30. m_size(data.m_size),
  31. m_bStretch(data.m_bStretch)
  32. {
  33. }
  34. };
  35. class MenuCommandSink : public IMenuCommandSink {
  36. private:
  37. EngineWindow* m_pwindow;
  38. public:
  39. MenuCommandSink(EngineWindow* pwindow) :
  40. m_pwindow(pwindow)
  41. {
  42. }
  43. void OnMenuCommand(IMenuItem* pitem);
  44. };
  45. friend class MenuCommandSink;
  46. //////////////////////////////////////////////////////////////////////////////
  47. //
  48. // Static Members
  49. //
  50. //////////////////////////////////////////////////////////////////////////////
  51. static ModeData s_pmodes[];
  52. static int s_countModes;
  53. static int s_forceHitTestCount;
  54. static bool s_cursorIsHidden;
  55. //////////////////////////////////////////////////////////////////////////////
  56. //
  57. // Members
  58. //
  59. //////////////////////////////////////////////////////////////////////////////
  60. TRef<Engine> m_pengine;
  61. TRef<Modeler> m_pmodeler;
  62. TRef<InputEngine> m_pinputEngine;
  63. TRef<ButtonEvent::Sink> m_pbuttonEventSink;
  64. TRef<MouseInputStream> m_pmouse;
  65. TRef<ModifiablePointValue> m_ppointMouse;
  66. TRef<Surface> m_psurface;
  67. TRef<ICaption> m_pcaption;
  68. WinRect m_rectWindowed;
  69. TRef<IKeyboardInput> m_pkeyboardInput;
  70. TRef<GroupImage> m_pgroupImage;
  71. TRef<WrapImage> m_pwrapImage;
  72. TRef<TransformImage> m_ptransformImageCursor;
  73. TRef<TranslateTransform2> m_ptranslateTransform;
  74. TRef<Image> m_pimageCursor;
  75. TRef<IPopupContainer> m_ppopupContainer;
  76. WinPoint m_sizeWindowed;
  77. WinPoint m_offsetWindowed;
  78. bool m_bMovingWindow;
  79. bool m_bSizeable;
  80. bool m_bMinimized;
  81. bool m_bHideCursor;
  82. bool m_bCaptured;
  83. bool m_bHit;
  84. bool m_bInvalid;
  85. bool m_bActive;
  86. bool m_bShowCursor;
  87. bool m_bMouseEnabled;
  88. bool m_bRestore;
  89. bool m_bMouseInside;
  90. bool m_bMoveOnHide;
  91. int m_modeIndex;
  92. TRef<ModifiableRectValue> m_prectValueScreen;
  93. TRef<ModifiableRectValue> m_prectValueRender;
  94. TRef<WrapRectValue> m_pwrapRectValueRender;
  95. TRef<ModifiableNumber> m_pnumberTime;
  96. Time m_timeStart;
  97. Time m_timeLast;
  98. Time m_timeLastFrame;
  99. Time m_timeCurrent;
  100. Time m_timeLastMouseMove;
  101. Time m_timeLastClick;
  102. //
  103. // Input
  104. //
  105. TRef<ButtonEvent::Sink> m_peventSink;
  106. //
  107. // menu
  108. //
  109. TRef<IMenuCommandSink> m_pmenuCommandSink;
  110. TRef<IMenuItem> m_pitemDevice;
  111. TRef<IMenuItem> m_pitemRenderer;
  112. TRef<IMenuItem> m_pitemResolution;
  113. TRef<IMenuItem> m_pitemRendering;
  114. TRef<IMenuItem> m_pitemAllowSecondary;
  115. TRef<IMenuItem> m_pitemAllow3DAcceleration;
  116. TRef<IMenuItem> m_pitemHigherResolution;
  117. TRef<IMenuItem> m_pitemLowerResolution;
  118. //
  119. // Performance
  120. //
  121. char m_pszLabel[20];
  122. bool m_bFPS;
  123. int m_indexFPS;
  124. float m_frameCount;
  125. int m_frameTotal;
  126. ZString m_strPerformance1;
  127. ZString m_strPerformance2;
  128. TRef<IEngineFont> m_pfontFPS;
  129. double m_triangles;
  130. double m_tpf;
  131. double m_ppf;
  132. double m_tps;
  133. double m_fps;
  134. double m_mspf;
  135. //////////////////////////////////////////////////////////////////////////////
  136. //
  137. // Methods
  138. //
  139. //////////////////////////////////////////////////////////////////////////////
  140. //
  141. // Performance
  142. //
  143. void UpdatePerformanceCounters(Context* pcontext, Time timeCurrent);
  144. void RenderPerformanceCounters(Surface* psurface);
  145. //
  146. // Implementation methods
  147. //
  148. void UpdateRectValues();
  149. void UpdateWindowStyle();
  150. void UpdateSurfacePointer();
  151. void UpdateCursor();
  152. void UpdateInput();
  153. void HandleMouseMessage(UINT message, const Point& point);
  154. void ParseCommandLine(const ZString& strCommandLine, bool& bStartFullscreen);
  155. void DoIdle();
  156. bool ShouldDrawFrame();
  157. bool RenderFrame();
  158. void UpdateFrame();
  159. void Invalidate();
  160. //
  161. // menu
  162. //
  163. void OnEngineWindowMenuCommand(IMenuItem* pitem);
  164. ZString GetRendererString();
  165. ZString GetDeviceString();
  166. ZString GetResolutionString();
  167. ZString GetRenderingString();
  168. ZString GetAllow3DAccelerationString();
  169. ZString GetAllowSecondaryString();
  170. void UpdateMenuStrings();
  171. public:
  172. EngineWindow(
  173. EngineApp* papp,
  174. const ZString& strCommandLine,
  175. const ZString& strTitle = ZString(),
  176. bool bStartFullscreen = false,
  177. const WinRect& rect = WinRect(0, 0, -1, -1),
  178. const WinPoint& sizeMin = WinPoint(1, 1),
  179. HMENU hmenu = NULL
  180. );
  181. ~EngineWindow();
  182. //
  183. // Static Functions
  184. //
  185. static void DoHitTest();
  186. //
  187. // EngineWindow methods
  188. //
  189. Number* GetTime() { return m_pnumberTime; }
  190. Engine* GetEngine() { return m_pengine; }
  191. Modeler* GetModeler() { return m_pmodeler; }
  192. bool GetFullscreen() { return m_pengine->IsFullscreen(); }
  193. bool GetShowFPS() { return m_bFPS; }
  194. IPopupContainer* GetPopupContainer() { return m_ppopupContainer; }
  195. InputEngine* GetInputEngine() { return m_pinputEngine; }
  196. const Point& GetMousePosition() { return m_ppointMouse->GetValue(); }
  197. bool GetActive() { return m_bActive; }
  198. TRef<IPopup> GetEngineMenu(IEngineFont* pfont);
  199. RectValue* GetScreenRectValue();
  200. RectValue* GetRenderRectValue();
  201. void SetFullscreen(bool bFullscreen);
  202. void SetSizeable(bool bSizeable);
  203. void SetWindowedSize(const WinPoint& point);
  204. void SetFullscreenSize(const WinPoint& point);
  205. void ChangeFullscreenSize(bool bLarger);
  206. void Set3DAccelerationImportant(bool b3DAccelerationImportant);
  207. void SetMouseEnabled(bool bEnable);
  208. WinPoint GetSize();
  209. WinPoint GetWindowedSize();
  210. WinPoint GetFullscreenSize();
  211. void OutputPerformanceCounters();
  212. void SetImage(Image* pimage);
  213. void SetCursorImage(Image* pimage);
  214. Image* GetCursorImage(void) const;
  215. void SetCaption(ICaption* pcaption);
  216. void SetHideCursorTimer(bool bHideCursor);
  217. void SetShowFPS(bool bFPS, const char* pszLabel = NULL);
  218. void ToggleShowFPS();
  219. void SetMoveOnHide(bool bMoveOnHide);
  220. //
  221. // App exit
  222. //
  223. virtual void StartClose();
  224. //
  225. // subclass overrides
  226. //
  227. virtual ZString GetFPSString(float dtime, float mspf, Context* pcontext);
  228. virtual void EvaluateFrame(Time time) {}
  229. virtual void RenderSizeChanged(bool bSmaller) {}
  230. //
  231. // ICaptionSite methods
  232. //
  233. void OnCaptionMinimize();
  234. void OnCaptionMaximize();
  235. void OnCaptionFullscreen();
  236. void OnCaptionRestore();
  237. void OnCaptionClose();
  238. //
  239. // ButtonEvent::Sink methods
  240. //
  241. bool OnEvent(ButtonEvent::Source* pevent, ButtonEventData data);
  242. //
  243. // IInputProvider methods
  244. //
  245. void SetCursorPos(const Point& point);
  246. bool IsDoubleClick();
  247. void ShowCursor(bool bShow);
  248. //
  249. // Window methods
  250. //
  251. void RectChanged();
  252. void OnClose();
  253. bool OnActivate(UINT nState, bool bMinimized);
  254. bool OnActivateApp(bool bActive);
  255. bool OnMouseMessage(UINT message, UINT nFlags, const WinPoint& point);
  256. bool OnSysCommand(UINT uCmdType, const WinPoint &point);
  257. void OnPaint(HDC hdc, const WinRect& rect);
  258. bool OnWindowPosChanging(WINDOWPOS* pwp);
  259. //
  260. // IObject methods
  261. //
  262. bool IsValid();
  263. };
  264. #endif