GuiMLText button
by Alex Huck · in Torque Game Engine · 01/06/2007 (6:16 pm) · 3 replies
Hi, I'm trying to make a highlighted-text button control as a hello-world to GUI Coding on the C++ Side,
using guiTextButtonCtrl as a base I got it very close to what I wanted, perfect except I want it to be formatted with a font.
The line of code which renders the text is:
renderJustifiedText(textPos, mBounds.extent, mButtonText);
I'm looking at replacing it with
dglDrawTextN("ArialBold", offset, mButtonText, 10, "0 0 0 255");
Though I get this error
Currently with renderJustifiedText it does everything I want except for font
Full code below:
.h
using guiTextButtonCtrl as a base I got it very close to what I wanted, perfect except I want it to be formatted with a font.
The line of code which renders the text is:
renderJustifiedText(textPos, mBounds.extent, mButtonText);
I'm looking at replacing it with
dglDrawTextN("ArialBold", offset, mButtonText, 10, "0 0 0 255");
Though I get this error
..\engine\gui\Populous\guiHighlightedTextButtonCtrl.cc(79) : error C2665: 'dglDrawTextN' : none of the 2 overloads could convert all the argument types
../engine\dgl/dgl.h(132): could be 'U32 dglDrawTextN(GFont *,const Point2I &,const UTF16 *,U32,const ColorI *,const U32,F32)'
../engine\dgl/dgl.h(134): or 'U32 dglDrawTextN(GFont *,const Point2I &,const UTF8 *,U32,const ColorI *,const U32,F32)'
while trying to match the argument list '(const char [10], Point2I, Point2I, int, const char [10])'Currently with renderJustifiedText it does everything I want except for font
Full code below:
.h
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _GUIHLTBUTTONCTRL_H_
#define _GUIHLTBUTTONCTRL_H_
#ifndef _GUIBUTTONBASECTRL_H_
#include "gui/controls/guiButtonBaseCtrl.h"
#endif
class GuiHighlightedTextButtonCtrl : public GuiButtonBaseCtrl
{
typedef GuiButtonBaseCtrl Parent;
protected:
bool mHasTheme;
public:
DECLARE_CONOBJECT(GuiHighlightedTextButtonCtrl);
GuiHighlightedTextButtonCtrl();
bool onWake();
void onRender(Point2I offset, const RectI &updateRect);
};
#endif //_GUI_BUTTON_CTRL_HAbout the author
#2
there are a couple things. If you want to set color it wants a reference, it actually isnt a required argument.
secondly, it wants a pointer to UTF16, or UTF8 for the position. Point2I wont work. And lastly, "ArialBold" is not a GFont. You can set these things through script when you create the object.
//edit: spelling
01/06/2007 (8:37 pm)
From looking at it...UTF16 textPos[2] = { offset.x, offset.y }; //Default position of text, in the center of the control
dglSetBitmapModulation( fontColor );
ColorI color(0,0,0,255);
//renderJustifiedText(textPos, mBounds.extent, mButtonText);
dglDrawTextN(mProfile->mFont, offset, textPos, 10, &color);there are a couple things. If you want to set color it wants a reference, it actually isnt a required argument.
secondly, it wants a pointer to UTF16, or UTF8 for the position. Point2I wont work. And lastly, "ArialBold" is not a GFont. You can set these things through script when you create the object.
// fill color opaque = false; fillColor = "255 255 255"; fillColorHL = "128 128 128"; fillColorNA = "244 244 244"; // border color border = false; borderColor = "190 190 190"; borderColorHL = "156 156 156"; borderColorNA = "64 64 64"; bevelColorHL = "255 255 255"; bevelColorLL = "0 0 0"; // font fontType = "Arial"; fontSize = 16; fontColor = "32 32 32"; fontColorHL = "32 100 100"; fontColorNA = "0 0 0"; tab = true; canKeyFocus = true;
//edit: spelling
#3
That explains a lot of things, like for instance, why mProfile->Variable is so common in the gui cc files, and where all these mProfile->Variables are coming from..
I love learning new stuff about this engine, it's been(being) a fun journey for me (And probably a long boring trip full of newb-questions for the rest of this forum) :)
01/07/2007 (7:35 pm)
Many many thanks, you opened my eyes to the usage of mProfile, I was looking at mProfile in the code and saying to myself, Hmm, where is that defined? (I found it in the parent class GuiControl). After some research I figured out all I need to know about Profiles, very handy.. In the GUI editor I always see Profile drop down list, and never understood what it did until now. Now all my needs are filled, many thanks again.That explains a lot of things, like for instance, why mProfile->Variable is so common in the gui cc files, and where all these mProfile->Variables are coming from..
I love learning new stuff about this engine, it's been(being) a fun journey for me (And probably a long boring trip full of newb-questions for the rest of this forum) :)
Torque Owner Alex Huck
Default Studio Name
//----------------------------------------------------------------------------- // Torque Game Engine // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- #include "console/console.h" #include "dgl/dgl.h" #include "console/consoleTypes.h" #include "platform/platformAudio.h" #include "gui/core/guiCanvas.h" #include "gui/Populous/guiHighlightedTextButtonCtrl.h" #include "gui/core/guiDefaultControlRender.h" //#include "gui/controls/guiMLTextCtrl.h" #include "gui/controls/guiMLTextCtrl.h" #include "gui/containers/guiScrollCtrl.h" #include "core/frameAllocator.h" #include "core/unicode.h" IMPLEMENT_CONOBJECT(GuiHighlightedTextButtonCtrl); GuiHighlightedTextButtonCtrl::GuiHighlightedTextButtonCtrl() { mBounds.extent.set(140, 30); mButtonText = StringTable->insert(""); } bool GuiHighlightedTextButtonCtrl::onWake() { if( !Parent::onWake() ) return false; // Button Theme? if( mProfile->constructBitmapArray() >= 36 ) mHasTheme = true; else mHasTheme = false; return true; } //-------------------------------------------------------------------------- void GuiHighlightedTextButtonCtrl::onRender(Point2I offset, const RectI& updateRect) { bool highlight = mMouseOver; bool depressed = mDepressed; ColorI fontColor = mActive ? (highlight ? mProfile->mFontColorHL : mProfile->mFontColor) : mProfile->mFontColorNA; ColorI backColor = mActive ? mProfile->mFillColor : mProfile->mFillColorNA; ColorI borderColor = mActive ? mProfile->mBorderColor : mProfile->mBorderColorNA; RectI boundsRect(offset, mBounds.extent); if( mProfile->mBorder != 0 && !mHasTheme ) { if (mDepressed || mStateOn) renderFilledBorder( boundsRect, mProfile->mBorderColorHL, mProfile->mFillColorHL ); else renderFilledBorder( boundsRect, mProfile->mBorderColor, mProfile->mFillColor ); } else if( mHasTheme ) { S32 indexMultiplier = 1; if ( mMouseOver ) indexMultiplier = 3; else if ( mDepressed || mStateOn ) indexMultiplier = 2; else if ( !mActive ) indexMultiplier = 4; } Point2I textPos = offset; //Default position of text, in the center of the control dglSetBitmapModulation( fontColor ); //renderJustifiedText(textPos, mBounds.extent, mButtonText); dglDrawTextN("ArialBold", offset, textPos, 10, "0 0 0 255"); //render the children renderChildControls( offset, updateRect); }