IsoView.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #if !defined(AFX_ISOVIEW_H__7FB6D6A0_7B52_11D3_99E1_DA6DFD21E706__INCLUDED_)
  17. #define AFX_ISOVIEW_H__7FB6D6A0_7B52_11D3_99E1_DA6DFD21E706__INCLUDED_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif // _MSC_VER > 1000
  21. // IsoView.h : header file
  22. //
  23. /////////////////////////////////////////////////////////////////////////////
  24. // View CIsoView
  25. #include <vector>
  26. #include <memory>
  27. #include "MissionEditorPackLib.h"
  28. #include "Structs.h"
  29. struct TextToRender
  30. {
  31. std::string text;
  32. int drawx;
  33. int drawy;
  34. int color;
  35. bool fixedScreenPos = false;
  36. bool useFont9 = false;
  37. bool centered = false;
  38. };
  39. struct WaypointToRender
  40. {
  41. int drawx;
  42. int drawy;
  43. };
  44. class TextDrawer;
  45. class CTube;
  46. class CIsoView : public CView
  47. {
  48. protected:
  49. DECLARE_DYNCREATE(CIsoView)
  50. // attributes
  51. public:
  52. INT m_mapx;
  53. INT m_mapy;
  54. int m_FlattenHeight; // for flatten ground
  55. int m_FlattenLastX;
  56. int m_FlattenLastY;
  57. int m_TileChangeCount;
  58. BOOL bThreadPainting;
  59. private:
  60. ProjectedVec m_viewOffset;
  61. Vec2<CSProjected, float> m_viewScale; // this is used for display and may e.g. be locked to zoom steps
  62. float m_viewScaleControl; // you control these with your mouse
  63. CPoint m_MButtonDown;
  64. CPoint m_MButtonMoveZooming;
  65. int rclick_x; // scroll pixel coordinates
  66. int rclick_y;
  67. int cur_x_mouse;
  68. int cur_y_mouse;
  69. BOOL rscroll;
  70. BOOL m_bAltCliff;
  71. bool m_zooming;
  72. std::vector<TextToRender> m_texts_to_render;
  73. std::vector<WaypointToRender> m_waypoints_to_render;
  74. // operations
  75. public:
  76. CIsoView();
  77. virtual ~CIsoView();
  78. // overwriteables
  79. //{{AFX_VIRTUAL(CIsoView)
  80. public:
  81. virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
  82. protected:
  83. virtual void OnDraw(CDC* pDC); // Überschrieben zum Zeichnen dieser Ansicht
  84. virtual void OnInitialUpdate(); // Zum ersten Mal nach der Konstruktion
  85. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  86. virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
  87. //}}AFX_VIRTUAL
  88. // implementation
  89. protected:
  90. #ifdef _DEBUG
  91. virtual void AssertValid() const;
  92. virtual void Dump(CDumpContext& dc) const;
  93. #endif
  94. // generated message maps
  95. //{{AFX_MSG(CIsoView)
  96. afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
  97. afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  98. afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  99. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  100. afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
  101. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  102. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  103. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  104. afx_msg void OnMove(int x, int y);
  105. afx_msg void OnSize(UINT nType, int cx, int cy);
  106. afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  107. afx_msg void OnDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  108. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  109. afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  110. afx_msg void OnTimer(UINT nIDEvent);
  111. afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  112. afx_msg void OnKillFocus(CWnd* pNewWnd);
  113. //}}AFX_MSG
  114. DECLARE_MESSAGE_MAP()
  115. public:
  116. void FocusWaypoint(int index);
  117. RECT m_funcRect;
  118. Vec2<CSProjected, float> GetViewScale() const
  119. {
  120. return m_viewScale;
  121. }
  122. ProjectedVec GetViewOffset() const
  123. {
  124. return m_viewOffset;
  125. }
  126. RECT GetScaledDisplayRect() const;
  127. void GetScroll(int& xscroll, int& yscroll) const;
  128. void SetScroll(int xscroll, int yscroll);
  129. void DrawMap();
  130. void AutoLevel();
  131. void FillArea(DWORD dwX, DWORD dwY, DWORD dwID, BYTE bSubTile);
  132. BOOL m_NoMove;
  133. void PlaceCurrentObjectAt(int x, int y);
  134. void PlaceTile(const int x, const int y, const UINT nMouseFlags);
  135. void ShowAllTileSets();
  136. void HideTileSet(DWORD dwTileSet);
  137. void FlipHighResBuffer();
  138. void BlitBackbufferToHighRes();
  139. void RenderUIOverlay();
  140. int m_BrushSize_x;
  141. int m_BrushSize_y;
  142. BOOL ReachableFrom(DWORD dwStart, DWORD dwEnd);
  143. void __fastcall ChangeTileHeight(DWORD dwPos, DWORD dwNewHeight, BOOL bNonMorphableMove, BOOL bOnlyThisTile=FALSE, BOOL bNoSlopes=FALSE);
  144. void UpdateOverlayPictures(int id=-1);
  145. void UpdateStatusBar(int x, int y);
  146. void DrawCell(int x, int y, int w, int h, COLORREF col, BOOL dotted=FALSE, HDC hDC=nullptr);
  147. void DrawCell(void* dest, int dest_width, int dest_height, int dest_pitch, int x, int y, int w, int h, int col, bool dotted=false, bool touchNeighbours=false, int colNeighbour=CLR_INVALID) const;
  148. void DrawCellCursor(const MapCoords& mapCoords, const DDSURFACEDESC2& desc);
  149. void DrawTube(const CTube& tube, const DDSURFACEDESC2* ddsd=nullptr, const COLORREF* color=nullptr) const;
  150. /// <summary>
  151. /// Converts from (world) pixel coordinates to logical map coordinates
  152. /// </summary>
  153. /// <param name="projCoords">World pixel coordinates</param>
  154. /// <returns>Logical map coordinates</returns>
  155. MapCoords GetMapCoordinates(const ProjectedCoords& projCoords, bool bAllowAccessBehindCliffs=false, bool ignoreHideFlags = false) const;
  156. /// <summary>
  157. /// Converts from view / render target pixel coordinates (0/0 is top left corner of screen) to logical map coordinates
  158. /// If you use mouse-move coordinates you need to
  159. /// </summary>
  160. /// <param name="projCoords">Texel coordinates of the backbuffer render target</param>
  161. /// <returns>Logical map coordinates</returns>
  162. MapCoords GetMapCoordinatesFromRenderTargetCoordinates(const ProjectedCoords& screenViewCoords, bool bAllowAccessBehindCliffs = false, bool ignoreHideFlags = false) const;
  163. /// <summary>
  164. /// Converts from Win32 window client coordinates (0/0 at the top left corner of the view window) to logical map coordinates
  165. /// </summary>
  166. /// <param name="clientPt">Client coordinates as given e.g. by window messages</param>
  167. /// <returns>Logical map coordinates</returns>
  168. MapCoords GetMapCoordinatesFromClientCoordinates(const CPoint& clientPt, bool bAllowAccessBehindCliffs = false, bool ignoreHideFlags = false) const;
  169. /// <summary>
  170. /// Converts from Win32 window client coordinates (0/0 at the top left corner of the view window) to (world) pixel coordinates
  171. /// </summary>
  172. /// <param name="clientPt">Client coordinates as given e.g. by window messages</param>
  173. /// <returns>World pixel coordinates</returns>
  174. ProjectedCoords GetProjectedCoordinatesFromClientCoordinates(const CPoint& clientPt) const;
  175. /// <summary>
  176. /// Converts from logical map coordinates to (world) pixel coordinates
  177. /// </summary>
  178. /// <param name="mapCoords">Logical map coordinates</param>
  179. /// <returns>World pixel coordinates</returns>
  180. ProjectedCoords GetProjectedCoordinates(const MapCoords& mapCoords) const;
  181. /// <summary>
  182. /// Converts from logical map coordinates to (world) pixel coordinates
  183. /// </summary>
  184. /// <param name="mapCoords">Logical map coordinates</param>
  185. /// <param name="mapZ">Fixed logical height</param>
  186. /// <returns>World pixel coordinates</returns>
  187. ProjectedCoords GetProjectedCoordinates(const MapCoords& mapCoords, int mapZ) const;
  188. /// <summary>
  189. /// Converts from logical map coordinates to view / render target pixel coordinates (screen backbuffer, e.g. currently not yet scaled by view zoom)
  190. /// </summary>
  191. /// <param name="mapCoords">Logical map coordinates</param>
  192. /// <returns>Texel coordinates of the screen backbuffer</returns>
  193. ProjectedCoords GetRenderTargetCoordinates(const MapCoords& mapCoords) const;
  194. /// <summary>
  195. /// Converts from logical map coordinates to view / render target pixel coordinates (screen backbuffer, e.g. currently not yet scaled by view zoom)
  196. /// </summary>
  197. /// <param name="mapCoords">Logical map coordinates</param>
  198. /// <param name="mapZ">Fixed logical height</param>
  199. /// <returns>Texel coordinates of the screen backbuffer</returns>
  200. ProjectedCoords GetRenderTargetCoordinates(const MapCoords& mapCoords, int mapZ) const;
  201. /// <summary>
  202. /// Converts from logical map coordinates to Win32 window client coordinates (0/0 at the top left corner of the view window)
  203. /// </summary>
  204. /// <param name="projCoords">Logical map coordinates</param>
  205. /// <returns>Texel coordinates of the backbuffer render target</returns>
  206. CPoint GetClientCoordinates(const MapCoords& mapCoords) const;
  207. /// <summary>
  208. /// Converts from (world) pixel coordinates to Win32 window client coordinates (0/0 at the top left corner of the view window)
  209. /// </summary>
  210. /// <param name="projCoords">World pixel coordinates</param>
  211. /// <returns>Client coordinates as given e.g. by window messages</returns>
  212. CPoint GetClientCoordinatesFromWorld(const ProjectedCoords& projectedCoords) const;
  213. /// <summary>
  214. /// Applies the scaling as it is being done when blitting from back to frontbuffer, required e.g. for drawing calls directly to the frontbuffer
  215. /// If you use mouse-move coordinates you need to
  216. /// </summary>
  217. /// <param name="projCoords">Texel coordinates of the backbuffer render target</param>
  218. /// <returns>Texel coordinates of the frontbuffer render target</returns>
  219. ProjectedCoords ScaleBackToFrontBuffer(const ProjectedCoords& backBufferCoords) const;
  220. void HandleTrail(int x, int y);
  221. int GetOverlayDirection(int x, int y);
  222. void SetError(const char* text);
  223. CWnd* owner;
  224. void ReInitializeDDraw();
  225. COLORREF GetColor(const char* house, const char* color=NULL);
  226. void Blit(LPDIRECTDRAWSURFACE4 pic, int x, int y, int width=-1, int height=-1)
  227. {
  228. if(pic==NULL) return;
  229. x+=1;
  230. y+=1;
  231. //y-=f_y;
  232. RECT r;
  233. GetDesktopWindow()->GetWindowRect(&r);
  234. //GetWindowRect(&r);
  235. if(width==-1 || height==-1)
  236. {
  237. DDSURFACEDESC2 ddsd;
  238. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  239. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  240. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  241. pic->GetSurfaceDesc(&ddsd);
  242. width=ddsd.dwWidth;
  243. height=ddsd.dwHeight;
  244. }
  245. if(x+width<0 || y+height<0) return;
  246. if(x>r.right || y>r.bottom) return;
  247. if(x<0 || y<0 || x+width>=r.right || y+height>=r.bottom)
  248. {
  249. RECT blrect;
  250. RECT srcRect;
  251. srcRect.left=0;
  252. srcRect.top=0;
  253. srcRect.right=width;
  254. srcRect.bottom=height;
  255. blrect.left=x;
  256. if(blrect.left<0)
  257. {
  258. srcRect.left=r.left+1-blrect.left;
  259. blrect.left=r.left+1;
  260. }
  261. blrect.top=y;
  262. if(blrect.top<0)
  263. {
  264. //errstream << "BlRect.top=" << blrect.top << endl;
  265. srcRect.top=(r.top+1)-blrect.top; //(r.top-blrect.top);
  266. blrect.top=r.top+1;//r.top;
  267. // errstream << blrect.top << " " << srcRect.top << endl;
  268. }
  269. blrect.right=(x+width);
  270. if(x+width>r.right)
  271. {
  272. srcRect.right=width-((x+width)-r.right);// -(-blrect.right+r.right);
  273. blrect.right=r.right;
  274. }
  275. blrect.bottom=(y+height);
  276. if(y+height>r.bottom)
  277. {
  278. srcRect.bottom=height-((y+height)-r.bottom); // -(-blrect.bottom+r.bottom);
  279. blrect.bottom=r.bottom;
  280. }
  281. DDBLTFX fx;
  282. memset(&fx, 0, sizeof(DDBLTFX));
  283. fx.dwSize=sizeof(DDBLTFX);
  284. lpdsBack->Blt(&blrect, pic, &srcRect, DDBLT_KEYSRC, &fx);
  285. }
  286. else
  287. lpdsBack->BltFast(x,y, pic, NULL, DDBLTFAST_SRCCOLORKEY);
  288. }
  289. void updateFontScaled();
  290. void TextOut(int x, int y, const char* text, COLORREF col);
  291. void TextOut(HDC hDC, int x, int y, const char* text, COLORREF col);
  292. LPDIRECTDRAWSURFACE4 lpdsBack;
  293. LPDIRECTDRAWSURFACE4 lpdsTemp; // used for saving the isoview when drawing current tile
  294. LPDIRECTDRAWSURFACE4 lpdsBackHighRes; // used for rendering text and some lines in high-res
  295. LPDIRECTDRAWSURFACE4 lpds;
  296. DDPIXELFORMAT pf;
  297. std::unique_ptr<FSunPackLib::ColorConverter> m_color_converter;
  298. LPDIRECTDRAW4 dd;
  299. LPDIRECTDRAW dd_1;
  300. HGLRC m_hglrc;
  301. void HandleProperties(int n, int type);
  302. void UpdateDialog(BOOL bRepos=TRUE);
  303. CMenu m_menu;
  304. BOOL b_IsLoading;
  305. int m_fontDefaultHeight;
  306. int m_Font9Height;
  307. std::unique_ptr<TextDrawer> m_textDefault;
  308. std::unique_ptr<TextDrawer> m_textScaled;
  309. std::unique_ptr<TextDrawer> m_text9;
  310. std::unique_ptr<TextDrawer> m_text9Scaled;
  311. std::unique_ptr<TextDrawer> m_textBlue;
  312. std::unique_ptr<TextDrawer> m_textBlue9;
  313. std::unique_ptr<TextDrawer> m_textBlueScaled;
  314. std::unique_ptr<TextDrawer> m_textBlue9Scaled;
  315. private:
  316. void UpdateScrollRanges();
  317. private:
  318. RECT m_myRect;
  319. // mapdata* _map;
  320. COLORREF m_linecolor;
  321. RECT line;
  322. int m_type;
  323. int m_id;
  324. BOOL m_drag;
  325. BOOL m_moved;
  326. MapCoords m_cellCursor;
  327. public:
  328. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  329. void Zoom(CPoint& pt, float f);
  330. afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
  331. afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
  332. };
  333. /////////////////////////////////////////////////////////////////////////////
  334. //{{AFX_INSERT_LOCATION}}
  335. #endif // AFX_ISOVIEW_H__7FB6D6A0_7B52_11D3_99E1_DA6DFD21E706__INCLUDED_