GuiBitmapTickCtrl
by JeffH · 05/27/2013 (12:48 pm) · 3 comments
This is my first <real> resource. A couple of years ago I just gave some methods in TS that were not that useful. However, to give back, I figured why not share this small but cool thing that I made.
This class basically allows you to have your standard bitmap control but with the ability to process script updates. Note: This does require modification to the engine.
The ticks are set to not be processed whenever the object is created. You must override the script method provided and add this:
This will allow it to be processed. To turn off ticks simply just set true to be false.
Engine Code:
Anyways, make a new file called GuiBitmapTickCtrl.h and paste this code into it:
And now the c++:
Now, here is the script that you will have to implement, just place it in core/main.cs or something that is done before gui controls are created:
--------------------------------------------
This was very very simple to code, but for non c++ programmers who like script, this may be helpful.
Enjoy!
~ Jeff
This class basically allows you to have your standard bitmap control but with the ability to process script updates. Note: This does require modification to the engine.
The ticks are set to not be processed whenever the object is created. You must override the script method provided and add this:
%this.setTick(true);
This will allow it to be processed. To turn off ticks simply just set true to be false.
Engine Code:
Anyways, make a new file called GuiBitmapTickCtrl.h and paste this code into it:
//-----------------------------------------------------------------------------
// guiBitmapTickCtrl.h
//
// Copyright (c) Jeff Hutchinson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GUIBITMAPTICKCTRL_
#define _GUIBITMAPTICKCTRL_
#ifndef _GUIBITMAPCTRL_H_
#include "gui/controls/guiBitmapCtrl.h"
#endif
#ifndef _ITICKABLE_H_
#include "core/iTickable.h"
#endif
class GuiBitmapCtrl;
class GuiBitmapTickCtrl : public GuiBitmapCtrl, public virtual ITickable
{
typedef GuiBitmapCtrl Parent;
public:
GuiBitmapTickCtrl();
bool onAdd();
void onRemove();
virtual void interpolateTick(F32 delta);
virtual void processTick();
virtual void advanceTime(F32 timeDelta);
DECLARE_CONOBJECT(GuiBitmapTickCtrl);
DECLARE_CALLBACK(void, onUpdate, ());
};
#endif // _GUIBITMAPTICKCTRL_And now the c++:
//-----------------------------------------------------------------------------
// guiBitmapTickCtrl.cpp
//
// Copyright (c) 2013 Jeff Hutchinson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// Jeff:
//
// This class renders a normal bitmap just like GuiBitmapCtrl
// However, it also gives script a chance to update based upon engine ticks.
// we only make use of process ticks to keep processing power down from
// going back and forth from c++ to the scripting engine. It will also
// update at a constant rate without framerate, so we do not have to worry
// about controlling speed based upon frames.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "guiBitmapTickCtrl.h"
#include "console/engineAPI.h"
IMPLEMENT_CONOBJECT(GuiBitmapTickCtrl);
IMPLEMENT_CALLBACK( GuiBitmapTickCtrl, onUpdate, void, (), (),
"Called once every 32ms if this object is set to process ticks.\n\n"
"In order to set process ticks, use this:\n"
"tsexample\n"
"function GuiBitmapTickCtrl::onAdd(%this)\n"
"{\n"
" %this.setTick(true);\n"
"}\n"
"endtsexample\n"
);
GuiBitmapTickCtrl::GuiBitmapTickCtrl()
{
}
bool GuiBitmapTickCtrl::onAdd()
{
if (!Parent::onAdd())
return false;
return true;
}
void GuiBitmapTickCtrl::onRemove()
{
Parent::onRemove();
}
// Jeff: this is where we update our scripting logic.
void GuiBitmapTickCtrl::processTick()
{
onUpdate_callback();
}
void GuiBitmapTickCtrl::interpolateTick(F32 delta)
{
}
void GuiBitmapTickCtrl::advanceTime(F32 delta)
{
}
DefineEngineMethod(GuiBitmapTickCtrl, setTick, void, (bool tick), (false),
"Brief toggles the onUpdate callback.\n\n")
{
object->setProcessTicks(tick);
}Now, here is the script that you will have to implement, just place it in core/main.cs or something that is done before gui controls are created:
// Jeff: whenever this type of control is called to process render
// updates per tick, this is the method that is used as a callback.
// This method should be overridden.
function GuiBitmapTickCtrl::onUpdate(%this)
{
// Jeff: to be overridden.
}
function GuiBitmapTickCtrl::onAdd(%this)
{
// Jeff: to be overridden.
%this.setTick(false);
}--------------------------------------------
This was very very simple to code, but for non c++ programmers who like script, this may be helpful.
Enjoy!
~ Jeff
About the author
19 year old who loves programming with Torque3D!

Torque Owner Kevin Mitchell
12 CatBlack Studios