Game Development Community

dev|Pro Game Development Curriculum

GuiSliderCtrl Modifications

by Daniel Allessi · 03/19/2005 (2:51 pm) · 2 comments

Download Code File

In GuiSliderCtrl.h line 28 add:
bool mAutoSnap;
StringTableEntry mFormat;

In GuiSliderCtrl.cc line 25 add:
mAutoSnap = false;
mFormat = StringTable->insert("%1.3f");

In GuiSliderCtrl.cc initPersistFields, add the following before endGroup("Slider");
addField("autoSnap", TypeBool,   Offset(mAutoSnap, GuiSliderCtrl));
addField("format",   TypeString, Offset(mFormat,   GuiSliderCtrl));

In onMouseDown, add the following at the top
if(mAutoSnap) return;

Later, change
if ((event.modifier & SI_SHIFT) && mTicks > 2) {

to

if ((event.modifier & SI_SHIFT) || mAutoSnap) {

Finally in onRender, change
dSprintf(buf,sizeof(buf),"%0.3f",mValue);

to

dSprintf(buf,sizeof(buf),mFormat,mValue);
I started using this change in my project since I needed things that snapped to integer boundaries in my GUI. Enjoy.