1. Win32Lib drawPolygon routine

------=_NextPart_000_0011_01BEDB58.4314E380
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Can somebody explain how this routine works?  It doesn't do what I would =
expect it to do...

Here is an example of what I would expect to draw a house-shaped polygon =
but it's not even close.
What am I doing wrong?

include win32lib.ew
without warning

constant TestWin =3D =20
    create( Window, "Polygon Test", 0, Default, Default, 640, 480, 0 )

----------------------------------------
procedure onPaint_TestWin( integer x1, integer y1, integer x2, integer =
y2 )
  setPenColor( TestWin, Black )
  drawPolygon( TestWin, 1, { {100,100}, {100,200} , {200,200}, =
{200,100}, {150,50}, {100,100 } } )=20
end procedure
onPaint[TestWin] =3D routine_id("onPaint_TestWin")

----------------------------------------
-- pass control to Windows
WinMain( TestWin )


------=_NextPart_000_0011_01BEDB58.4314E380
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3401" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Can somebody explain how this routine works?&nbsp; =
It doesn't=20
do what I would expect it to do...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Here is an example of what I would expect to draw a=20
house-shaped polygon but it's not even close.</FONT></DIV>
<DIV><FONT size=3D2>What am I doing wrong?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>include win32lib.ew<BR>without warning</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>constant TestWin =3D&nbsp; <BR>&nbsp;&nbsp;&nbsp; =
create(=20
Window, "Polygon Test", 0, Default, Default, 640, 480, 0 )</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT =
onPaint_TestWin( integer x1, integer y1, integer x2, integer y2 =
)<BR>&nbsp;=20
setPenColor( TestWin, Black )<BR>&nbsp; drawPolygon( TestWin, 1, { =
{100,100},=20
{100,200} , {200,200}, {200,100}, {150,50}, {100,100 } } ) <BR>end=20
procedure<BR>onPaint[TestWin] =3D =
routine_id("onPaint_TestWin")</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>----------------------------------------<BR>-- pass =
control to=20

------=_NextPart_000_0011_01BEDB58.4314E380--

new topic     » topic index » view message » categorize

2. Re: Win32Lib drawPolygon routine

Brian Broker wrote:

> Can somebody explain how this routine works?

Ooops. It doesn't. There are two bugs in drawPolygon:

1. The point count is twice what it should be.
2. The points are being stored wrong.

I'm including the corrected routine. I'll try to get the corrected code
posted, along with some other fixes that were suggested last week.

-- David Cuny

----------------------------------------------------------------------------
-
global procedure drawPolygon( integer id, integer filled, sequence points )

    -- draw a polygon
    integer count, offset
    atom hdc, address

    -- count of points
    count = length( points )

    -- allocate room for points
    address = allocate_struct( count * 4 * 2 )

    -- poke the points
    offset = 0
    for i = 1 to count do

        -- x point
        poke( address+offset, int_to_bytes( points[i][1] ) )

        -- y point
        poke( address+offset+4, int_to_bytes( points[i][2] ) )

        -- increment offset
        -- fixed: this had been +4
        offset += 8

    end for

    -- get the device context
    hdc = getDC( id )

    -- create a pen
    createPen( id, hdc )

    -- create the brush
    createBrush( id, filled, hdc )

    -- call Polygon
    -- fixed: this had been count*2
    if not c_func( xPolygon, {hdc, address, count } ) then
        warnErr( "Polygon in drawPolygon failed." )
    end if

    -- release the device context
    releaseDC( id )

    -- release the memory
    free( address )

end procedure

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu