1 // Copyright (C) 2002-2012 Nikolaus Gebhardt / Gaz Davidson 2 // This file is part of the "Irrlicht Engine". 3 // For conditions of distribution and use, see copyright notice in irrlicht.h 4 5 #ifndef __C_GUIEDIT_WORKSPACE_H_INCLUDED__ 6 #define __C_GUIEDIT_WORKSPACE_H_INCLUDED__ 7 8 #include "IGUIElement.h" 9 #include "CGUIEditWindow.h" 10 #include "EGUIEditTypes.h" 11 12 namespace irr 13 { 14 namespace gui 15 { 16 17 //! Adding the GUI Editor Workspace to an element allows you 18 /** to create, edit, load and save any elements supported 19 by any loaded factories. 20 When you add it without a parent (to the root element) 21 it will also allow you to edit, load and save settings in 22 the current skin. 23 */ 24 25 // custom events 26 enum EGUIEDIT_CUSTOM_EVENTS 27 { 28 EGUIEDCE_ATTRIB_EDITOR = MAKE_IRR_ID('g','A','t','t'), 29 EGUIEDCE_OPTION_EDITOR = MAKE_IRR_ID('g','O','p','t'), 30 EGUIEDCE_ENV_EDITOR = MAKE_IRR_ID('g','E','n','v') 31 }; 32 33 class CGUIEditWorkspace : public IGUIElement 34 { 35 public: 36 37 //! constructor 38 CGUIEditWorkspace(IGUIEnvironment* environment, s32 id=-1, IGUIElement *parent=0); 39 40 //! destructor 41 ~CGUIEditWorkspace(); 42 43 //! called if an event happened. 44 virtual bool OnEvent(const SEvent &event); 45 46 //! Removes a child. 47 virtual void removeChild(IGUIElement* child); 48 49 //! draws the element and its children 50 virtual void draw(); 51 52 //! Updates the absolute position. 53 virtual void updateAbsolutePosition(); 54 55 //! Sets the menu command id's 56 /** The GUI editor defaults to command ID's from 0xED17 to 0xED17+EGUIEDMC_COUNT 57 In the rare case that these are already in use and you wish to use menus 58 while the editor is present you can set a new offset here. 59 */ 60 virtual void setMenuCommandIDStart(s32 id); 61 62 //! grid drawing... 63 virtual void setDrawGrid(bool drawGrid); 64 virtual void setGridSize(const core::dimension2di& gridSize); 65 virtual void setUseGrid(bool useGrid); 66 67 //! returns the first editable element under the mouse 68 virtual IGUIElement* getEditableElementFromPoint(IGUIElement *start, const core::position2di &point, s32 index=0 ); 69 70 //! selecting elements 71 virtual void setSelectedElement(IGUIElement *sel); 72 virtual void selectNextSibling(); 73 virtual void selectPreviousSibling(); 74 75 //! returns the selected element 76 virtual IGUIElement* getSelectedElement(); 77 78 //! copies the xml of the selected element and all children to the clipboard 79 virtual void CopySelectedElementXML(); 80 81 //! copies the xml of the selected element and all children to the clipboard 82 virtual void PasteXMLToSelectedElement(); 83 getTypeName()84 virtual const c8* getTypeName() const 85 { 86 return GUIEditElementTypeNames[EGUIEDIT_GUIEDIT]; 87 } 88 89 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0); 90 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0); 91 92 private: 93 94 enum EGUIEDIT_MODE 95 { 96 // when we are currently selecting an element 97 EGUIEDM_SELECT=0, 98 // selecting a new parent for the selected element 99 EGUIEDM_SELECT_NEW_PARENT, 100 101 // moving the selected element 102 EGUIEDM_MOVE, 103 // resizing the selected element 104 EGUIEDM_RESIZE_TL, 105 EGUIEDM_RESIZE_T, 106 EGUIEDM_RESIZE_TR, 107 EGUIEDM_RESIZE_R, 108 EGUIEDM_RESIZE_BR, 109 EGUIEDM_RESIZE_B, 110 EGUIEDM_RESIZE_BL, 111 EGUIEDM_RESIZE_L 112 }; 113 114 enum EGUIEDIT_MENUCOMMANDS 115 { 116 //! file commands 117 EGUIEDMC_FILE_NEW, 118 EGUIEDMC_FILE_LOAD, 119 EGUIEDMC_FILE_SAVE, 120 //! edit menu 121 EGUIEDMC_CUT_ELEMENT, 122 EGUIEDMC_COPY_ELEMENT, 123 EGUIEDMC_PASTE_ELEMENT, 124 EGUIEDMC_DELETE_ELEMENT, 125 EGUIEDMC_SET_PARENT, 126 EGUIEDMC_BRING_TO_FRONT, 127 EGUIEDMC_SAVE_ELEMENT, 128 //! grid 129 EGUIEDMC_TOGGLE_EDITOR, 130 131 EGUIEDMC_INSERT_XML, 132 133 //! number of menu options 134 EGUIEDMC_COUNT 135 }; 136 137 EGUIEDIT_MODE getModeFromPos(core::position2di p); 138 139 EGUIEDIT_MODE CurrentMode; 140 EGUIEDIT_MODE MouseOverMode; 141 core::position2di DragStart; 142 core::position2di StartMovePos; 143 core::rect<s32> SelectedArea; 144 145 core::dimension2di GridSize; 146 s32 MenuCommandStart; 147 bool DrawGrid, UseGrid; 148 149 IGUIElement *MouseOverElement, 150 *SelectedElement; 151 CGUIEditWindow *EditorWindow; 152 153 core::rect<s32> TLRect; 154 core::rect<s32> TRRect; 155 core::rect<s32> TopRect; 156 core::rect<s32> BLRect; 157 core::rect<s32> LRect; 158 core::rect<s32> RRect; 159 core::rect<s32> BRRect; 160 core::rect<s32> BRect; 161 }; 162 163 164 } // end namespace gui 165 } // end namespace irr 166 167 #endif 168 169