CGUIEditWorkspace.h 4.7 KB

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