Make new control

There are no stupid questions, just stupid answers.
7 posts Page 1 of 1
avovana
Posts: 13
Joined: Sun Feb 25, 2018 2:32 am
by avovana » Mon Feb 26, 2018 5:26 am
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?
avovana
Posts: 13
Joined: Sun Feb 25, 2018 2:32 am
by avovana » Mon Feb 26, 2018 7:57 am
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:

Code: Select all

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

Code: Select all

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

Code: Select all

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:

Code: Select all

ConsoleDocClass( GuiButtonNewCtrl,

Image

What did I miss?
avovana
Posts: 13
Joined: Sun Feb 25, 2018 2:32 am
by avovana » Mon Feb 26, 2018 8:09 am
I found what I missed.

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

Code: Select all

#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.
avovana
Posts: 13
Joined: Sun Feb 25, 2018 2:32 am
by avovana » Mon Feb 26, 2018 8:51 am
Builded in a "RelWithDebugInfo".
Got more errors:

Image
avovana
Posts: 13
Joined: Sun Feb 25, 2018 2:32 am
by avovana » Mon Feb 26, 2018 10:51 am
Actually, I have 3 errors.
I build it in "Debug", the result is the same:

Image
avovana
Posts: 13
Joined: Sun Feb 25, 2018 2:32 am
by avovana » Tue Feb 27, 2018 7:31 am
Solution.

Additional to:

Code: Select all

DECLARE_CONOBJECT(GuiButtonNewCtrl);


I added some info:

Code: Select all

DECLARE_CATEGORY("Gui Game");
DECLARE_DESCRIPTION("some text");


And it works now!
JeffR
Steering Committee
Steering Committee
Posts: 808
Joined: Tue Feb 03, 2015 9:49 pm
 
by JeffR » Tue Feb 27, 2018 4:01 pm
Ah, yes. I managed to forget about those macros. Glad that you managed to figure it out! That could definitely be better documented.
7 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests