1{%mainunit appkit.pas} 2(* 3 NSGraphicsContext.h 4 Application Kit 5 Copyright (c) 1997-2004, Apple Computer, Inc. 6 All rights reserved. 7*) 8 9{$ifdef HEADER} 10{$ifndef NSGRAPHICSCONTEXT_PAS_H} 11{$define NSGRAPHICSCONTEXT_PAS_H} 12 13{$include AppKitDefines.inc} 14{$include NSGraphics.inc} 15 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 16 {.$endif} 17 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 18 {.$endif} 19 20//APPKIT_EXTERN NSString *NSGraphicsContextDestinationAttributeName; // Can be an instance of NSWindow, NSMutableData, NSBitmapImageRep, or NSURL. 21//APPKIT_EXTERN NSString *NSGraphicsContextRepresentationFormatAttributeName; // Specifies destination file format 22//APPKIT_EXTERN NSString *NSGraphicsContextPSFormat; 23//APPKIT_EXTERN NSString *NSGraphicsContextPDFFormat; 24type 25 NSImageInterpolation = ( 26 NSImageInterpolationDefault, 27 NSImageInterpolationNone, 28 NSImageInterpolationLow, 29 NSImageInterpolationHigh 30 ); 31 32 33{$endif} 34{$endif} 35 36{$ifdef FORWARD} 37 NSGraphicsContext = class; 38 39{$endif} 40 41{$ifdef CLASSES} 42{$ifndef NSGRAPHICSCONTEXT_PAS_C} 43{$define NSGRAPHICSCONTEXT_PAS_C} 44 45{$include AppKitDefines.inc} 46{$include NSGraphics.inc} 47 48 { NSGraphicsContext } 49 50 NSGraphicsContext = class(NSObject) 51 public 52 class function getClass: lobjc.id; override; 53 // Instantiates from an appropriate concrete subclass depending on NSGraphicsContextDestinationAttributeName 54 // attribute 55 constructor graphicsContextWithAttributes(_attributes: CFDictionaryRef); 56 // Convenience cover method for [NSGraphicsContext graphicsContextWithAttributes:[NSDictionary 57 // dictionaryWithObject:<NSWindow instance> forKey:NSGraphicsContextDestinationAttributeName]] 58 constructor graphicsContextWithWindow(_window: lobjc.id {NSWindow}); 59 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 60 // Convenience cover method for [NSGraphicsContext graphicsContextWithAttributes:[NSDictionary 61 // dictionaryWithObject:<NSBitmapImageRep instance> forKey:NSGraphicsContextDestinationAttributeName]]. 62 // Only NSBitmapImageRep instances with isPlanar == NO are supported. 63 constructor graphicsContextWithBitmapImageRep(_bitmapRep: lobjc.id {NSBitmapImageRep}); 64 // Instantiates from an arbitrary graphicsPort (usually CGContextRef). initialFlippedState 65 // is used to determine the return value from -isFlipped when no view is focused in 66 // the context. 67 constructor graphicsContextWithGraphicsPort_flipped(_graphicsPort: Pointer; _initialFlippedState: LongBool); 68 {.$endif} 69 // Setting and identifying the current context in the thread 70 constructor currentContext; 71 class procedure setCurrentContext(_context: lobjc.id {NSGraphicsContext}); 72 // Convenience cover method for [[NSGraphicsContext currentContext] isDrawingToScreen] 73 class function currentContextDrawingToScreen: LongBool; 74 // Graphics state controls 75 // Calls -saveGraphicsContext, and pushes the current context on per-thread stack. 76 // It's functional equivalent of PSgsave 77 class procedure saveGraphicsState_; 78 // Pops a context from per-thread stack, makes it current, and calls -resotreGraphicsContext. 79 // It's functional equivalent of PSgrestore 80 class procedure restoreGraphicsState_; 81 // Makes gState's context current, and resets graphics state. The gState must be created 82 // in the calling thread 83 class procedure setGraphicsState(_gState: Integer); 84 // Returns attributes used to create this instance 85 function attributes: CFDictionaryRef; 86 // Testing the drawing destination 87 function isDrawingToScreen: LongBool; 88 // Controlling the context 89 procedure saveGraphicsState; 90 procedure restoreGraphicsState; 91 procedure flushGraphics; 92 // Focus Stack support (abstract) 93 function focusStack: Pointer; 94 procedure setFocusStack(_stack: Pointer); 95 // Platform specific drawing context (usually CGContextRef) 96 function graphicsPort: Pointer; 97 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 98 // Returns the flip state of the receiver. The state is determined by messaging -isFlipped 99 // to the focus view in the context. If no view has focus, returns NO unless the receiver 100 // is instantiated via graphicsContextWithGraphicsPort:drawingToScreen:flipped: with 101 // initialFlippedState == YES. 102 function isFlipped: LongBool; 103 {.$endif} 104 procedure setShouldAntialias(_antialias: LongBool); 105 function shouldAntialias: LongBool; 106 procedure setImageInterpolation(_interpolation: NSImageInterpolation); 107 function imageInterpolation: NSImageInterpolation; 108 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2} 109 procedure setPatternPhase(_phase: NSPoint); 110 function patternPhase: NSPoint; 111 {.$endif} 112 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 113 procedure setCompositingOperation(_operation: NSCompositingOperation); 114 function compositingOperation: NSCompositingOperation; 115 {.$endif} 116 function CIContext: lobjc.id;{CIContext} 117 end; 118 119 {.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 120 {.$endif} 121{$endif} 122{$endif} 123 124{$ifdef IMPLEMENTATION} 125const 126 StrNSGraphicsContext_NSGraphicsContext = 'NSGraphicsContext'; 127 StrNSGraphicsContext_graphicsContextWithAttributes = 'graphicsContextWithAttributes:'; 128 StrNSGraphicsContext_graphicsContextWithWindow = 'graphicsContextWithWindow:'; 129 StrNSGraphicsContext_graphicsContextWithBitmapImageRep = 'graphicsContextWithBitmapImageRep:'; 130 StrNSGraphicsContext_graphicsContextWithGraphicsPort_flipped = 'graphicsContextWithGraphicsPort:flipped:'; 131 StrNSGraphicsContext_currentContext = 'currentContext'; 132 StrNSGraphicsContext_setCurrentContext = 'setCurrentContext:'; 133 StrNSGraphicsContext_currentContextDrawingToScreen = 'currentContextDrawingToScreen'; 134 StrNSGraphicsContext_saveGraphicsState = 'saveGraphicsState'; 135 StrNSGraphicsContext_restoreGraphicsState = 'restoreGraphicsState'; 136 StrNSGraphicsContext_setGraphicsState = 'setGraphicsState:'; 137 StrNSGraphicsContext_attributes = 'attributes'; 138 StrNSGraphicsContext_isDrawingToScreen = 'isDrawingToScreen'; 139 StrNSGraphicsContext_flushGraphics = 'flushGraphics'; 140 StrNSGraphicsContext_focusStack = 'focusStack'; 141 StrNSGraphicsContext_setFocusStack = 'setFocusStack:'; 142 StrNSGraphicsContext_graphicsPort = 'graphicsPort'; 143 StrNSGraphicsContext_isFlipped = 'isFlipped'; 144 145 StrNSGraphicsContext_setShouldAntialias = 'setShouldAntialias:'; 146 StrNSGraphicsContext_shouldAntialias = 'shouldAntialias'; 147 StrNSGraphicsContext_setImageInterpolation = 'setImageInterpolation:'; 148 StrNSGraphicsContext_imageInterpolation = 'imageInterpolation'; 149 StrNSGraphicsContext_setPatternPhase = 'setPatternPhase:'; 150 StrNSGraphicsContext_patternPhase = 'patternPhase'; 151 StrNSGraphicsContext_setCompositingOperation = 'setCompositingOperation:'; 152 StrNSGraphicsContext_compositingOperation = 'compositingOperation'; 153 154 StrNSGraphicsContext_CIContext = 'CIContext'; 155 156{ NSGraphicsContext } 157 158class function NSGraphicsContext.getClass: lobjc.id; 159begin 160 Result := objc_getClass(StrNSGraphicsContext_NSGraphicsContext); 161end; 162 163constructor NSGraphicsContext.graphicsContextWithAttributes(_attributes: CFDictionaryRef); 164type 165 TmsgSendWrapper = function (param1: lobjc.id; param2: SEL;_attributes: CFDictionaryRef): lobjc.id; cdecl; 166var 167 vmethod: TmsgSendWrapper; 168begin 169 ClassID := getClass(); 170 vmethod := TmsgSendWrapper(@objc_msgSend); 171 Handle := vmethod(ClassID, sel_registerName(PChar(StrNSGraphicsContext_graphicsContextWithAttributes)), _attributes); 172end; 173 174constructor NSGraphicsContext.graphicsContextWithWindow(_window: lobjc.id {NSWindow}); 175type 176 TmsgSendWrapper = function (param1: lobjc.id; param2: SEL;_window: lobjc.id {NSWindow}): lobjc.id; cdecl; 177var 178 vmethod: TmsgSendWrapper; 179begin 180 ClassID := getClass(); 181 vmethod := TmsgSendWrapper(@objc_msgSend); 182 Handle := vmethod(ClassID, sel_registerName(PChar(StrNSGraphicsContext_graphicsContextWithWindow)), _window); 183end; 184 185{.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 186constructor NSGraphicsContext.graphicsContextWithBitmapImageRep(_bitmapRep: lobjc.id {NSBitmapImageRep}); 187type 188 TmsgSendWrapper = function (param1: lobjc.id; param2: SEL;_bitmapRep: lobjc.id {NSBitmapImageRep}): lobjc.id; cdecl; 189var 190 vmethod: TmsgSendWrapper; 191begin 192 ClassID := getClass(); 193 vmethod := TmsgSendWrapper(@objc_msgSend); 194 Handle := vmethod(ClassID, sel_registerName(PChar(StrNSGraphicsContext_graphicsContextWithBitmapImageRep)), _bitmapRep); 195end; 196 197constructor NSGraphicsContext.graphicsContextWithGraphicsPort_flipped(_graphicsPort: Pointer; _initialFlippedState: LongBool); 198type 199 TmsgSendWrapper = function (param1: lobjc.id; param2: SEL;_graphicsPort: Pointer; _initialFlippedState: LongBool): lobjc.id; cdecl; 200var 201 vmethod: TmsgSendWrapper; 202begin 203 ClassID := getClass(); 204 vmethod := TmsgSendWrapper(@objc_msgSend); 205 Handle := vmethod(ClassID, sel_registerName(PChar(StrNSGraphicsContext_graphicsContextWithGraphicsPort_flipped)), _graphicsPort, _initialFlippedState); 206end; 207 208{.$endif} 209constructor NSGraphicsContext.currentContext; 210type 211 TmsgSendWrapper = function (param1: lobjc.id; param2: SEL): lobjc.id; cdecl; 212var 213 vmethod: TmsgSendWrapper; 214begin 215 ClassID := getClass(); 216 vmethod := TmsgSendWrapper(@objc_msgSend); 217 Handle := vmethod(ClassID, sel_registerName(PChar(StrNSGraphicsContext_currentContext))); 218end; 219 220class procedure NSGraphicsContext.setCurrentContext(_context: lobjc.id {NSGraphicsContext}); 221type 222 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_context: lobjc.id {NSGraphicsContext}); cdecl; 223var 224 vmethod: TmsgSendWrapper; 225begin 226 vmethod := TmsgSendWrapper(@objc_msgSend); 227 vmethod(getClass, sel_registerName(PChar(StrNSGraphicsContext_setCurrentContext)), _context); 228end; 229 230class function NSGraphicsContext.currentContextDrawingToScreen: LongBool; 231begin 232 Result := {%H-}LongBool(objc_msgSend(getClass, sel_registerName(PChar(StrNSGraphicsContext_currentContextDrawingToScreen)), [])); 233end; 234 235class procedure NSGraphicsContext.saveGraphicsState_; 236begin 237 objc_msgSend(getClass, sel_registerName(PChar(StrNSGraphicsContext_saveGraphicsState)), []); 238end; 239 240class procedure NSGraphicsContext.restoreGraphicsState_; 241begin 242 objc_msgSend(getClass, sel_registerName(PChar(StrNSGraphicsContext_restoreGraphicsState)), []); 243end; 244 245class procedure NSGraphicsContext.setGraphicsState(_gState: Integer); 246type 247 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_gState: Integer); cdecl; 248var 249 vmethod: TmsgSendWrapper; 250begin 251 vmethod := TmsgSendWrapper(@objc_msgSend); 252 vmethod(getClass, sel_registerName(PChar(StrNSGraphicsContext_setGraphicsState)), _gState); 253end; 254 255function NSGraphicsContext.attributes: CFDictionaryRef; 256begin 257 Result := CFDictionaryRef(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_attributes)), [])); 258end; 259 260function NSGraphicsContext.isDrawingToScreen: LongBool; 261begin 262 Result := {%H-}LongBool(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_isDrawingToScreen)), [])); 263end; 264 265procedure NSGraphicsContext.saveGraphicsState; 266begin 267 objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_saveGraphicsState)), []); 268end; 269 270procedure NSGraphicsContext.restoreGraphicsState; 271begin 272 objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_restoreGraphicsState)), []); 273end; 274 275procedure NSGraphicsContext.flushGraphics; 276begin 277 objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_flushGraphics)), []); 278end; 279 280function NSGraphicsContext.focusStack: Pointer; 281begin 282 Result := Pointer(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_focusStack)), [])); 283end; 284 285procedure NSGraphicsContext.setFocusStack(_stack: Pointer); 286type 287 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_stack: Pointer); cdecl; 288var 289 vmethod: TmsgSendWrapper; 290begin 291 vmethod := TmsgSendWrapper(@objc_msgSend); 292 vmethod(Handle, sel_registerName(PChar(StrNSGraphicsContext_setFocusStack)), _stack); 293end; 294 295function NSGraphicsContext.graphicsPort: Pointer; 296begin 297 Result := Pointer(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_graphicsPort)), [])); 298end; 299 300{.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 301function NSGraphicsContext.isFlipped: LongBool; 302begin 303 Result := {%H-}LongBool(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_isFlipped)), [])); 304end; 305 306{.$endif} 307procedure NSGraphicsContext.setShouldAntialias(_antialias: LongBool); 308type 309 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_antialias: LongBool); cdecl; 310var 311 vmethod: TmsgSendWrapper; 312begin 313 vmethod := TmsgSendWrapper(@objc_msgSend); 314 vmethod(Handle, sel_registerName(PChar(StrNSGraphicsContext_setShouldAntialias)), _antialias); 315end; 316 317function NSGraphicsContext.shouldAntialias: LongBool; 318begin 319 Result := {%H-}LongBool(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_shouldAntialias)), [])); 320end; 321 322procedure NSGraphicsContext.setImageInterpolation(_interpolation: NSImageInterpolation); 323type 324 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_interpolation: NSImageInterpolation); cdecl; 325var 326 vmethod: TmsgSendWrapper; 327begin 328 vmethod := TmsgSendWrapper(@objc_msgSend); 329 vmethod(Handle, sel_registerName(PChar(StrNSGraphicsContext_setImageInterpolation)), _interpolation); 330end; 331 332function NSGraphicsContext.imageInterpolation: NSImageInterpolation; 333begin 334 Result := NSImageInterpolation(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_imageInterpolation)), [])); 335end; 336 337{.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2} 338procedure NSGraphicsContext.setPatternPhase(_phase: NSPoint); 339type 340 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_phase: NSPoint); cdecl; 341var 342 vmethod: TmsgSendWrapper; 343begin 344 vmethod := TmsgSendWrapper(@objc_msgSend); 345 vmethod(Handle, sel_registerName(PChar(StrNSGraphicsContext_setPatternPhase)), _phase); 346end; 347 348function NSGraphicsContext.patternPhase: NSPoint; 349begin 350 objc_msgSend_stret(@Result, Handle, sel_registerName(PChar(StrNSGraphicsContext_patternPhase)), []); 351end; 352 353{.$endif} 354{.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4} 355procedure NSGraphicsContext.setCompositingOperation(_operation: NSCompositingOperation); 356type 357 TmsgSendWrapper = procedure (param1: lobjc.id; param2: SEL;_operation: NSCompositingOperation); cdecl; 358var 359 vmethod: TmsgSendWrapper; 360begin 361 vmethod := TmsgSendWrapper(@objc_msgSend); 362 vmethod(Handle, sel_registerName(PChar(StrNSGraphicsContext_setCompositingOperation)), _operation); 363end; 364 365function NSGraphicsContext.compositingOperation: NSCompositingOperation; 366begin 367 Result := NSCompositingOperation(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_compositingOperation)), [])); 368end; 369 370{.$endif} 371function NSGraphicsContext.CIContext: lobjc.id; 372begin 373 Result := lobjc.id(objc_msgSend(Handle, sel_registerName(PChar(StrNSGraphicsContext_CIContext)), [])); 374end; 375 376{$endif} 377