Page 1 of 1

All OS filled polygon

Posted: Tue Jul 08, 2008 8:11 am
by ozzie
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

Re: All OS filled polygon

Posted: Tue Jul 08, 2008 8:48 am
by Little John
ozzie wrote:A Polygon function would be very useful.
We can easily write it ourselves (PB 4.20, tested on Windows, should be x-plat):

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
Regards, Little John

Posted: Wed Jul 09, 2008 12:39 am
by ozzie
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

Posted: Wed Jul 09, 2008 6:45 am
by Little John
ozzie wrote:With your demo I can add a FillArea command to fill the polygon,
Yes, that was my idea.
ozzie wrote:but that relies on the area within the polygon not currently contain any instance of the border color.
Ooops. Didn't think of that. Then I also would like to have a built-in polygon command with the mentioned capabilities. :)

Regards, Little John

Re: All OS filled polygon

Posted: Fri Sep 11, 2009 10:00 pm
by Seymour Clufley
+1