1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Source/QuartzUtils.h Fri Mar 07 11:43:02 2008 -0800
1.3 @@ -0,0 +1,70 @@
1.4 +/* This code is based on Apple's "GeekGameBoard" sample code, version 1.0.
1.5 + http://developer.apple.com/samplecode/GeekGameBoard/
1.6 + Copyright © 2007 Apple Inc. Copyright © 2008 Jens Alfke. All Rights Reserved.
1.7 +
1.8 + Redistribution and use in source and binary forms, with or without modification, are permitted
1.9 + provided that the following conditions are met:
1.10 +
1.11 + * Redistributions of source code must retain the above copyright notice, this list of conditions
1.12 + and the following disclaimer.
1.13 + * Redistributions in binary form must reproduce the above copyright notice, this list of
1.14 + conditions and the following disclaimer in the documentation and/or other materials provided
1.15 + with the distribution.
1.16 +
1.17 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
1.18 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1.19 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
1.20 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.21 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1.22 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1.23 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
1.24 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.25 +*/
1.26 +#import <Quartz/Quartz.h>
1.27 +
1.28 +
1.29 +/** Constants for various commonly used colors. */
1.30 +extern CGColorRef kBlackColor, kWhiteColor,
1.31 + kTranslucentGrayColor, kTranslucentLightGrayColor,
1.32 + kAlmostInvisibleWhiteColor,
1.33 + kHighlightColor;
1.34 +
1.35 +
1.36 +/** Moves a layer from one superlayer to another, without changing its position onscreen. */
1.37 +void ChangeSuperlayer( CALayer *layer, CALayer *newSuperlayer, int index );
1.38 +
1.39 +/** Removes a layer from its superlayer without any fade-out animation. */
1.40 +void RemoveImmediately( CALayer *layer );
1.41 +
1.42 +/** Convenience for creating a CATextLayer. */
1.43 +CATextLayer* AddTextLayer( CALayer *superlayer,
1.44 + NSString *text, NSFont* font,
1.45 + enum CAAutoresizingMask align );
1.46 +
1.47 +
1.48 +/** Loads an image or pattern file into a CGImage or CGPattern.
1.49 + If the name begins with "/", it's interpreted as an absolute filesystem path.
1.50 + Otherwise, it's the name of a resource that's looked up in the app bundle.
1.51 + The image must exist, or an assertion-failure exception will be raised!
1.52 + Loaded images/patterns are cached in memory, so subsequent calls with the same name
1.53 + are very fast.
1.54 + The caller must NOT release the result, since it's retained in the cache. */
1.55 +CGImageRef GetCGImageNamed( NSString *name );
1.56 +CGColorRef GetCGPatternNamed( NSString *name );
1.57 +
1.58 +/** Loads image data from the pasteboard into a CGImage. */
1.59 +CGImageRef GetCGImageFromPasteboard( NSPasteboard *pb );
1.60 +
1.61 +/** Creates a CGPattern from a CGImage. Caller must release it. */
1.62 +CGPatternRef CreateImagePattern( CGImageRef image );
1.63 +
1.64 +/** Creates a CGColor that draws the given CGImage as a pattern. Caller must release it. */
1.65 +CGColorRef CreatePatternColor( CGImageRef image );
1.66 +
1.67 +/** Returns the alpha value of a single pixel in a CGImage, scaled to a particular size. */
1.68 +float GetPixelAlpha( CGImageRef image, CGSize imageSize, CGPoint pt );
1.69 +
1.70 +/** Returns the center point of a CGRect. */
1.71 +static inline CGPoint GetCGRectCenter( CGRect rect ) {
1.72 + return CGPointMake(CGRectGetMidX(rect),CGRectGetMidY(rect));
1.73 +}
1.74 \ No newline at end of file