// Draws the bitmap within a special button control. Only a single bitmap is used and the
// button will be drawn in a highlighted mode when the mouse hovers over it or when it
// has been clicked.
//
// Use mTextLocation to choose where within the button the text will be drawn, if at all.
// Use mTextMargin to set the text away from the button sides or from the bitmap.
// Use mButtonMargin to set everything away from the button sides.
// Use mErrorBitmapName to set the name of a bitmap to draw if the main bitmap cannot be found.
// Use mFitBitmapToButton to force the bitmap to fill the entire button extent. Usually used
// with no button text defined.
//
//
#include"platform/platform.h"
#include"gui/buttons/guiIconButtonCtrl.h"
#include"console/console.h"
#include"gfx/gfxDevice.h"
#include"gfx/gfxDrawUtil.h"
#include"console/consoleTypes.h"
#include"gui/core/guiCanvas.h"
#include"gui/core/guiDefaultControlRender.h"
#include"console/engineAPI.h"
staticconstColorIcolorWhite(255,255,255);
staticconstColorIcolorBlack(0,0,0);
IMPLEMENT_CONOBJECT(GuiIconButtonCtrl);
ConsoleDocClass(GuiIconButtonCtrl,
"@brief Draws the bitmap within a special button control. Only a single bitmap is used and the\n"
"button will be drawn in a highlighted mode when the mouse hovers over it or when it\n"
"has been clicked.\n\n"
"@tsexample\n"
"new GuiIconButtonCtrl(TestIconButton)\n"
"{\n"
" buttonMargin = \"4 4\";\n"
" iconBitmap = \"art/gui/lagIcon.png\";\n"
" iconLocation = \"Center\";\n"
" sizeIconToButton = \"0\";\n"
" makeIconSquare = \"1\";\n"
" textLocation = \"Bottom\";\n"
" textMargin = \"-2\";\n"
" autoSize = \"0\";\n"
" text = \"Lag Icon\";\n"
" textID = \"\"STR_LAG\"\";\n"
" buttonType = \"PushButton\";\n"
" profile = \"GuiIconButtonProfile\";\n"
"};\n"
"@endtsexample\n\n"
"@see GuiControl\n"
"@see GuiButtonCtrl\n\n"
"@ingroup GuiCore\n"
);
GuiIconButtonCtrl::GuiIconButtonCtrl()
{
mBitmapName=StringTable->insert("");
mTextLocation=TextLocLeft;
mIconLocation=IconLocLeft;
mTextMargin=4;
mButtonMargin.set(4,4);
mFitBitmapToButton=false;
mMakeIconSquare=false;
mErrorBitmapName=StringTable->insert("");
mErrorTextureHandle=NULL;
mAutoSize=false;
setExtent(140,30);
}
ImplementEnumType(GuiIconButtonTextLocation,
"\n\n"
"@ingroup GuiImages")
{GuiIconButtonCtrl::TextLocNone,"None"},
{GuiIconButtonCtrl::TextLocBottom,"Bottom"},
{GuiIconButtonCtrl::TextLocRight,"Right"},
{GuiIconButtonCtrl::TextLocTop,"Top"},
{GuiIconButtonCtrl::TextLocLeft,"Left"},
{GuiIconButtonCtrl::TextLocCenter,"Center"},
EndImplementEnumType;
ImplementEnumType(GuiIconButtonIconLocation,
"\n\n"
"@ingroup GuiImages")
{GuiIconButtonCtrl::IconLocNone,"None"},
{GuiIconButtonCtrl::IconLocLeft,"Left"},
{GuiIconButtonCtrl::IconLocRight,"Right"},
{GuiIconButtonCtrl::IconLocCenter,"Center"}
EndImplementEnumType;
voidGuiIconButtonCtrl::initPersistFields()
{
addField("buttonMargin",TypePoint2I,Offset(mButtonMargin,GuiIconButtonCtrl),"Margin area around the button.\n");
addField("iconBitmap",TypeFilename,Offset(mBitmapName,GuiIconButtonCtrl),"Bitmap file for the icon to display on the button.\n");
addField("iconLocation",TYPEID<IconLocation>(),Offset(mIconLocation,GuiIconButtonCtrl),"Where to place the icon on the control. Options are 0 (None), 1 (Left), 2 (Right), 3 (Center).\n");
addField("sizeIconToButton",TypeBool,Offset(mFitBitmapToButton,GuiIconButtonCtrl),"If true, the icon will be scaled to be the same size as the button.\n");
addField("makeIconSquare",TypeBool,Offset(mMakeIconSquare,GuiIconButtonCtrl),"If true, will make sure the icon is square.\n");
addField("textLocation",TYPEID<TextLocation>(),Offset(mTextLocation,GuiIconButtonCtrl),"Where to place the text on the control.\n"
addField("textMargin",TypeS32,Offset(mTextMargin,GuiIconButtonCtrl),"Margin between the icon and the text.\n");
addField("autoSize",TypeBool,Offset(mAutoSize,GuiIconButtonCtrl),"If true, the text and icon will be automatically sized to the size of the control.\n");