Revision: 5849
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5849&view=rev
Author:   hofman
Date:     2009-10-05 13:01:34 +0000 (Mon, 05 Oct 2009)

Log Message:
-----------
avoid some code duplication in color comparison

Modified Paths:
--------------
    trunk/NSColor_SKExtensions.m

Modified: trunk/NSColor_SKExtensions.m
===================================================================
--- trunk/NSColor_SKExtensions.m        2009-10-05 12:51:03 UTC (rev 5848)
+++ trunk/NSColor_SKExtensions.m        2009-10-05 13:01:34 UTC (rev 5849)
@@ -41,47 +41,38 @@
 
 @implementation NSColor (SKExtensions)
 
-typedef union _SKHSBAInt {
-    struct {
-        uint8_t h;
-        uint8_t s;
-        uint8_t b;
-        uint8_t a;
-    } hsba;
-    uint32_t uintValue;
-} SKHSBAInt;
+- (uint32_t)uint32HSBAValue {
+    NSColor *rgbColor = [self 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+    if (rgbColor) {
+        CGFloat h = 0.0, s = 0.0, b = 0.0, a = 0.0;
+        [rgbColor getHue:&h saturation:&s brightness:&b alpha:&a];
+        union _ {
+            struct {
+                uint8_t h;
+                uint8_t s;
+                uint8_t b;
+                uint8_t a;
+            } hsba;
+            uint32_t uintValue;
+        } u;
+        u.hsba.h = (uint8_t)(h * 255);
+        u.hsba.s = (uint8_t)(s * 255);
+        u.hsba.b = (uint8_t)(b * 255);
+        u.hsba.a = (uint8_t)(a * 255);
+        return CFSwapInt32HostToBig(u.uintValue);
+    }
+    return 0;
+}
 
 - (NSComparisonResult)colorCompare:(NSColor *)aColor {
-    NSColor *rgbColor1 = [self 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
-    NSColor *rgbColor2 = [aColor 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
-    if (rgbColor1 && rgbColor2) {
-        CGFloat h1 = 0.0, s1 = 0.0, b1 = 0.0, a1 = 0.0, h2 = 0.0, s2 = 0.0, b2 
= 0.0, a2 = 0.0;
-        [rgbColor1 getHue:&h1 saturation:&s1 brightness:&b1 alpha:&a1];
-        [rgbColor2 getHue:&h2 saturation:&s2 brightness:&b2 alpha:&a2];
-        SKHSBAInt u1, u2;
-        u1.hsba.h = (uint8_t)(h1 * 255);
-        u1.hsba.s = (uint8_t)(s1 * 255);
-        u1.hsba.b = (uint8_t)(b1 * 255);
-        u1.hsba.a = (uint8_t)(a1 * 255);
-        u2.hsba.h = (uint8_t)(h2 * 255);
-        u2.hsba.s = (uint8_t)(s2 * 255);
-        u2.hsba.b = (uint8_t)(b2 * 255);
-        u2.hsba.a = (uint8_t)(a2 * 255);
-        uint32_t value1 = CFSwapInt32HostToBig(u1.uintValue);
-        uint32_t value2 = CFSwapInt32HostToBig(u2.uintValue);
-        if (value1 < value2)
-            return NSOrderedAscending;
-        else if (value1 > value2)
-            return NSOrderedDescending;
-        else
-            return NSOrderedSame;
-    } else if (rgbColor1) {
-        return NSOrderedDescending;
-    } else if (rgbColor2) {
+    uint32_t value1 = [self uint32HSBAValue];
+    uint32_t value2 = [aColor uint32HSBAValue];
+    if (value1 < value2)
         return NSOrderedAscending;
-    } else {
+    else if (value1 > value2)
+        return NSOrderedDescending;
+    else
         return NSOrderedSame;
-    }
 }
 
 + (id)scriptingRgbaColorWithDescriptor:(NSAppleEventDescriptor *)descriptor {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to