Commit 4fc3ef98 authored by bitplane's avatar bitplane

Added root GUI element type. Added tree view to GUI editor, from Armen



git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3545 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 1ab25bd3
Changes in 1.8 (??.??.2011)
- Added treeview to GUI editor, provided by Armen
- Added root type for GUI environment
- Fixed panel scrollbars in GUI editor, reported by Armen
- Add some getters to IGUIImage: getImage, getColor
......
......@@ -88,6 +88,9 @@ enum EGUI_ELEMENT_TYPE
//! Unknown type.
EGUIET_ELEMENT,
//! The root of the GUI
EGUIET_ROOT,
//! Not an element, amount of elements in there
EGUIET_COUNT,
......@@ -123,6 +126,7 @@ const c8* const GUIElementTypeNames[] =
"treeview",
"window",
"element",
"root",
0
};
......
......@@ -54,7 +54,7 @@ const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE = L"type";
//! constructor
CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op)
: IGUIElement(EGUIET_ELEMENT, 0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? core::dimension2d<s32>(driver->getScreenSize()) : core::dimension2d<s32>(0,0))),
: IGUIElement(EGUIET_ROOT, 0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? core::dimension2d<s32>(driver->getScreenSize()) : core::dimension2d<s32>(0,0))),
Driver(driver), Hovered(0), HoveredNoSubelement(0), Focus(0), LastHoveredMousePos(0,0), CurrentSkin(0),
FileSystem(fs), UserReceiver(0), Operator(op)
{
......@@ -699,6 +699,7 @@ IGUIElement* CGUIEnvironment::addGUIElement(const c8* elementName, IGUIElement*
for (u32 i=0; i<GUIElementFactoryList.size() && !node; ++i)
node = GUIElementFactoryList[i]->addGUIElement(elementName, parent);
return node;
}
......
......@@ -5,6 +5,7 @@
#include "CGUIPanel.h"
#include "irrArray.h"
#include "IAttributes.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -33,8 +34,11 @@ namespace gui
// save the attributes
void updateAttribs();
//! this shoudln't be serialized, but this is included as it's an example
virtual const c8* getTypeName() const { return "attributeEditor"; }
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_ATTRIBUTEEDITOR];
}
private:
......
......@@ -3,6 +3,7 @@
#include "CGUIAttribute.h"
#include "IGUICheckBox.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -51,6 +52,12 @@ namespace gui
return CGUIAttribute::updateAttrib(sendEvent);
}
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_BOOLATTRIBUTE];
}
private:
IGUICheckBox* AttribCheckBox;
};
......
......@@ -5,6 +5,7 @@
#include "IGUIStaticText.h"
#include "IGUIScrollBar.h"
#include "IGUITabControl.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -156,10 +157,10 @@ namespace gui
return CGUIAttribute::updateAttrib(sendEvent);
}
//! this shoudln't be serialized, but this is included as it's an example
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return "color_attribute";
return GUIEditElementTypeNames[EGUIEDIT_COLORATTRIBUTE];
}
private:
......
......@@ -2,6 +2,8 @@
#include "IGUIEnvironment.h"
#include "irrString.h"
#include "EGUIEditTypes.h"
#include "CGUIEditWorkspace.h"
#include "CGUIEditWindow.h"
#include "CGUIPanel.h"
......@@ -19,56 +21,6 @@ namespace irr
namespace gui
{
enum EGUIEDIT_ELEMENT_TYPES
{
// GUI Editor
EGUIEDIT_GUIEDIT=0,
EGUIEDIT_GUIEDITWINDOW,
// Generic
EGUIEDIT_GUIPANEL,
EGUIEDIT_TEXTUREBROWSER,
// Attribute editors
EGUIEDIT_ATTRIBUTEEDITOR,
EGUIEDIT_STRINGATTRIBUTE,
EGUIEDIT_BOOLATTRIBUTE,
EGUIEDIT_ENUMATTRIBUTE,
EGUIEDIT_COLORATTRIBUTE,
EGUIEDIT_COLORFATTRIBUTE,
EGUIEDIT_TEXTUREATTRIBUTE,
// Dummy editor stubs
EGUIEDIT_CONTEXTMENUEDITOR,
EGUIEDIT_MENUEDITOR,
EGUIEDIT_FILEDIALOGEDITOR,
EGUIEDIT_COLORDIALOGEDITOR,
EGUIEDIT_MODALSCREENEDITOR,
// Count
EGUIEDIT_COUNT
};
const c8* const GUIEditElementTypeNames[] =
{
"GUIEditor",
"GUIEditWindow",
"panel",
"textureCacheBrowser",
"attributeEditor",
"string_attribute",
"bool_attribute",
"enum_attribute",
"color_attribute",
"colorf_attribute",
"texture_attribute",
// dummy editors
"contextMenu_editor",
"menu_editor",
"fileOpenDialog_editor",
"colorSelectDialog_editor",
"modalScreen_editor",
0
};
CGUIEditFactory::CGUIEditFactory(IGUIEnvironment* env)
: Environment(env)
{
......
......@@ -36,7 +36,6 @@ namespace gui
getCreatableGUIElementTypeCount() */
virtual const c8* getCreateableGUIElementTypeName(s32 idx) const;
// not used:
virtual const c8* getCreateableGUIElementTypeName(EGUI_ELEMENT_TYPE type) const {return 0;} ;
virtual EGUI_ELEMENT_TYPE getCreateableGUIElementType(s32 idx) const { return EGUIET_ELEMENT;};
......
......@@ -6,6 +6,7 @@
#include "IAttributes.h"
#include "IGUIFont.h"
#include "IGUITabControl.h"
#include "IGUITreeView.h"
#include "CGUIEditWorkspace.h"
using namespace irr;
......@@ -76,6 +77,12 @@ CGUIEditWindow::CGUIEditWindow(IGUIEnvironment* environment, core::rect<s32> rec
AttribEditor->setRelativePositionProportional(core::rect<f32>(0.0f, 0.0f, 1.0f, 1.0f));
AttribEditor->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
IGUITab* TreeTab = TabControl->addTab(L"Tree");
TreeView = environment->addTreeView(core::rect<s32>(0,0,0,0), TreeTab);
TreeView->setRelativePositionProportional(core::rect<f32>(0.0f, 0.0f, 1.0f, 1.0f));
TreeView->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
IGUITreeViewNode* treenode = TreeView->getRoot();
//treenode->addChildFront(L"Elements");
ResizeButton = environment->addButton(core::rect<s32>(199-th,449-th,199,449), this);
ResizeButton->setDrawBorder(false);
ResizeButton->setEnabled(false);
......@@ -85,6 +92,7 @@ CGUIEditWindow::CGUIEditWindow(IGUIEnvironment* environment, core::rect<s32> rec
ResizeButton->grab();
ResizeButton->setSubElement(true);
ResizeButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
updateTree();
}
......@@ -102,6 +110,10 @@ CGUIEditWindow::~CGUIEditWindow()
ResizeButton->drop();
}
IGUITreeView* CGUIEditWindow::getTreeView() const
{
return TreeView;
}
CGUIAttributeEditor* CGUIEditWindow::getEnvironmentEditor() const
{
return EnvEditor;
......@@ -117,10 +129,65 @@ CGUIAttributeEditor* CGUIEditWindow::getOptionEditor() const
return OptionEditor;
}
IGUITreeViewNode* CGUIEditWindow::getTreeNode(IGUIElement* element, IGUITreeViewNode* searchnode)
{
IGUITreeViewNode* child = searchnode->getFirstChild();
while (!child)
{
if (((IGUIElement*) child->getData()) == element)
return child;
if (child->hasChildren())
{
IGUITreeViewNode* foundnode = getTreeNode(element, child);
if (foundnode)
return foundnode;
}
child = child->getNextSibling();
}
return 0;
}
void CGUIEditWindow::addChildrenToTree(IGUIElement* parentElement, IGUITreeViewNode* treenode)
{
core::stringw name = core::stringw(parentElement->getTypeName());
if (parentElement->getID() != -1)
name += core::stringw(L" [") + core::stringw(parentElement->getID()) + core::stringw(L"]");
IGUITreeViewNode* newnode = treenode->addChildBack(name.c_str());
newnode->setData((void*)parentElement);
core::list<IGUIElement*> children = parentElement->getChildren();
for (core::list<IGUIElement*>::Iterator i = children.begin(); i != children.end(); i++ )
{
if(core::stringc((*i)->getTypeName()) != "GUIEditor" && !(*i)->isSubElement())
addChildrenToTree(*i, newnode);
}
}
void CGUIEditWindow::updateTree()
{
TreeView->getRoot()->clearChildren();
IGUIElement* root = Environment->getRootGUIElement();
addChildrenToTree(root, TreeView->getRoot());
TreeView->getRoot()->getFirstChild()->setExpanded(true);
}
void CGUIEditWindow::setSelectedElement(IGUIElement *sel)
{
// save changes
AttribEditor->updateAttribs();
IGUITreeViewNode* elementTreeNode = getTreeNode(sel, TreeView->getRoot());
if (elementTreeNode)
{
elementTreeNode->setSelected(true);
while (elementTreeNode)
{
elementTreeNode->setExpanded(true);
elementTreeNode = elementTreeNode->getParent();
}
}
io::IAttributes* Attribs = AttribEditor->getAttribs();
......@@ -196,7 +263,6 @@ bool CGUIEditWindow::OnEvent(const SEvent &event)
{
case EMIE_LMOUSE_PRESSED_DOWN:
{
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
......@@ -284,10 +350,7 @@ void CGUIEditWindow::setDraggable(bool draggable)
// but we don't need them so we'll just return null
//! Returns the rectangle of the drawable area (without border, without titlebar and without scrollbars)
core::rect<s32> CGUIEditWindow::getClientRect() const
{
return core::recti();
}
core::rect<s32> CGUIEditWindow::getClientRect() const {return core::recti();}
IGUIButton* CGUIEditWindow::getCloseButton() const {return 0;}
IGUIButton* CGUIEditWindow::getMinimizeButton() const {return 0;}
IGUIButton* CGUIEditWindow::getMaximizeButton() const {return 0;}
......@@ -6,8 +6,10 @@
#include "CGUIAttributeEditor.h"
//#include "IGUIStaticText.h"
#include "IGUIButton.h"
#include "IGUITreeView.h"
#include "irrArray.h"
#include "IAttributes.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -47,16 +49,22 @@ namespace gui
virtual void setDrawTitlebar(bool draw) { }
virtual bool getDrawTitlebar() const { return true; }
IGUITreeView* getTreeView() const;
CGUIAttributeEditor* getAttributeEditor() const;
CGUIAttributeEditor* getOptionEditor() const;
CGUIAttributeEditor* getEnvironmentEditor() const;
//! this shoudln't be serialized, but this is included as it's an example
virtual const c8* getTypeName() const { return "GUIEditWindow"; }
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_GUIEDITWINDOW];
}
void updateTree();
private:
void addChildrenToTree(IGUIElement* parentElement, IGUITreeViewNode* treenode);
IGUITreeViewNode* getTreeNode(IGUIElement* element, IGUITreeViewNode* searchnode);
// for dragging the window
bool Dragging;
bool IsDraggable;
......@@ -68,6 +76,7 @@ namespace gui
CGUIAttributeEditor* AttribEditor; // edits the current attribute
CGUIAttributeEditor* OptionEditor; // edits the options for the window
CGUIAttributeEditor* EnvEditor; // edits attributes for the environment
IGUITreeView* TreeView; // tree view of all elements in scene
IGUIButton* ResizeButton;
};
......
......@@ -16,6 +16,7 @@
#include "CGUIEditWindow.h"
#include "IGUIContextMenu.h"
#include "IGUIFileOpenDialog.h"
#include "IGUITreeView.h"
#include "CGUIAttribute.h"
#include "CMemoryReadWriteFile.h"
......@@ -237,6 +238,7 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
if (SelectedElement)
{
SelectedElement->deserializeAttributes(EditorWindow->getAttributeEditor()->getAttribs());
EditorWindow->updateTree();
}
return true;
}
......@@ -268,6 +270,7 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
setSelectedElement(0);
MouseOverElement = 0;
el->remove();
EditorWindow->updateTree();
}
break;
case KEY_KEY_X:
......@@ -570,6 +573,13 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
case EET_GUI_EVENT:
switch(e.GUIEvent.EventType)
{
case EGET_TREEVIEW_NODE_SELECT:
{
IGUITreeViewNode* eventnode = ((IGUITreeView*)e.GUIEvent.Caller)->getLastEventNode();
if(!eventnode->isRoot())
setSelectedElement((IGUIElement*)(eventnode->getData()));
break;
}
// load a gui file
case EGET_FILE_SELECTED:
dialog = (IGUIFileOpenDialog*)e.GUIEvent.Caller;
......@@ -639,6 +649,7 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
break;
case EGUIEDMC_SAVE_ELEMENT:
//TODO: add 'save' dialog.
Environment->saveGUI("guiTest.xml", SelectedElement ? SelectedElement : Environment->getRootGUIElement() );
break;
......@@ -678,6 +689,7 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
}
break;
}
EditorWindow->updateTree();
}
return true;
default:
......
......@@ -7,6 +7,7 @@
#include "IGUIElement.h"
#include "CGUIEditWindow.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -80,8 +81,10 @@ namespace gui
//! copies the xml of the selected element and all children to the clipboard
virtual void PasteXMLToSelectedElement();
//! this shoudln't be serialized, but this is included as it's an example
virtual const c8* getTypeName() const { return "GUIEditor"; }
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_GUIEDIT];
}
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0);
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
......
......@@ -4,6 +4,7 @@
#include "CGUIAttribute.h"
#include "IGUIComboBox.h"
#include "IGUIEditBox.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -95,8 +96,11 @@ namespace gui
return CGUIAttribute::updateAttrib(sendEvent);
}
//! this shoudln't be serialized, but this is included as it's an example
virtual const c8* getTypeName() const { return "enum_attribute"; }
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_ENUMATTRIBUTE];
}
private:
IGUIComboBox* AttribComboBox;
......
......@@ -20,7 +20,7 @@ namespace irr
namespace gui
{
CGUIPanel::CGUIPanel( IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
CGUIPanel::CGUIPanel(IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
bool border, E_SCROLL_BAR_MODE vMode, E_SCROLL_BAR_MODE hMode)
: IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle),
VScrollBar(0), HScrollBar(0), ClipPane(0), InnerPane(0),
......
......@@ -6,6 +6,7 @@
#define _C_GUI_PANEL_H_
#include "IGUIElement.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -93,6 +94,12 @@ public:
//! returns children of the inner pane
virtual const core::list<IGUIElement*>& getChildren();
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_GUIPANEL];
}
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0);
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
......
......@@ -3,6 +3,7 @@
#include "CGUIAttribute.h"
#include "IGUIEditBox.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -53,8 +54,11 @@ namespace gui
return CGUIAttribute::updateAttrib(sendEvent);
}
//! this shoudln't be serialized, but this is included as it's an example
virtual const c8* getTypeName() const { return "string_attribute"; }
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_STRINGATTRIBUTE];
}
private:
IGUIEditBox* AttribEditBox;
......
......@@ -5,6 +5,7 @@
#include "IGUIEditBox.h"
#include "IGUIImage.h"
#include "IGUIButton.h"
#include "EGUIEditTypes.h"
namespace irr
{
......@@ -121,8 +122,11 @@ namespace gui
return CGUIAttribute::updateAttrib(sendEvent);
}
//! this shoudln't be serialized, but this is included as it's an example
virtual const c8* getTypeName() const { return "texture_attribute"; }
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_TEXTUREATTRIBUTE];
}
private:
IGUIEditBox* AttribEditBox;
......
......@@ -8,6 +8,7 @@
#include "IGUIWindow.h"
#include "CGUIPanel.h"
#include "IGUIImage.h"
#include "EGUIEditTypes.h"
namespace irr
{
......
#ifndef __C_GUIEDIT_TYPES_H_INCLUDED__
#define __C_GUIEDIT_TYPES_H_INCLUDED__
#include "irrTypes.h"
namespace irr {
namespace gui {
enum EGUIEDIT_ELEMENT_TYPES
{
// GUI Editor
EGUIEDIT_GUIEDIT=0,
EGUIEDIT_GUIEDITWINDOW,
// Generic
EGUIEDIT_GUIPANEL,
EGUIEDIT_TEXTUREBROWSER,
// Attribute editors
EGUIEDIT_ATTRIBUTEEDITOR,
EGUIEDIT_STRINGATTRIBUTE,
EGUIEDIT_BOOLATTRIBUTE,
EGUIEDIT_ENUMATTRIBUTE,
EGUIEDIT_COLORATTRIBUTE,
EGUIEDIT_COLORFATTRIBUTE,
EGUIEDIT_TEXTUREATTRIBUTE,
// Dummy editor stubs
EGUIEDIT_CONTEXTMENUEDITOR,
EGUIEDIT_MENUEDITOR,
EGUIEDIT_FILEDIALOGEDITOR,
EGUIEDIT_COLORDIALOGEDITOR,
EGUIEDIT_MODALSCREENEDITOR,
// Count
EGUIEDIT_COUNT
};
const c8* const GUIEditElementTypeNames[] =
{
"GUIEditor",
"GUIEditWindow",
"panel",
"textureCacheBrowser",
"attributeEditor",
"string_attribute",
"bool_attribute",
"enum_attribute",
"color_attribute",
"colorf_attribute",
"texture_attribute",
// dummy editors
"contextMenu_editor",
"menu_editor",
"fileOpenDialog_editor",
"colorSelectDialog_editor",
"modalScreen_editor",
0
};
} // gui
} // irr
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment