[futurebasic] Re: [FB] CG Context Question

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2011 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Sun, 30 Jan 2011 12:02:41 +1300
Max Taylor wrote:

> Q. What is the scope of a CGContext?

Depends what you mean by 'scope'.

> Q. Are they limited one to a window or is there one for each View within a Window?

There is one for each HIView, but the CGContextRef is available to you only at drawing time, in a handler for {_kEventClassControl, _kEventControlDraw}.


> Q. Is there a limit as to how many CGContexts one can have within any given window?

There's no limit to the number of HIViews.

> Q. Could one have an array of CGContext objects?

Yes, but only for contexts that you explicitly create, such as CGBitmapContexts or CGPDFContexts.

> Since you can "Save" and "Restore" them it does seem like one could have as many as they want but I have not tried that yet.

CGContextSaveGState() pushes the state; CGContextRestoreGState() pops the state. These work on a private stack managed by each CGContextRef. 


> I see (in my mind) a CGContext (internally) as a data structure that holds all of the current "State of The Context" attributes that are used whenever any CG object gets drawn.

Yes.

> Any thoughts or ideas on how any of you have used them in an application?

[1] Drawing to a control (a.k.a HIView) in an event handler. The CGContextRef is made available as a parameter of the event.

case _kEventControlDraw
  dim as CGContextRef  ctx
  fn GetEventParameter( theEvent, _kEventParamCGContextRef, _typeCGContextRef, #0, sizeof( CGContextRef ), #0, @ctx )
  .. your drawing code here

[2] Drawing directly to a window   QDBeginCGContext(); deprecated.

Contexts that you explicitly create:
[3] Drawing to a bitmap   CGBitmapContextCreate()
[4] CGPDFContextCreate()
[5] HIWindowCreateCollapsedDockTileContext()
[6] HIApplicationCreateDockTileContext()

Robert P.