I'm wanting to draw 5-sided pointers for my own sliders, but can't find any easy way to provide this, especially as I want to support Mac OS X and Linux platforms as well as Windows. A Polygon function would be very useful.
Mike
All OS filled polygon
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: All OS filled polygon
We can easily write it ourselves (PB 4.20, tested on Windows, should be x-plat):ozzie wrote:A Polygon function would be very useful.
Code: Select all
EnableExplicit
Macro Ubound (array)
(PeekL(@array-8)-1)
EndMacro
Structure point_xy
x.l
y.l
EndStructure
Procedure Polygon (points.point_xy(1), color.l, connect.l=#True)
Protected i
For i = 1 To Ubound(points())
LineXY(points(i-1)\x, points(i-1)\y, points(i)\x, points(i)\y, color)
Next
If connect
LineXY(points(Ubound(points()))\x, points(Ubound(points()))\y, points(0)\x, points(0)\y, color)
EndIf
EndProcedure
;-- Demo
Dim points.point_xy(4)
points(0)\x = 40: points(0)\y = 40
points(1)\x = 50: points(1)\y = 60
points(2)\x = 70: points(2)\y = 60
points(3)\x = 60: points(3)\y = 30
points(4)\x = 50: points(4)\y = 30
Define width.l, height.l, color.l, event.l
Width = 100
Height = 100
Color = 0
If OpenWindow(0, 0, 0, Width, Height, "Polygon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If StartDrawing(WindowOutput(0))
Polygon(points(), color, #False)
StopDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
-
- Enthusiast
- Posts: 443
- Joined: Sun Apr 06, 2008 12:54 pm
- Location: Brisbane, Qld, Australia
- Contact:
Thanks, Little John. That helps, but doesn't give me a filled polygon. I note that the box, circle and ellipse commands all provide filled drawings. With your demo I can add a FillArea command to fill the polygon, but that relies on the area within the polygon not currently contain any instance of the border color.
Mike
Mike
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Yes, that was my idea.ozzie wrote:With your demo I can add a FillArea command to fill the polygon,
Ooops. Didn't think of that. Then I also would like to have a built-in polygon command with the mentioned capabilities.ozzie wrote:but that relies on the area within the polygon not currently contain any instance of the border color.

Regards, Little John
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: All OS filled polygon
+1
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."