Jump to content

Make new control


Recommended Posts

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?

Link to comment
Share on other sites

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:


#include "gui/buttons/guiButtonBaseCtrl.h"

class GuiButtonNewCtrl : public GuiButtonBaseCtrl
  typedef GuiButtonBaseCtrl Parent;
  bool mHasTheme;
  bool onWake();
  void onRender(Point2I offset, const RectI &updateRect);



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"


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"

  "// Create a PushButton GuiButtonNewCtrl that calls randomFunction when clicked\n"
  "%button = new GuiButtonNewCtrl()\n"
  "   profile    = \"GuiButtonProfile\";\n"
  "   buttonType = \"PushButton\";\n"
  "   command    = \"randomFunction();\";\n"

  "@ingroup GuiButtons"


  setExtent(140, 30);
  mButtonText = StringTable->EmptyString();


bool GuiButtonNewCtrl::onWake()
  if( !Parent::onWake() )
     return false;

  // Button Theme?
  if( mProfile->constructBitmapArray() >= 36 )
     mHasTheme = true;
     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 );
        GFX->getDrawUtil()->drawRectFill( boundsRect, fillColor );
     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?

Link to comment
Share on other sites

I found what I missed.

In a header file I didn't change the name of a guard:


#include "gui/buttons/guiButtonBaseCtrl.h"


So the 1st error is not anymore. But the second - "cannot open file" still exists.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...