OK
I played around with the library, and I'm liking the fact that its so small that it is rather easy to customize the library to fit my needs. What I'm working on right now is to be able to control the fonts by means of scripting. Currently, the over/not over colors are hard coded. I want them to be scriptable.
So, what im trying to do, is to be able to define a "style template" for the text in certain situations. For example, I want to be able to do something like this:
Code: Select all
// BetaGUI template overlays
template element TextArea(bgui.button.caption)
{
font_name StarWars
char_height 300
colour_top 0.5 0.5 0.5
colour_bottom 0.5 0.5 0.5
}
template element TextArea(bgui.button.caption.over)
{
font_name StarWars
char_height 400
colour_top 0.7 0.7 0.7
colour_bottom 0.5 0.5 0.5
}
I started implementing this, but have encountered a problem :
Overlay templates are not "deltas" - they are absolute definitions. Which means that when the template is created, the default values are placed as well, and when i use overlay's CopyFromTemplate method, they get copied over as well, meaning that the position & size of my overlay will also be changed, whereas I just want the style.
So, I decided to do this manually, and change Widget's over() method (the rest will follow of course) The code :
Code: Select all
if (a && mHasActiveState && mMainOverlay)
{
mMainOverlay->setMaterialName(mMaterialName + ".over");
if (mCaptionOverlay)
{
mCaptionOverlay->setParameter("colour_top",
Ogre::StringConverter::toString(Ogre::ColourValue(1.0, 0.96, 0.76, 1.0)));
mCaptionOverlay->setParameter("colour_bottom",
Ogre::StringConverter::toString(Ogre::ColourValue(1.0, 0.96, 0.76, 1.00)));
}
}
Is now
Code: Select all
if (a && mHasActiveState && mMainOverlay)
{
mMainOverlay->setMaterialName(mMaterialName + ".over");
if (mCaptionOverlay)
{
try
{
Ogre::OverlayElement* templateOverlay = Ogre::OverlayManager::getSingleton().
getOverlayElement("bgui.caption.over", true);
Ogre::OverlayElement* defaultOverlay = Ogre::OverlayManager::getSingleton().
createOverlayElement("TextArea", "DefaultTemplateTextArea", true);
for (int i=0; i<templateOverlay->getParameters().size(); i++)
{
Ogre::String name = templateOverlay->getParameters()[i].name;
Ogre::String templateValue = templateOverlay->getParameter(name);
Ogre::String defaultValue = defaultOverlay->getParameter(name);
if (defaultValue.compare(templateValue) != 0)
{
mCaptionOverlay->setParameter(name, templateOverlay->getParameter(name));
}
}
}
catch (...)
{
mCaptionOverlay->setParameter("colour_top",
Ogre::StringConverter::toString(Ogre::ColourValue(1.0, 0.96, 0.76, 1.0)));
mCaptionOverlay->setParameter("colour_bottom",
Ogre::StringConverter::toString(Ogre::ColourValue(1.0, 0.96, 0.76, 1.00)));
}
}
}
(Code is still in debugging/research state - has hard coded stuff etc, but is rather easy to refine when i work out my problems)
This works (only things defined in the template get set), except that the call for defaultOverlay's getParameter with font_name gives me an access violation error. I tried iterating over its parameters to see that it has a font_name parameters and it reports that it does. Once i get around this, it will work and we will be able to scriptably set font styles for widgets.
If anyone knows why this happens, i think this could be a good addition to BetaGUI...