Currently I am using TL, so there is one button, TaharezLook/Button. The xml file lists the name, and then the TL dll interprets that and creates a factory object for the button. Then when we want a TL/Button, the factory object creates it. Here's the current line:
Code: Select all
<WindowFactory Name="TaharezLook/Button" />
Now what if we wanted two types of buttons. Well, it isn't that hard! We'd need to create two factory objects, each of which creates a TLButton instance. If we change the code so it supports a separate name to the actual factory type, we'd have this:
Code: Select all
<WindowFactory Name="TaharezLook/Button" />
<WindowFactory Name="TaharezLook/RoundButton" Widget="TaharezLook/Button" />
So with a small change, we've now created two button factories. How to get them looking different? WindowFactory could keep a list of {name,value} string pairs from the xml file. So we'd have it like this:
Code: Select all
<WindowFactory Name="TaharezLook/RoundButton" Widget="TaharezLook/Button" >
<Data Name="NormalImage" Value="TaharezLook/Round1" />
<Data Name="PushedImage" Value="TaharezLook/Round2" />
<Data Name="DisabledColour" Value="0xff808080" />
</WindowFactory>
Ok, the code creates the window factory, then pushes data into it. Now we'd need to change the creation so that the widgets created get a pointer back to their WindowFactory. In that case, the TLButton could then pick off the data:
Code: Select all
if (myFactory->doesExist("NormalImage"))
{
d_middleSectionHover = &iset->getImage(myFactory->getString("NormalImage"));
d_mycolour = myFactory->getInteger("DisabledColour"));
}
else
{
.. hard coded default way
}
In summary, the road to Falagard isn't that rocky at all. Rather than throwing away two implementations, we could gradually migrate them by slowly allowing an override of all the appropriate values. At all points in this process everything still works, it just gets more powerful. Eventually you could merge the two dlls, taking the best implementation of each. For instance sometimes TL assumes a 1x1 image, WL assumes 3x3. So you might end up taking the best of the two. It would be easy to mix and match until this happened, e.g.:
Code: Select all
<WindowFactory Name="MyLook/Button" Widget="TaharezLook/Button" />
... the TL button is better
<WindowFactory Name="MyLook/BigFatMommaButton" Widget="TaharezLook/Button" />
... same with new data driven fields
<WindowFactory Name="MyLook/Scrollbar" Widget="WindowsLook/Scrollbar/>
... but i like the WL scrollbar
Note: This is one of those useless posts where I state something but then don't go ahead and implement it. Still, its a good concept.
