Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

[Cocoa] Using CoreGraphics in Canvas.Paint with child controls (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Escaped or non-escaped path in a dragitem?
Next thread: Re: Documentation (FROM: [ANN] iBasic)


Re: Documentation (FROM: [ANN] iBasic)   -   Garth Hjelte
  [Cocoa] Using CoreGraphics in Canvas.Paint with child controls   -  
   Re: [Cocoa] Using CoreGraphics in Canvas.Paint with child controls   -  

[Cocoa] Using CoreGraphics in Canvas.Paint with child controls
Date: 29.09.11 20:28 (Thu, 29 Sep 2011 15:28:15 -0400)
From:

Here's a tip to those of you exploring using CoreGraphics to do your

on-screen drawing where your Canvas also has child controls:


If you use commands like TranslateCTM and ScaleCTM, you must wrap your

code in balanced calls to SaveGState and RestoreGState. In this example,

I'm using the excellent MacOSLib:


Paint (g as graphics)


dim context as CoreGraphics.CGContext


context=new CoreGraphics.CGContextGraphicsPort(g)


'Save the state

context.SaveGState


'Move to the offset

context.TranslateCTM(xOffset, yOffset)


'Do some drawing here

...


'Restore the state

context.RestoreGState


End


I.e., you must return your context to the exact state it was in when you

entered the event. If you do not, any controls that are the child of the

Canvas control will be offset, scaled, or worse by the transformations

you've executed. They will still respond to clicks in their correct

positions, but they will not draw correctly.


For the sadists in the audience, you can also have some fun with this code

in your Paint event:


Paint (g as graphics)


dim context as CoreGraphics.CGContext


context=new CoreGraphics.CGContextGraphicsPort(g)


'Sadistically restore the state

context.RestoreGState


End


...which (apparently) undoes some set up that the RB framework does before

triggering the Paint event.


Eric M. Williams

Oxalyn

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: [Cocoa] Using CoreGraphics in Canvas.Paint with child controls
Date: 29.09.11 20:40 (Thu, 29 Sep 2011 15:40:57 -0400)
From:

On Thu, 29 Sep 2011 15:28:15 -0400, <<email address removed>> wrote:

> For the sadists in the audience, you can also have some fun with this

code

> in your Paint event:

>

> Paint (g as graphics)

>

> dim context as CoreGraphics.CGContext

>

> context=new CoreGraphics.CGContextGraphicsPort(g)

>

> 'Sadistically restore the state

> context.RestoreGState

>

> End

>

> ...which (apparently) undoes some set up that the RB framework does

before

> triggering the Paint event.


Here is a particularly amusing example. Make a window, set it to Live

Resize, throw some controls into it, and place THIS in the window's Paint

event:


dim context as CoreGraphics.CGContext


context=new CoreGraphics.CGContextGraphicsPort(g)


context.RestoreGState


context.RestoreGState


context.RestoreGState


context.RestoreGState


context.RotateCTM .1


return



Then, run the project and resize the window for 30 seconds or so. Try not

to get dizzy! Note that the project must be run in Cocoa.


Eric M. Williams

Oxalyn

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>