Hello,
not so experienced with cocoa
i need little help to draw in Cocoa :
a line , with thickness, dash and arrow
and a circle
even plot a point.
Sincerely
Glomph
Cocoa: how to do Line, Circle, Dash & Arrow?
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Cocoa: how to do Line, Circle, Dash & Arrow?
In Tips n Tricks: http://www.purebasic.fr/english/viewtop ... 12&t=54161
Arrows: http://www.purebasic.fr/english/viewtop ... 13&t=41593
Arrows: http://www.purebasic.fr/english/viewtop ... 13&t=41593
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Cocoa: how to do Line, Circle, Dash & Arrow?
Hi IdeasVacuum,
thanks for the hint, but that stuff i use since years,
it is a bit slow.
I found out that cocoa can do this much faster and in better quality.
A line in cocoa i got out of Wilberts code ([PB Cocoa] Methods, Tips & Tricks)
about a filled roundbox.
This the rest i am stuck.
Sincerely
glomph
thanks for the hint, but that stuff i use since years,
it is a bit slow.
I found out that cocoa can do this much faster and in better quality.
A line in cocoa i got out of Wilberts code ([PB Cocoa] Methods, Tips & Tricks)
about a filled roundbox.
This the rest i am stuck.
Sincerely
glomph
Re: Cocoa: how to do Line, Circle, Dash & Arrow?
You can Google for "NSBezierPath Class Reference" .
It's the document from Apple describing all methods.
Here's a modified example with line width and dash
To draw a circle you need bezierPathWithOvalInRect: or appendBezierPathWithOvalInRect:
It's the document from Apple describing all methods.
Here's a modified example with line width and dash
Code: Select all
Dim LineDashPattern.CGFloat(3)
LineDashPattern(0) = 9
LineDashPattern(1) = 6
LineDashPattern(2) = 3
LineDashPattern(3) = 6
LineWidth.CGFloat = 3
CocoaMessage(0, 0, "NSBezierPath setDefaultLineWidth:@", @LineWidth)
; *** Create image and draw onto it ***
CreateImage(0, 300, 200, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(0))
Crayons = CocoaMessage(0, CocoaMessage(0, 0, "NSColorList colorListNamed:$", @"Crayons"), "retain")
ColorGreen = CocoaMessage(0, 0, "NSColor greenColor")
ColorBrown = CocoaMessage(0, 0, "NSColor brownColor")
ColorMocha = CocoaMessage(0, Crayons, "colorWithKey:$", @"Mocha")
CocoaMessage(0, ColorMocha, "setStroke"); set stroke color to Mocha
Gradient = CocoaMessage(0, 0, "NSGradient alloc"); create gradient from green to brown
CocoaMessage(@Gradient, Gradient, "initWithStartingColor:", ColorGreen, "endingColor:", ColorBrown)
CocoaMessage(0, Gradient, "autorelease")
GradientAngle.CGFloat = 315
Rect.NSRect
Rect\origin\x = 5
Rect\origin\y = 5
Rect\size\width = 290
Rect\size\height = 190
RadiusX.CGFloat = 20
RadiusY.CGFloat = 20
Path = CocoaMessage(0, 0, "NSBezierPath bezierPathWithRoundedRect:@", @Rect, "xRadius:@", @RadiusX, "yRadius:@", @RadiusY)
Phase.CGFloat = 0
CocoaMessage(0, Path, "setLineDash:", @LineDashPattern(), "count:", 4, "phase:@", @Phase)
CocoaMessage(0, Gradient, "drawInBezierPath:", Path, "angle:@", @GradientAngle)
CocoaMessage(0, Path, "stroke")
StopDrawing()
; *** Show the result ***
If OpenWindow(0, 0, 0, 320, 220, "Drawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 300, 200, ImageID(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Cocoa: how to do Line, Circle, Dash & Arrow?
Hi Wilbert,
thanks for that!
I hoped for for a snippet like that,
now i would get through.
Sincerely
glomph
thanks for that!
I hoped for for a snippet like that,
now i would get through.

Sincerely
glomph