wxPG: Value from wxColourProperty?

BlitzMax Forums/Brucey's Modules/wxPG: Value from wxColourProperty?

Gabriel(Posted 2008) [#1]
Would anyone happen to know how to get the colour of a wxColourProperty? I've hacked it in by fiddling with the wrapper a little ( didn't need much ) and I can set it just fine, but I can't seem to get it. I've tried getting it as an object pointer and casting to wxColour or a wxColourValueProperty. I've tried getting it as a wxVariant and casting to a wxColour or a wxColourValueProperty. I even tried getting it as a wxVariant and casting it to a ulong or a string ( since these can be both represent colors, it seems. ) I've tried various snippets of code from the website ( including two from the wxPropertyGrid site itself, and one where all the text apart from the code was in chinese ) but I get a memory exception error no matter what.

It must be my expectations are wrong on what I'm getting with these functions, I guess. Perhaps someone with experience of the property grid in another language can point me in the right direction.

EDIT: Forgot to mention. When I get the variant and call GetType() it returns "wxColour" so I don't know why casting it never works.


Gabriel(Posted 2008) [#2]
Argh! Don't you hate it when you spend hours failing to do something and then find the answer just after you ask for help.

The solution was to use the shift operator to cast from wxVariant to wxColour. I've no idea why it wouldn't work any other way. Probably my error, but just in case it saves you any time, I ended up doing it like this :

void bmx_wxpropertygrid_getpropertyvalueascolour(wxPropertyGrid* grid, BBString* prop, int* red, int* green, int* blue) {
	wxVariant v = grid->GetPropertyValue(wxStringFromBBString(prop));
	wxColour c;
	c << v;
	*red=(int)c.Red();
	*green=(int)c.Green();
	*blue=(int)c.Blue();
}


Returning it as a color didn't work either. Again, probably just my stupidity, but I don't need a perfect solution, I only need to hack in a few extra functions.


Brucey(Posted 2008) [#3]
Hmm... I seem to have covered everything except for colour :-)

Will sort it out.
Is there anything else that needs looked at?

I've been working through a pile of methods yesterday (did about 60 of them), but it's a fairly long, slow process. (read, tedious!).


Brucey(Posted 2008) [#4]
Righty, I've added GetPropertyValueAsColour() and GetPropertyValueAsColourByName(), both returning a wxColour.
Also, SetPropertyValueColour() and SetPropertyValueColourByName(), accepting a wxColour.

While I was there, I added a GetRGB() and GetRGBA() method to wxColour, which take Int Var arguments for populating.

Finally, have implemented wxColourProperty, to go with the wxSystemColourProperty property.


Gabriel(Posted 2008) [#5]
Thanks Brucey, that's very kind of you. I really don't think there's anything else I need, and I wasn't prompting you to add anything. You've already done a ton of work on this and I only needed a few extras so I thought I'd rather do it myself rather than pester you for them.

I don't have a specific set of uses, I'm just adding things to the property grid as I add features to the game engine, so anything which needs to be edited in the level editor gets put onto the PG. As I say, if there is anything else, it'll only be something small which I can do myself. You've already done the hard bit, and you've got a bunch of helper functions for converting between string formats as well.

Again, thanks for the new color stuff.