The declare in the title can be used in COCOA to set line patterns (dotted, dashed etc)…
Does anyone have a snippet that does the same thing for WINDOWS?
Here is how I use the declare in OSX
Dim lengths(-1) As Double
Dim x As Integer
Dim lengthArray As MemoryBlock
Declare Sub CGContextSetLineDash Lib "Cocoa" ( context As Integer, phase As Single, lengths As Ptr, count As UInt32)
x=g.penwidth
Select Case pattern_id
Case BorderDotted
lengths=Array(Ceil(x/2.),x*2.) ' dotted line [.......]
Case borderDashed
lengths=Array(x*8.,x*4.) ' dashed line [- - - -]
Case Else
pattern_id=BorderSolid
End Select
//
If pattern_id<>BorderSolid Then
lengthArray= zz_CFloatArray(lengths)
If lengthArray Is Nil Then Return
CGContextSetLineDash g.handle( g.HandleTypeCGContextRef ),start_at,lengthArray,lengths.Ubound+1
Else
CGContextSetLineDash g.handle( g.HandleTypeCGContextRef ),0,Nil,0 ' solid line
End If
My current project has ONE declare keeping it from being “x-plat”, and this is the one
I am using a Canvas… the declare in my first post creates a “brush” in OSX, and I know (and confirmed by above response) that something most likey exists for windows.
Drawing a dotted or dashed line in “pure xojo code” is VERY VERY SLOW (compared)
[quote=165580:@Dave S]I am using a Canvas… the declare in my first post creates a “brush” in OSX, and I know (and confirmed by above response) that something most likey exists for windows.
Drawing a dotted or dashed line in “pure xojo code” is VERY VERY SLOW (compared)
dim gfx as new GdiPlusGraphics( g.Handle( Graphics.HandleTypeHDC ) )
dim brush as new GdiPlusSolidBrush(new GdiPlusColor( Alpha, col.Red, col.Green, col.Blue ))
that is the “no mention of how to implement the GDIPLUS objects”
Some time ago, there was some code floating around for faking a dashed line… I realize that a declare is the best solution, but you may end up having to resort to faking it…
The biggest problem with x-plat nowadays, is feature parity. Mobile developers have the same issue, where Apple has pumped up the iOS toolbox far quicker than Google, making it even less rewarding to create an Android version of your application.
Way WAY back (as in over a decade) there was a class named DotLine by Søren Olin. Is that what you are referring to?
I have some code for drawing patterned lines with pure xojo that I need to clean up that I am considering open sourcing… No fancy math just an empirical solution.
I sort of have a web page about it, but I never seem to get around to getting the code ready to upload and finishing documentation… What It does can be seen here:
[quote=165949:@Dave S]There is a Windows API that seems to be the equivalent to CGContextSetLineDash
and I believe it is SETPENDASH or something like that (part of GDI+)
and I guess in plain GDI there is/was
Declare Function CreatePen Lib “gdi32” (ByVal fnPenStyle As Long, ByVal w As Long, ByVal crColor As Long) As Long
but can’t find anything to tell me exactly how to implement it… seeing as the OSX versionis related to a specific graphics object… and all.
and for now I need 3 line styles … DOTTED, DASHED and SOLID (obviously solid is easy)
and YES I know I could do
for x=x1 to x2 step 8
g.drawline x,y,x+4,y
next x
but I would prefer to do it “right” (and of course as fast as possible)[/quote]
The other thing… with the OSX call… I don’t have to alter any of my drawing code at all… regardless of the line pattern I call the same line drawing routine. resorting to the above method would cause me to have to alter tons of existing code
Aaron Ballman’s Advanced Graphics for Windows has the declares and examples of using them… is that hosted anywhere these days?
I think I originally got it from his website when he worked for REALSoftware.
In any case in this day and age Xojo really should directly support pattered lines and gradients at least, along other graphics goodies that are supported by both Windows and OSX . Xojo’s built-in graphics capabilities are really very behind the times!!!
My Bezo class draws solid or dashed bezier curves of any number of control points. The demo starts with 5 control points which you can drag around, context-click a point to delete it or context-click elsewhere to append a point. original post
It doesn’t automatically support curve chaining, which would also need supplying an initial dash pattern phase. Should be easy to add.
[quote=165958:@Karen Atkocius]Aaron Ballman’s Advanced Graphics for Windows has the declares and examples of using them… is that hosted anywhere these days?
[/quote]
In GDI+ you pass a pen object to each drawing primitive. There is no way to set a dashed style globally that subsequent drawing commands will just use. Here is an example of drawing a dashed line. You must enable UseGDIPlus to use it.
Sub DrawDash(g as graphics, x1 as integer, y1 as integer, x2 as integer, y2 as integer)
const DashStyleSolid = 0
const DashStyleDash = 1
const DashStyleDot = 2
const DashStyleDashDot = 3
const DashStyleDashDotDot = 4
const DashStyleCustom = 5
declare function GdipCreatePen1 lib "gdiplus" (c as integer, width as single, unit as integer, byref p as integer) as integer
declare function GdipSetPenDashStyle lib "gdiplus" (pen as integer, style as integer) as integer
declare function GdipCreateFromHDC lib "gdiplus" (hdc as integer, byref g as integer) as integer
declare function GdipDrawLine lib "gdiplus" (g as integer, pen as integer, x1 as single, y1 as single, x2 as single, y2 as single) as integer
declare function GdipDeletePen lib "gdiplus" (pen as integer) as integer
declare function GdipDeleteGraphics lib "gdiplus" (g as integer) as integer
dim pen, n as integer
dim c as color
dim mb as new MemoryBlock(4)
c = g.ForeColor
mb.byte(0) = c.blue
mb.byte(1) = c.green
mb.byte(2) = c.red
mb.byte(3) = 255 // alpha = opaque
n = mb.Int32Value(0)
call GdipCreatePen1(n, g.PenWidth, 2, pen)
call GdipSetPenDashStyle(pen, DashStyleDash)
dim gpx as integer
call GdipCreateFromHDC(g.handle(Graphics.HandleTypeHDC), gpx)
call GdipDrawLine(gpx, pen, x1, y1, x2, y2)
call GdipDeletePen(pen)
call GdipDeleteGraphics(gpx)
End Sub