|
| 1 | +// |
| 2 | +// File: GLString.h |
| 3 | +// (Originally StringTexture.h) |
| 4 | +// |
| 5 | +// Abstract: Uses Quartz to draw a string into an OpenGL texture |
| 6 | +// |
| 7 | +// Version: 1.1 - Minor enhancements and bug fixes. |
| 8 | +// 1.0 - Original release. |
| 9 | +// |
| 10 | +// |
| 11 | +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") |
| 12 | +// in consideration of your agreement to the following terms, and your use, |
| 13 | +// installation, modification or redistribution of this Apple software |
| 14 | +// constitutes acceptance of these terms. If you do not agree with these |
| 15 | +// terms, please do not use, install, modify or redistribute this Apple |
| 16 | +// software. |
| 17 | +// |
| 18 | +// In consideration of your agreement to abide by the following terms, and |
| 19 | +// subject to these terms, Apple grants you a personal, non - exclusive |
| 20 | +// license, under Apple's copyrights in this original Apple software ( the |
| 21 | +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple |
| 22 | +// Software, with or without modifications, in source and / or binary forms; |
| 23 | +// provided that if you redistribute the Apple Software in its entirety and |
| 24 | +// without modifications, you must retain this notice and the following text |
| 25 | +// and disclaimers in all such redistributions of the Apple Software. Neither |
| 26 | +// the name, trademarks, service marks or logos of Apple Inc. may be used to |
| 27 | +// endorse or promote products derived from the Apple Software without specific |
| 28 | +// prior written permission from Apple. Except as expressly stated in this |
| 29 | +// notice, no other rights or licenses, express or implied, are granted by |
| 30 | +// Apple herein, including but not limited to any patent rights that may be |
| 31 | +// infringed by your derivative works or by other works in which the Apple |
| 32 | +// Software may be incorporated. |
| 33 | +// |
| 34 | +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO |
| 35 | +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
| 36 | +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A |
| 37 | +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION |
| 38 | +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
| 39 | +// |
| 40 | +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
| 41 | +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 42 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 43 | +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION |
| 44 | +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER |
| 45 | +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR |
| 46 | +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 47 | +// |
| 48 | +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. |
| 49 | +// |
| 50 | + |
| 51 | +#import <Cocoa/Cocoa.h> |
| 52 | +#import <OpenGL/gl.h> |
| 53 | +#import <OpenGL/glext.h> |
| 54 | +#import <OpenGL/OpenGL.h> |
| 55 | +#import <OpenGL/CGLContext.h> |
| 56 | + |
| 57 | +@interface NSBezierPath (RoundRect) |
| 58 | ++ (NSBezierPath *)bezierPathWithRoundedRect:(NSRect)rect cornerRadius:(float)radius; |
| 59 | + |
| 60 | +- (void)appendBezierPathWithRoundedRect:(NSRect)rect cornerRadius:(float)radius; |
| 61 | +@end |
| 62 | + |
| 63 | +@interface GLString : NSObject { |
| 64 | + CGLContextObj cgl_ctx; // current context at time of texture creation |
| 65 | + GLuint texName; |
| 66 | + NSSize texSize; |
| 67 | + |
| 68 | + NSAttributedString * string; |
| 69 | + NSColor * textColor; // default is opaque white |
| 70 | + NSColor * boxColor; // default transparent or none |
| 71 | + NSColor * borderColor; // default transparent or none |
| 72 | + BOOL staticFrame; // default in NO |
| 73 | + BOOL antialias; // default to YES |
| 74 | + NSSize marginSize; // offset or frame size, default is 4 width 2 height |
| 75 | + NSSize frameSize; // offset or frame size, default is 4 width 2 height |
| 76 | + float cRadius; // Corner radius, if 0 just a rectangle. Defaults to 4.0f |
| 77 | + |
| 78 | + BOOL requiresUpdate; |
| 79 | +} |
| 80 | + |
| 81 | +// this API requires a current rendering context and all operations will be performed in regards to thar context |
| 82 | +// the same context should be current for all method calls for a particular object instance |
| 83 | + |
| 84 | +// designated initializer |
| 85 | +- (id) initWithAttributedString:(NSAttributedString *)attributedString withTextColor:(NSColor *)color withBoxColor:(NSColor *)color withBorderColor:(NSColor *)color; |
| 86 | + |
| 87 | +- (id) initWithString:(NSString *)aString withAttributes:(NSDictionary *)attribs withTextColor:(NSColor *)color withBoxColor:(NSColor *)color withBorderColor:(NSColor *)color; |
| 88 | + |
| 89 | +// basic methods that pick up defaults |
| 90 | +- (id) initWithString:(NSString *)aString withAttributes:(NSDictionary *)attribs; |
| 91 | +- (id) initWithAttributedString:(NSAttributedString *)attributedString; |
| 92 | + |
| 93 | +- (void) dealloc; |
| 94 | + |
| 95 | +- (GLuint) texName; // 0 if no texture allocated |
| 96 | +- (NSSize) texSize; // actually size of texture generated in texels, (0, 0) if no texture allocated |
| 97 | + |
| 98 | +- (NSColor *) textColor; // get the pre-multiplied default text color (includes alpha) string attributes could override this |
| 99 | +- (NSColor *) boxColor; // get the pre-multiplied box color (includes alpha) alpha of 0.0 means no background box |
| 100 | +- (NSColor *) borderColor; // get the pre-multiplied border color (includes alpha) alpha of 0.0 means no border |
| 101 | +- (BOOL) staticFrame; // returns whether or not a static frame will be used |
| 102 | + |
| 103 | +- (NSSize) frameSize; // returns either dynamc frame (text size + margins) or static frame size (switch with staticFrame) |
| 104 | + |
| 105 | +- (NSSize) marginSize; // current margins for text offset and pads for dynamic frame |
| 106 | + |
| 107 | +- (void) genTexture; // generates the texture without drawing texture to current context |
| 108 | +- (void) drawWithBounds:(NSRect)bounds; // will update the texture if required due to change in settings (note context should be setup to be orthographic scaled to per pixel scale) |
| 109 | +- (void) drawAtPoint:(NSPoint)point; |
| 110 | + |
| 111 | +// these will force the texture to be regenerated at the next draw |
| 112 | +- (void) setMargins:(NSSize)size; // set offset size and size to fit with offset |
| 113 | +- (void) useStaticFrame:(NSSize)size; // set static frame size and size to frame |
| 114 | +- (void) useDynamicFrame; // set static frame size and size to frame |
| 115 | + |
| 116 | +- (void) setString:(NSAttributedString *)attributedString; // set string after initial creation |
| 117 | +- (void) setString:(NSString *)aString withAttributes:(NSDictionary *)attribs; // set string after initial creation |
| 118 | + |
| 119 | +- (void) setTextColor:(NSColor *)color; // set default text color |
| 120 | +- (void) setBoxColor:(NSColor *)color; // set default text color |
| 121 | +- (void) setBorderColor:(NSColor *)color; // set default text color |
| 122 | + |
| 123 | +- (BOOL) antialias; |
| 124 | +- (void) setAntialias:(bool)request; |
| 125 | + |
| 126 | +@end |
| 127 | + |
0 commit comments