guiMissionArea.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIMISSIONAREA_H_
  23. #define _GUIMISSIONAREA_H_
  24. #ifndef _GUIBITMAPCTRL_H_
  25. #include "gui/controls/guiBitmapCtrl.h"
  26. #endif
  27. #ifndef _GUITYPES_H_
  28. #include "gui/guiTypes.h"
  29. #endif
  30. #ifndef _MISSIONAREA_H_
  31. #include "T3D/missionArea.h"
  32. #endif
  33. #ifndef _UNDO_H_
  34. #include "util/undo.h"
  35. #endif
  36. class GBitmap;
  37. class TerrainBlock;
  38. class GuiMissionAreaCtrl : public GuiBitmapCtrl
  39. {
  40. typedef GuiBitmapCtrl Parent;
  41. protected:
  42. enum HandleInfo
  43. {
  44. // Handle in use
  45. Handle_None = 0,
  46. Handle_Left = BIT(0),
  47. Handle_Right = BIT(1),
  48. Handle_Top = BIT(2),
  49. Handle_Bottom = BIT(3),
  50. Handle_Middle = BIT(4), // Used to drag the whole area
  51. Handle_Pixel_Size = 3,
  52. };
  53. SimObjectPtr<MissionArea> mMissionArea;
  54. SimObjectPtr<TerrainBlock> mTerrainBlock;
  55. GFXStateBlockRef mBlendStateBlock;
  56. GFXStateBlockRef mSolidStateBlock;
  57. DECLARE_IMAGEASSET(GuiMissionAreaCtrl, HandleBitmap, onHandleBitmapChanged, GFXDefaultGUIProfile);
  58. DECLARE_ASSET_SETGET(GuiMissionAreaCtrl, HandleBitmap);
  59. Point2I mHandleTextureSize;
  60. Point2F mHandleTextureHalfSize;
  61. ColorI mMissionBoundsColor;
  62. ColorI mCameraColor;
  63. bool mSquareBitmap;
  64. VectorF mScale;
  65. Point2F mCenterPos;
  66. S32 mLastHitMode;
  67. Point2I mLastMousePoint;
  68. bool mSavedDrag;
  69. void submitUndo( const UTF8 *name = "Action" );
  70. TerrainBlock * getTerrainObj();
  71. GBitmap * createTerrainBitmap();
  72. void updateTerrainBitmap();
  73. //void onUpdate();
  74. void setupScreenTransform(const Point2I & offset);
  75. Point2F worldToScreen(const Point2F &);
  76. Point2F screenToWorld(const Point2F &);
  77. Point2I worldToScreen(const Point2I &);
  78. Point2I screenToWorld(const Point2I &);
  79. Point2I screenDeltaToWorldDelta(const Point2I &screenPoint);
  80. void getScreenMissionArea(RectI & rect);
  81. void getScreenMissionArea(RectF & rect);
  82. Point2I convertOrigin(const Point2I &);
  83. void drawHandle(const Point2F & pos);
  84. void drawHandles(RectI & box);
  85. bool testWithinHandle(const Point2I & testPoint, S32 handleX, S32 handleY);
  86. S32 getHitHandles(const Point2I & mousePnt, const RectI & box);
  87. void onHandleBitmapChanged() {}
  88. public:
  89. GuiMissionAreaCtrl();
  90. virtual ~GuiMissionAreaCtrl();
  91. DECLARE_CONOBJECT(GuiMissionAreaCtrl);
  92. // SimObject
  93. bool onAdd();
  94. static void initPersistFields();
  95. // GuiControl
  96. void onRender(Point2I offset, const RectI &updateRect);
  97. bool onWake();
  98. void onSleep();
  99. virtual void onMouseUp(const GuiEvent & event);
  100. virtual void onMouseDown(const GuiEvent & event);
  101. virtual void onMouseMove(const GuiEvent & event);
  102. virtual void onMouseDragged(const GuiEvent & event);
  103. virtual void onMouseEnter(const GuiEvent & event);
  104. virtual void onMouseLeave(const GuiEvent & event);
  105. void setMissionArea( MissionArea* area );
  106. void updateTerrain();
  107. const RectI & getArea();
  108. void setArea(const RectI & area);
  109. };
  110. class GuiMissionAreaUndoAction : public UndoAction
  111. {
  112. public:
  113. GuiMissionAreaUndoAction( const UTF8* actionName ) : UndoAction( actionName ), mMissionAreaEditor(NULL), mObjId(0)
  114. {
  115. }
  116. GuiMissionAreaCtrl *mMissionAreaEditor;
  117. SimObjectId mObjId;
  118. RectI mArea;
  119. virtual void undo();
  120. virtual void redo() { undo(); }
  121. };
  122. #endif // _GUIMISSIONAREA_H_