From 7028cbe09c688437910a25623098762bf0fa592d Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 28 Mar 2016 22:28:34 +1000 Subject: Move Irrlicht to src/others. --- .../tools/GUIEditor/CGUITextureAttribute.h | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/others/irrlicht-1.8.1/tools/GUIEditor/CGUITextureAttribute.h (limited to 'src/others/irrlicht-1.8.1/tools/GUIEditor/CGUITextureAttribute.h') diff --git a/src/others/irrlicht-1.8.1/tools/GUIEditor/CGUITextureAttribute.h b/src/others/irrlicht-1.8.1/tools/GUIEditor/CGUITextureAttribute.h new file mode 100644 index 0000000..6a4fef2 --- /dev/null +++ b/src/others/irrlicht-1.8.1/tools/GUIEditor/CGUITextureAttribute.h @@ -0,0 +1,140 @@ +#ifndef __C_GUI_TEXTURE_ATTRIBUTE_H_INCLUDED__ +#define __C_GUI_TEXTURE_ATTRIBUTE_H_INCLUDED__ + +#include "CGUIAttribute.h" +#include "IGUIEditBox.h" +#include "IGUIImage.h" +#include "IGUIButton.h" +#include "EGUIEditTypes.h" + +namespace irr +{ +namespace gui +{ + + class CGUITextureAttribute : public CGUIAttribute + { + public: + // + CGUITextureAttribute(IGUIEnvironment* environment, IGUIElement *parent, s32 myParentID) : + CGUIAttribute(environment, parent, myParentID), + AttribEditBox(0), AttribImage(0), AttribButton(0) + { + IGUISkin* skin = Environment->getSkin(); + + core::rect r = getAbsolutePosition(); + s32 topy = skin->getFont()->getDimension(L"A").Height + 10; + s32 h = skin->getFont()->getDimension(L"A").Height + 5; + + AttribImage = environment->addImage(0, core::position2di(0, topy), false, this); + AttribImage->setRelativePosition( core::rect(0,topy, r.getWidth() - 5, 100+topy)); + AttribImage->grab(); + AttribImage->setSubElement(true); + AttribImage->setScaleImage(true); + AttribImage->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + + topy += 105; + + core::rect r2(0, topy, r.getWidth() - 15 - skin->getSize(EGDS_CHECK_BOX_WIDTH), topy + h); + core::rect br(r.getWidth() - 10 - skin->getSize(EGDS_CHECK_BOX_WIDTH), topy, r.getWidth(), topy + h); + + AttribEditBox = environment->addEditBox(0, r2, true, this, -1); + AttribEditBox->grab(); + AttribEditBox->setSubElement(true); + AttribEditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + + AttribButton = environment->addButton(br, this, -1, L"..."); + AttribButton->grab(); + AttribButton->setSubElement(true); + AttribButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); + //AttribButton->setSpriteBank(skin->getSpriteBank()); + //AttribButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_FILE), skin->getColor(EGDC_WINDOW_SYMBOL)); + //AttribButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_FILE), skin->getColor(EGDC_WINDOW_SYMBOL), true); + } + + virtual ~CGUITextureAttribute() + { + if (AttribEditBox) + AttribEditBox->drop(); + if (AttribImage) + AttribImage->drop(); + if (AttribButton) + AttribButton->drop(); + } + + virtual bool OnEvent(const SEvent &e) + { + + if (IsEnabled) + { + switch (e.EventType) + { + case EET_GUI_EVENT: + switch (e.GUIEvent.EventType) + { + case EGET_BUTTON_CLICKED: + // button click: open file dialog + if (e.GUIEvent.Caller == AttribButton) + { + //Environment->addGUIElement("textureBrowser", Environment->getRootGUIElement()); + return true; + } + break; + case EGET_FILE_SELECTED: + // file selected: change editbox value and set event + + return true; + case EGET_FILE_CHOOSE_DIALOG_CANCELLED: + + return true; + default: + break; + } + break; + case EET_KEY_INPUT_EVENT: + return true; + default: + break; + } + } + return CGUIAttribute::OnEvent(e); + } + + virtual void setAttrib(io::IAttributes *attribs, u32 attribIndex) + { + AttribEditBox->setText(attribs->getAttributeAsStringW(attribIndex).c_str()); + AttribImage->setImage(attribs->getAttributeAsTexture(Index)); + + CGUIAttribute::setAttrib(attribs, attribIndex); + } + + //! save the attribute and possibly post the event to its parent + virtual bool updateAttrib(bool sendEvent=true) + { + if (!Attribs) + return true; + + Attribs->setAttribute(Index, AttribEditBox->getText()); + core::stringw tmp = Attribs->getAttributeAsStringW(Index); + AttribEditBox->setText(Attribs->getAttributeAsStringW(Index).c_str()); + AttribImage->setImage(Attribs->getAttributeAsTexture(Index)); + + return CGUIAttribute::updateAttrib(sendEvent); + } + + //! Returns the type name of the gui element. + virtual const c8* getTypeName() const + { + return GUIEditElementTypeNames[EGUIEDIT_TEXTUREATTRIBUTE]; + } + + private: + IGUIEditBox* AttribEditBox; + IGUIImage* AttribImage; + IGUIButton* AttribButton; + }; + +} // namespace gui +} // namespace irr + +#endif -- cgit v1.1