best way for 'lil' extending
Posted: Tue Sep 27, 2005 19:06
I've been using CEGUI for a while, and I quite love it. I am nearing the phase where I need to refactor my current application that I've been working on (as soon as I find a good exorcist) and I really want to do a few things the "right" way that I've been working around.
I am not yet on the 0.4 release, but plan to upgrade in the near future.
My problem is, I don't really understand how I am supposed to extend widgets on a behavior level without having to extend the look and feel.
An example is, I have a "toggle button" which when clicked once, stays down, and when clicked again, pops up. Its just a push button, with a state boolean, and a variable. I also have a group of toggle buttons, that are a lot like radios.
Since I can't subclass the Pushbutton, I've had to do it this way:
Built a general property helper class, that takes an object's memory address, plus a key, to return a value, or takes an object's address, plus a key and value to set a property. (Thats not a CEGUI property, but a property I've added)
To handle the behavoir, I write handleToggleButton... methods into my class that get wired into the events for the PushButton, then they use the general property manager and pass the handle of the button that triggered the event to get/set data for that button.
I am pretty sure there is an easier way to do this sort of thing. I would really like to create a PushButton, but instead of creating a literal PushButton, just create a subclass, that I can cast to in its event handlers, which can be in its own class code - leaving it in every other way a normal Push Button. The prob is I don't know how to do this when I call a function in the window manager to create all my PushButtons.
What is the correct way to extend functionality like this without breaking into a derivation of the Look and Feel? Is there a different way in 0.4?
Thanks
- Paddy
I am not yet on the 0.4 release, but plan to upgrade in the near future.
My problem is, I don't really understand how I am supposed to extend widgets on a behavior level without having to extend the look and feel.
An example is, I have a "toggle button" which when clicked once, stays down, and when clicked again, pops up. Its just a push button, with a state boolean, and a variable. I also have a group of toggle buttons, that are a lot like radios.
Since I can't subclass the Pushbutton, I've had to do it this way:
Built a general property helper class, that takes an object's memory address, plus a key, to return a value, or takes an object's address, plus a key and value to set a property. (Thats not a CEGUI property, but a property I've added)
To handle the behavoir, I write handleToggleButton... methods into my class that get wired into the events for the PushButton, then they use the general property manager and pass the handle of the button that triggered the event to get/set data for that button.
I am pretty sure there is an easier way to do this sort of thing. I would really like to create a PushButton, but instead of creating a literal PushButton, just create a subclass, that I can cast to in its event handlers, which can be in its own class code - leaving it in every other way a normal Push Button. The prob is I don't know how to do this when I call a function in the window manager to create all my PushButtons.
What is the correct way to extend functionality like this without breaking into a derivation of the Look and Feel? Is there a different way in 0.4?
Thanks
- Paddy