Home » U++ Library support » Look and Chameleon Technology » A little theming
Re: A little theming [message #18649 is a reply to message #18647] |
Tue, 14 October 2008 14:39 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
Well, I've bodged it. The problems:
1- As above, you have to add code to serialize the look based on it's type.
2- The reason the style was being ignored was that you can't just create a ChStyle and expect it to work, it needs to registered properly with Upp. This is normally done by the CH_STYLE macro, but you can also do it by copying an existing ChStyle before altering it. It may also be possible to use ChRegisterStyle__ directly.
Below is the code I used. There is a bit more bodging with StringStreams because for some reason PNGRaster and PNGEncoder are slightly incompatible.
Personally I would avoid supporting saving themes, and just create a sensible file format than can be edited externally.
enum {
ImageLookType = 0,
ColorLookType
};
void SerializeLook(Stream &s, Value &v) {
int type;
if (s.IsStoring()) {
if(IsType<Color>(v)) {
Color c = v;
type = ColorLookType;
s % type % c;
}
else if(IsType<Image>(v)) {
type = ImageLookType;
s % type;
StringStream png;
Image img = v;
PNGEncoder().Save(png, img);
s % (String)png;
Point p1 = img.GetHotSpot();
Point p2 = img.Get2ndSpot();
s % p1 % p2;
}
}
else {
s % type;
if (type == ImageLookType) {
String png;
s % png;
StringStream str(png);
Image img = PNGRaster().Load(str);
ASSERT(!IsNull(img));
Point p1;
Point p2;
s % p1 % p2;
ImageBuffer ib(img);
ib.SetHotSpot(p1);
ib.Set2ndSpot(p2);
v = (Image)ib;
}
else if (type == ColorLookType) {
Color c;
s % c;
ASSERT(!IsNull(c));
v = c;
}
}
};
void Theme::ButtonStyle::Serialize(Stream& s)
{
if (s.IsLoading())
d = Button::StyleNormal(); // Make sure style is initialised
s % d.cancel % d.exit % d.focusmargin;
for (int i = 0; i < 4; i++) {
SerializeLook(s, d.look[i]);
}
}
[Updated on: Tue, 14 October 2008 14:43] Report message to a moderator
|
|
|
|
|
A little theming
|
|
|
Re: A little theming
By: captainc on Wed, 01 October 2008 21:58
|
|
|
Re: A little theming
By: yoco on Thu, 02 October 2008 06:34
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Fri, 03 October 2008 17:30
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: unodgs on Fri, 03 October 2008 19:35
|
|
|
Re: A little theming
By: mirek on Fri, 03 October 2008 19:59
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Mon, 06 October 2008 09:03
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Sat, 11 October 2008 08:22
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Sat, 11 October 2008 08:29
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Sat, 11 October 2008 20:19
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Sun, 12 October 2008 11:04
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mrjt on Tue, 14 October 2008 13:14
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mrjt on Tue, 14 October 2008 14:39
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mrjt on Wed, 15 October 2008 17:41
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mrjt on Fri, 17 October 2008 00:04
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: chickenk on Sat, 18 October 2008 09:10
|
|
|
Re: A little theming
By: chickenk on Sat, 18 October 2008 09:51
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mrjt on Mon, 20 October 2008 10:51
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: unodgs on Thu, 23 October 2008 21:06
|
|
|
Re: A little theming
By: tojocky on Fri, 24 October 2008 07:59
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: unodgs on Fri, 24 October 2008 14:53
|
|
|
Re: A little theming
By: tojocky on Sat, 25 October 2008 11:31
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Fri, 31 October 2008 14:34
|
|
|
Re: A little theming
By: Infausto on Fri, 06 March 2009 21:01
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: Didier on Sun, 24 May 2009 11:33
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: tojocky on Sat, 25 October 2008 11:40
|
|
|
Re: A little theming
By: mirek on Fri, 31 October 2008 14:40
|
|
|
Re: A little theming
By: mirek on Sat, 11 October 2008 08:23
|
|
|
Re: A little theming
By: Didier on Sun, 24 May 2009 12:11
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Fri, 26 June 2009 13:34
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mirek on Tue, 07 July 2009 20:05
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: Alboni on Thu, 27 August 2015 13:46
|
|
|
Re: A little theming
By: Sgifan on Mon, 01 March 2010 19:52
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: Sgifan on Wed, 03 March 2010 21:20
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: Sgifan on Thu, 04 March 2010 21:19
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
|
|
|
Re: A little theming
By: mrjt on Thu, 01 April 2010 13:36
|
|
|
Re: A little theming
By: Sgifan on Fri, 05 March 2010 10:01
|
|
|
Re: A little theming
By: Alboni on Thu, 27 August 2015 14:25
|
|
|
Re: A little theming
By: Alboni on Thu, 27 August 2015 14:35
|
Goto Forum:
Current Time: Thu Mar 28 20:04:17 CET 2024
Total time taken to generate the page: 0.00990 seconds
|