diff options
| author | Mirrorbot <mirrorbot@cogarr.net> | 2025-12-27 17:53:06 -0600 |
|---|---|---|
| committer | Mirrorbot <mirrorbot@cogarr.net> | 2025-12-27 17:53:06 -0600 |
| commit | 71e94ee161447b84c0eaabf6567f8fa62262cd3e (patch) | |
| tree | 391064cc6173a6fe75069af2fdc1978af12f623e /tools/GUIEditor/CGUITextureAttribute.h | |
| download | irrlicht-master.tar.gz irrlicht-master.tar.bz2 irrlicht-master.zip | |
Diffstat (limited to 'tools/GUIEditor/CGUITextureAttribute.h')
| -rw-r--r-- | tools/GUIEditor/CGUITextureAttribute.h | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/tools/GUIEditor/CGUITextureAttribute.h b/tools/GUIEditor/CGUITextureAttribute.h new file mode 100644 index 0000000..6a4fef2 --- /dev/null +++ b/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<s32> 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<s32>(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<s32> r2(0, topy, r.getWidth() - 15 - skin->getSize(EGDS_CHECK_BOX_WIDTH), topy + h);
+ core::rect<s32> 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
|
