THGraphics External

Here is where the magnanimous folks that create externals post them (.zip archives only please).

THGraphics External

Postby sctell » Sat Feb 26, 2011 11:35 am

Hi,

I have recently been inspired by Lorenz's efforts in scripting a SC interface onto the CG external and thought I would have a go at providing a simple interface to Cocoa's NSBezierPath.

I have made progress and here is my current release of the THGraphics external.

It is my intention in the coming month to add the remaining NSBezierPath functions that will allow the scripter to perform arbitrary drawing within the canvas.

Please post any observations and comments:

THGraphics.zip
(248.18 KiB) Downloaded 335 times
Last edited by sctell on Thu Jan 08, 2015 11:06 am, edited 20 times in total.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby Dan_Kelleher » Mon Feb 28, 2011 10:57 am

Hi Terry,
Super-looking graphics!

I'm using PPC and OSX 10.5.8

If I click on any control, on the card the image disappears; the calls to "clearCanvas" works well.

If I then re-start with a fresh project,
1. Then Click the "ClearCanvas" control --> it works - the image of the six rectangles is gone
2. Then Click the "createCanvas" control --> I get the expected result --> nothing changes (it may work)
3. Then Click on "pretty example?" control --> nothing changes, no image. :cry:

After the call,
get THGraphics("rectangle",tCoords,tFillSpec,tLineSpec,tShadowSpec,tAngle,tRotationPoint)
the SC var "It" contains two lines:

IT_NG.png
IT_NG.png (9.22 KiB) Viewed 16445 times




After the 6 iterations in the script (see image below), and
After the call,
get THGraphics("imageToVar",@tImageVar)
the SuperCard Variable "tImageVar
contains one line:

tImageVar_NG.png
tImageVar_NG.png (4.37 KiB) Viewed 16445 times


HTH,
-Dan


pretty example Script.jpg
pretty example Script.jpg (62.12 KiB) Viewed 16445 times
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby sctell » Mon Feb 28, 2011 11:58 am

Hi,


[NSImage lockedFocusFilpped] is a 10.6 call.

I will see what I can do.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Tue Mar 01, 2011 1:17 am

Dan_Kelleher wrote:I'm using PPC and OSX 10.5.8


I have now removed the [NSImage lockedFocusFlipped] call and also recompiled as a universal binary.


As I am no longer PPC perhaps you would test?

It should work down to 10.5 not sure about 10.4.

Just download the file at the top of this thread.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby Dan_Kelleher » Tue Mar 01, 2011 6:56 am

It all works very smoothly. It's great!
Love the arrows!
I really appreciate your graphic controls-demonstration showing us how to adjust parameters to get desired results.

Thanks for making it accessible to more folks.

The rest of the family here use Intel Macs but Dad's quite happy with what he has, as long as he can keep it running. :cheers:

-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby LorenzT » Tue Mar 01, 2011 7:52 am

Hi Terry

Nice project!
Would it also be possible to rotate an object around its center? (I guess you would have to translate the object before and after the rotation.)

And then I noticed strange artifacts around the lines of a rotated rectangle. Where does this come from? I dont get such artifacts with the CG external.
line.jpg
line.jpg (8.72 KiB) Viewed 16426 times


Lorenz
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: THGraphics External

Postby LorenzT » Tue Mar 01, 2011 8:49 am

Terry

Why does the clearCanvas command produce 646561 bytes?
To reduce the file size of the project you could add the following line to the clearCanvas script:
set the pictureData of cd grc "scCanvas" to none

And why did you decide to produce tiff files with your external?
A similar png file from the cg external is much smaller (~15 kB) compared to 646kB with a tiff file.

Lorenz
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: THGraphics External

Postby sctell » Tue Mar 01, 2011 12:07 pm

LorenzT wrote:Would it also be possible to rotate an object around its center? (I guess you would have to translate the object before and after the rotation.)


If you look in the card script for say rectangle you will see:
Code: Select all
put the currentValue of cd btn "left" + the currentValue of cd btn "width"/2 into item 1 of tRotationPoint--centre of rect
put the currentValue of cd btn "top" + the currentValue of cd btn "height"/2 into item 2 of tRotationPoint

--put the currentValue of cd btn "left" into item 1 of tRotationPoint--topleft of rect
--put the currentValue of cd btn "top" into item 2 of tRotationPoint


You can set the rotation point to any point you wish, unless I am misunderstanding?

LorenzT wrote:And then I noticed strange artifacts around the lines of a rotated rectangle. Where does this come from? I dont get such artifacts with the CG external.


I am sure this is just a setting somewhere in Cocoa, I will find it and update accordingly.

EDITED my post: It is probably this setting NSImageInterpolationHigh which needs setting. Will check.

LorenzT wrote:Why does the clearCanvas command produce 646561 bytes?


I found it, failed to release an NSImage. Will update. Thanks.

