Jump to content

Make new control


avovana

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:

#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,

62lYKdH.png


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:

#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.

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.

Guest
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...