guiMissionArea.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. GFXStateBlockRef mBlendStateBlock;
  55. GFXStateBlockRef mSolidStateBlock;
  56. GFXTextureTargetRef mLevelTexture;
  57. Box3F mLevelBounds;
  58. DECLARE_IMAGEASSET(GuiMissionAreaCtrl, HandleBitmap, GFXDefaultGUIProfile)
  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. //void onUpdate();
  71. void setupScreenTransform(const Point2I & offset);
  72. Point2F worldToScreen(const Point2F &);
  73. Point2F screenToWorld(const Point2F &);
  74. Point2I worldToScreen(const Point2I &);
  75. Point2I screenToWorld(const Point2I &);
  76. Point2I screenDeltaToWorldDelta(const Point2I &screenPoint);
  77. void getScreenMissionArea(RectI & rect);
  78. void getScreenMissionArea(RectF & rect);
  79. Point2I convertOrigin(const Point2I &);
  80. void drawHandle(const Point2F & pos);
  81. void drawHandles(RectI & box);
  82. bool testWithinHandle(const Point2I & testPoint, S32 handleX, S32 handleY);
  83. S32 getHitHandles(const Point2I & mousePnt, const RectI & box);
  84. public:
  85. GuiMissionAreaCtrl();
  86. virtual ~GuiMissionAreaCtrl();
  87. DECLARE_CONOBJECT(GuiMissionAreaCtrl);
  88. // SimObject
  89. bool onAdd() override;
  90. static void initPersistFields();
  91. // GuiControl
  92. void onRender(Point2I offset, const RectI &updateRect) override;
  93. bool onWake() override;
  94. void onSleep() override;
  95. void onMouseUp(const GuiEvent & event) override;
  96. void onMouseDown(const GuiEvent & event) override;
  97. void onMouseMove(const GuiEvent & event) override;
  98. void onMouseDragged(const GuiEvent & event) override;
  99. void onMouseEnter(const GuiEvent & event) override;
  100. void onMouseLeave(const GuiEvent & event) override;
  101. void setMissionArea( MissionArea* area );
  102. void updateLevelBitmap();
  103. const RectI & getArea();
  104. void setArea(const RectI & area);
  105. };
  106. class GuiMissionAreaUndoAction : public UndoAction
  107. {
  108. public:
  109. GuiMissionAreaUndoAction( const UTF8* actionName ) : UndoAction( actionName ), mMissionAreaEditor(NULL), mObjId(0)
  110. {
  111. }
  112. GuiMissionAreaCtrl *mMissionAreaEditor;
  113. SimObjectId mObjId;
  114. RectI mArea;
  115. void undo() override;
  116. void redo() override { undo(); }
  117. };
  118. #endif // _GUIMISSIONAREA_H_