LorenzT wrote:And why did you decide to produce tiff files with your external?


If think Tiff is lossless. Is png lossless?

It is easy to change to png if that is better. Opinion?

Does the png in CG not grow significantly when loading into a SC grc as these are Pict data?

Perhaps I should offer an alternative?

pngImageToVar
tiffImageToVar
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby LorenzT » Tue Mar 01, 2011 2:31 pm

Re. Rotation
Apparently I was using an older version of your project where rotation wasn't around the center...

In the new version, however, the following grcs don't appear (anymore):
- curvedArrow
- Star
- Drawing Lines

That's on a MacPro Intel and Mac OS 10.6.6

Re. PNG
According to what I have found on the internet PNG seems to be lossless and the file size of the project doesn't grow much when the png is loaded.

Lorenz
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: THGraphics External

Postby sctell » Tue Mar 01, 2011 11:51 pm

LorenzT wrote:In the new version, however, the following grcs don't appear (anymore):
- curvedArrow
- Star
- Drawing Lines



I have a Macbook Pro Intel 10.6.6 and there are no problems at all (downloaded from this thread)l.

Are you sure you have created a canvas first? Nothing has changed with curvedArrow and star.

Although the Drawing Lines section is incomplete as this is coming under the NSBezierPath Primitive's part of my project and is subject to change.

I should perhaps hide those cards until that section is finished.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Wed Mar 02, 2011 1:53 am

LorenzT wrote:And then I noticed strange artifacts around the lines of a rotated rectangle. Where does this come from? I dont get such artifacts with the CG external.



Having looked at the setting in the externals code I could not see an issue.

I then looked at the grc representing the canvas in SC.

If you set to alphaBlack rather than alpha, it seems to rectify the issue.

Not sure why? but hey it seems to work.

All the best
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby LorenzT » Wed Mar 02, 2011 3:32 am

Now all graphics work again. Maybe I should have restarted SC before posting? :oops:

And the Black Alpha trick resolves the issue with the grey outline.

Thanks!
Lorenz
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: THGraphics External

Postby Dan_Kelleher » Wed Mar 02, 2011 5:11 am

All Parts are working well here; curvedArrows and star included.

PPC & 1.05.8
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby sctell » Wed Mar 02, 2011 5:35 am

LorenzT wrote:And the Black Alpha trick resolves the issue with the grey outline.


I recall there was a discussion on the old Yahoo externals list about premultiplied and TIFF but we never got to the bottom of it other than Premultiplied Black seems to be the answer for TIFF. It seems PICT which is the basis of SC wasn't really designed to handle transparency and SC's implementation of PICT is a proprietary solution.

I will also implement a PNG solution to see how that performs.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Thu Mar 03, 2011 3:01 pm

sctell wrote:
LorenzT wrote:And the Black Alpha trick resolves the issue with the grey outline.


I recall there was a discussion on the old Yahoo externals list about premultiplied and TIFF but we never got to the bottom of it other than Premultiplied Black seems to be the answer for TIFF. It seems PICT which is the basis of SC wasn't really designed to handle transparency and SC's implementation of PICT is a proprietary solution.

I will also implement a PNG solution to see how that performs.


I read somewhere that quartz premultiplies alpha to black by default.

As i recall PNG is lossless as it uses Zlib compression. Png uses sRGB colorspace which may result in color shifts compared to tiff version of same.

Haven't had time to test, but looking forward to it. Hope you'll add ability to clip raster image sources.

DCS

PS: Png format allows for private data... so one could store source data in the png for round trip editing.
Not exactly a trivial task but doable with SC.
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Fri Mar 04, 2011 4:43 am

Hi,

The latest release is at the top of the thread:

It now includes the following functions:

createCanvas
clearCanvas
imageToVar
rectangle
roundedRectangle
oval
regularPolygon
arrow
curvedArrow
star

In addition there is a primitives section with these functions:

bezierPath
releasePath
closePath
stroke
moveToPoint
relativeMoveToPoint
setLineWidth
lineToPoint
relativeLineToPoint
curveToPoint
relativeCurveToPoint
setLineColor
setShadow
setLineCapStyle
setLineJoinStyle

On the primitives page I have linked to Apple's Documentation on NSBezierPath rather than repeat the documentation in SC.

The work continues :)
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Fri Mar 04, 2011 8:00 am

Hi again,

I have had a really busy day.

The list of primitive functions is now:

bezierPath
releasePath
closePath
stroke
fill
moveToPoint
relativeMoveToPoint
setLineWidth
lineToPoint
relativeLineToPoint
curveToPoint
relativeCurveToPoint
setLineColor
setFillColor
setShadow
setLineCapStyle
setLineJoinStyle
removeAllPoints
fillRect
strokeRect
setDefaultLineWidth
setDefaultLineCapStyle
setDefaultLineJoinStyle
strokeLineFromPointToPoint

There has been no change to the shapes section.

