Radically simplified the whole theming mechanism. Theming can now be done declaratively with less typing, better readability, easier maintenance.

Also fixed some oversights in the existing themes: text was not dimmed in disabled state for segmented controls, text was not dimmed for default buttons in disabled state in HUD (IIRC).
This commit is contained in:
Aparajita Fishman
2010-08-02 18:17:02 -04:00
parent 10c12e7e4d
commit ecbbe57709
2 changed files with 1133 additions and 930 deletions
File diff suppressed because it is too large Load Diff
+129
View File
@@ -219,3 +219,132 @@ function BKLabelFromIdentifier(anIdentifier)
return label;
}
PatternIsVertical = YES,
PatternIsHorizontal = NO;
/*
To create a simple color with a pattern image:
PatternColor(name, width, height)
To create a color with a three part pattern image:
PatternColor(slices, orientation)
where slices is an array of three [name, width, height] arrays,
and orientation is PatternIsVertical or PatternIsHorizontal.
To create a color with a nine part pattern image:
PatternColor(slices);
where slices is an array of nine [name, width, height] arrays.
*/
function PatternColor()
{
if (arguments.length < 3)
{
var slices = arguments[0],
imageSlices = [];
for (var i = 0; i < slices.length; ++i)
{
var slice = slices[i];
imageSlices.push(slice ? [_CPCibCustomResource imageResourceWithName:slice[0] size:CGSizeMake(slice[1], slice[2])] : nil);
}
if (arguments.length == 2)
return [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:imageSlices isVertical:arguments[1]]];
else
return [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:imageSlices]];
}
else if (arguments.length == 3)
{
return [CPColor colorWithPatternImage:[_CPCibCustomResource imageResourceWithName:arguments[0] size:CGSizeMake(arguments[1], arguments[2])]];
}
else
{
return nil;
}
}
function SetThemeValues(object, values)
{
for (var i = 0; i < values.length; ++i)
{
var attributeValueState = values[i],
attribute = attributeValueState[0],
value = attributeValueState[1],
state = attributeValueState[2];
if (state)
[object setValue:value forThemeAttribute:attribute inState:state];
else
[object setValue:value forThemeAttribute:attribute];
}
}
function SetHUDThemeValues(object, values, overrides)
{
for (var i = 0; i < values.length; ++i)
{
var attributeValueState = values[i],
attribute = attributeValueState[0],
value = attributeValueState[1],
state = attributeValueState[2];
if (attribute == "text-color" || attribute == "text-shadow-color")
{
var whiteValue = attribute == "text-color" ? 1.0 : 0.0,
alpha = (state && (state & CPThemeStateDisabled)) ? 0.6 : 1.0;
value = [CPColor colorWithCalibratedWhite:whiteValue alpha:alpha];
}
else if (typeof(value) === "object" && value.hasOwnProperty("isa") && [value isKindOfClass:CPColor])
{
var pattern = [value patternImage];
if (pattern)
{
if ([pattern isThreePartImage] || [pattern isNinePartImage])
{
var slices = [pattern imageSlices],
newSlices = [];
for (var sliceIndex = 0; sliceIndex < slices.length; ++sliceIndex)
{
var slice = slices[sliceIndex],
filename = "HUD/" + [[slice filename] lastPathComponent],
size = [slice size];
newSlices.push([filename, size.width, size.height]);
}
if ([pattern isThreePartImage])
value = PatternColor(newSlices, [pattern isVertical]);
else
value = PatternColor(newSlices);
}
else
{
var filename = "HUD/" + [[pattern filename] lastPathComponent],
size = [pattern size];
value = PatternColor(filename, size.width, size.height);
}
}
}
else if (attribute == "text-shadow-offset")
{
value = CGSizeMake(-1.0, -1.0);
}
if (state)
[object setValue:value forThemeAttribute:attribute inState:state];
else
[object setValue:value forThemeAttribute:attribute];
}
if (overrides)
SetThemeValues(object, overrides);
}