avovana Posted February 26, 2018 Share Posted February 26, 2018 Hello everyone!I wonder how to make new control and add it to the GUI Editor.For example, I need to make improved "GuiTreeViewCtrl" - control that have new property. It should take an XML file(that is input thanks to property) and show it.I guess I should inherit from the "GuiTreeViewCtrl" and add this property. But I don't now how to show new control in the GUI Editor.Could someone help me? Quote Link to comment Share on other sites More sharing options...
avovana Posted February 26, 2018 Author Share Posted February 26, 2018 I tried to make "GuiButtonNewCtrl" for example.It is the same as "GuiButtonCtrl":- consist of two files - *.cpp and *.h;- inherited from the "GuiButtonBaseCtrl".So the only difference is a name of a class actually.Here is a GuiButtonNewCtrl.h:#ifndef _GUIBUTTONCTRL_H_ #define _GUIBUTTONCTRL_H_ #ifndef _GUIBUTTONBASECTRL_H_ #include "gui/buttons/guiButtonBaseCtrl.h" #endif class GuiButtonNewCtrl : public GuiButtonBaseCtrl { typedef GuiButtonBaseCtrl Parent; protected: bool mHasTheme; public: DECLARE_CONOBJECT(GuiButtonNewCtrl); GuiButtonNewCtrl(); bool onWake(); void onRender(Point2I offset, const RectI &updateRect); }; #endif //_GUI_BUTTON_CTRL_H Here is a GuiButtonNewCtrl.cpp: #include "platform/platform.h" #include "gui/buttons/GuiButtonNewCtrl.h" #include "console/console.h" #include "console/consoleTypes.h" #include "gfx/gfxDevice.h" #include "gfx/gfxDrawUtil.h" #include "gui/core/guiCanvas.h" #include "gui/core/guiDefaultControlRender.h" IMPLEMENT_CONOBJECT(GuiButtonNewCtrl); ConsoleDocClass( GuiButtonNewCtrl, "@brief The most widely used button class.\n\n" "GuiButtonNewCtrl renders seperately of, but utilizes all of the functionality of GuiBaseButtonCtrl.\n" "This grants GuiButtonNewCtrl the versatility to be either of the 3 button types.\n\n" "@tsexample\n" "// Create a PushButton GuiButtonNewCtrl that calls randomFunction when clicked\n" "%button = new GuiButtonNewCtrl()\n" "{\n" " profile = \"GuiButtonProfile\";\n" " buttonType = \"PushButton\";\n" " command = \"randomFunction();\";\n" "};\n" "@endtsexample\n\n" "@ingroup GuiButtons" ); //----------------------------------------------------------------------------- GuiButtonNewCtrl::GuiButtonNewCtrl() { setExtent(140, 30); mButtonText = StringTable->EmptyString(); } //----------------------------------------------------------------------------- bool GuiButtonNewCtrl::onWake() { if( !Parent::onWake() ) return false; // Button Theme? if( mProfile->constructBitmapArray() >= 36 ) mHasTheme = true; else mHasTheme = false; return true; } //----------------------------------------------------------------------------- void GuiButtonNewCtrl::onRender(Point2I offset, const RectI& updateRect) { bool highlight = mMouseOver; bool depressed = mDepressed; ColorI fontColor = mActive ? ( highlight ? mProfile->mFontColorHL : mProfile->mFontColor ) : mProfile->mFontColorNA; ColorI fillColor = mActive ? ( highlight ? mProfile->mFillColorHL : mProfile->mFillColor ) : mProfile->mFillColorNA; ColorI borderColor = mActive ? ( highlight ? mProfile->mBorderColorHL : mProfile->mBorderColor ) : mProfile->mBorderColorNA; RectI boundsRect(offset, getExtent()); if( !mHasTheme ) { if( mProfile->mBorder != 0 ) renderFilledBorder( boundsRect, borderColor, fillColor, mProfile->mBorderThickness ); else GFX->getDrawUtil()->drawRectFill( boundsRect, fillColor ); } else { S32 indexMultiplier = 1; if( !mActive ) indexMultiplier = 4; else if ( mDepressed || mStateOn ) indexMultiplier = 2; else if ( mMouseOver ) indexMultiplier = 3; renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile ); } Point2I textPos = offset; if( depressed ) textPos += Point2I( 1, 1 ); GFX->getDrawUtil()->setBitmapModulation( fontColor ); renderJustifiedText( textPos, getExtent(), mButtonText ); //render the children renderChildControls( offset, updateRect); } But I got an error: Severity Code Description Project File Line Suppression State Error (active) explicit specialization of member "EngineClassTypeInfo<T, Base>::smDocString [with T=GuiButtonNewCtrl::ThisType, Base=GuiButtonNewCtrl::_ClassBase]" must precede its first use () newFull e:\Vova\projects\Torque3D\Engine\source\gui\buttons\guiButtonNewCtrl.cpp 35 Error points to: ConsoleDocClass( GuiButtonNewCtrl,What did I miss? Quote Link to comment Share on other sites More sharing options...
avovana Posted February 26, 2018 Author Share Posted February 26, 2018 I found what I missed.In a header file I didn't change the name of a guard:#ifndef _GUIBUTTONCTRL_H_ #define _GUIBUTTONCTRL_H_ #ifndef _GUIBUTTONBASECTRL_H_ #include "gui/buttons/guiButtonBaseCtrl.h" #endif So the 1st error is not anymore. But the second - "cannot open file" still exists. Quote Link to comment Share on other sites More sharing options...
avovana Posted February 26, 2018 Author Share Posted February 26, 2018 Builded in a "RelWithDebugInfo".Got more errors: Quote Link to comment Share on other sites More sharing options...
avovana Posted February 26, 2018 Author Share Posted February 26, 2018 Actually, I have 3 errors.I build it in "Debug", the result is the same: Quote Link to comment Share on other sites More sharing options...
avovana Posted February 27, 2018 Author Share Posted February 27, 2018 Solution.Additional to:DECLARE_CONOBJECT(GuiButtonNewCtrl); I added some info: DECLARE_CATEGORY("Gui Game"); DECLARE_DESCRIPTION("some text"); And it works now! Quote Link to comment Share on other sites More sharing options...
JeffR Posted February 27, 2018 Share Posted February 27, 2018 Ah, yes. I managed to forget about those macros. Glad that you managed to figure it out! That could definitely be better documented. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.