No more for a couple of days. :)
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby Dan_Kelleher » Fri Mar 04, 2011 8:43 am

Looks terrific. Thank you Terry,
-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby sctell » Fri Mar 04, 2011 12:00 pm

Hi,

One last post.

gonetriadrr wrote:Hope you'll add ability to clip raster image sources.



Please download the latest update. I have added a "clipImage" routine. There is an example on the last card.

Is this what you were after?

It may still be a little rough around the edges but I wanted to get this out as I am busy for a couple of days.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Fri Mar 04, 2011 1:34 pm

sctell wrote:Hi,

One last post.

gonetriadrr wrote:Hope you'll add ability to clip raster image sources.



Please download the latest update. I have added a "clipImage" routine. There is an example on the last card.

Is this what you were after?

It may still be a little rough around the edges but I wanted to get this out as I am busy for a couple of days.


You have been busy!

Hope to have a look soon. Also very busy. Could be a while.

Thanks!
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Mon Mar 07, 2011 12:14 am

Hi,

Just posted another update.

I have added additional functionality with the following functions:

appendPathWithOvalInRect
appendPathWithRect
appendPathWithRoundedRect
appendPathWithArcFromPoint

rotatePath (this rotates the path, NOT THE CTM)
scalePath (this scales the path, NOT THE CTM)
translatePath (this translates the path, NOT THE CTM)
I implemented these (NOT CTM) because I thought this concept would be easier for all to grasp, including me.

linearGradientInPath
radialGradientInPath

The new download can be found at the top of this thread.

Oh, I have also added an index to get to each function and links to Apple's NSBezierPath documentation.

There is also a link to Apple's Cocoa Drawing documentation which should be a good study for those interested.
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Wed Mar 09, 2011 1:33 pm

Hi Terry,

Haven't had a chance to look over the external yet, but tomorrow looks good.
Curious if color specification is limited to rgb?
Allowing specification in cmyk and lab would be very helpful to me. More intuitive for sure.

Thanks,
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby Dan_Kelleher » Wed Mar 09, 2011 2:53 pm

DCS wrote:
...more intuitive...


I'd like to understand that particular adjective (here) a bit; could you explain briefly or point us in the 'best' direction.

From the [objective-C/]Cocoa drawing guide (p30): "[the] NSColor[a parent object of NSBezierPath] supports RGB, CMYK and Grayscale by default but can support custom colors defined by ICC and Colorsync profiles."

yellow & blue make green,
tested w Crayola,
-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby sctell » Fri Mar 11, 2011 12:20 am

Dan_Kelleher wrote:From the [objective-C/]Cocoa drawing guide (p30): "[the] NSColor[a parent object of NSBezierPath] supports RGB, CMYK and Grayscale by default but can support custom colors defined by ICC and Colorsync profiles."


That is correct but my external has you input the values for NSColor in r,g,b,a format not cmyk.

There are many ways to create an NSColor object in Cocoa.

Examples:

colorWithCalibratedHue:saturation:brightness:alpha:
colorWithCalibratedRed:green:blue:alpha:
colorWithCalibratedWhite:alpha:
colorWithCatalogName:colorName:
colorWithDeviceCyan:magenta:yellow:black:alpha:
colorWithDeviceHue:saturation:brightness:alpha:
colorWithDeviceRed:green:blue:alpha:
colorWithDeviceWhite:alpha:
colorWithCIColor:
colorWithColorSpace:components:count:

Perhaps I should add a means of cmyk?

Here is another Apple link for study:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DrawColor/DrawColor.html%23//apple_ref/doc/uid/10000082i
sctell
 
Posts: 1134
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby Dan_Kelleher » Fri Mar 11, 2011 6:54 am

I can imagine the degree of difficulty that might be for you to do.

Personally, I'm happy with RGB but it seems David is yearning for the option, my understanding being that would be very useful providing a more robust final processing step in rendering, back into SuperCard, SuperCard objects created with his monumental BezierPenTool written entirely in SuperTalk.

He's the image-manipulation guru and probably has ideas about the best way to implement NSColor more broadly from the point of view of the benefits.

BezierPenTool --> SuperCard object(s) --> THGraphics XFcn (or "CG" XFcn") --> 'Pretty-example'-SuperCard-object [with more that a little reliance from the SuperCard Internal's Toolbox to provide the mechanisms for the object's journey(s).]

At least that's my present understanding.

I've just been trying to pay attention to what's happening, best-I-can.

And to think of ways to demo the power of the tools, like use of the saved-state of a single Cocoa/Core Graphics "context" (or perhaps two "contexts" if the limited "stack" mechanism of saving/recalling "contexts" was available.)

And thinking about how, in practice, to usefully combine objects that are created/processed with
Cocoa/Core Graphics XFcns with other types of SuperCard objects like real text fields and with SuperCard functions and abilities like mouseloc() and it's sisters and brothers.

-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Next

Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest

cron