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