Re: Virtual Window code

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message -----=20
From: "Pete Lomax" <petelomax at blueyonder.co.uk>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Virtual Window code


>=20
>=20
> On Tue, 19 Aug 2003 06:00:08 +0000, Derek Parnell
> <ddparnell at bigpond.com> wrote:
>=20
> > Here is a reworking of your example for all the API code removed=20
> <snip>
>=20
> Derek,
> Thanks for the updated code (that you did for Wayne), however it
> exhibits some of the same minor flaws I'd like to get rid of in my
> program. I think I've fixed it, now I can see the trees from the
> forest, your comments please.
>=20
> First, this is(was) the problem:
> Put with trace trace(1) at the top of the program and ensure
> win32lib.ew is 100% without trace.
> Run the program and reposition the trace window bottom right.
> Minimise all other apps so the window is definitely not hidden.
> First it draws a blank window, and invokes on_resize()
> setScrollRange causes another resize event, so you get 3 in total, and
> the blank window is drawn (with scrollbars) another two times.
> 1st bitblt dumps garbage to the screen.
> 2nd and 3rd ditto
> Window is redrawn blank
> w32HPaint event re-dumps garbage to the screen
> Finally the w32HActivate gets it together and it is all fine.
>=20
> The fix:
> 1) do this immediately after creating the window:
> setScrollRange ( {MainWin, SB_HORZ}, 1, (vxScreen - vxMainWin))
> setScrollRange ( {MainWin, SB_VERT}, 1, (vyScreen - vyMainWin))
> and they can be removed from the start of onCreate_MainWin().
> This means they occur before the resize event handler is associated
> with the window, so now it only gets called once.

Instead of this 'fix', remove these two lines altogether and add the =
WS_SCROLLBARS flag to the createEx(Window...).

> 2) put isVisible(MainWin) test around the onPaint_MainWin call in
> onCreate_MainWin()

This 'fix' is not needed at all. The paint is not called if the window =
is minimized or hidden.

> 3) Change onCreate_MainWin from w32HActivate to w32HOpen
> This means it is called before paint or resize.

Remove this setHandler as it is not needed. I've renamed this routine =
InitVirtualScreen and call it just after creating the pixmap.

> 4) finally, I think the onPaint_MainWin call in on_resize is spurious,
> so I removed it.

Agreed. It is not needed in the onCreate_MainWin() either.


Here is my version....

-----------------------
without warning
include Win32Lib.ew

integer vxScreen
integer vyScreen=20
integer fromX
integer fromY
integer vxMainWin
integer vyMainWin
integer MainWin
integer VirtScrn=20
       =20
-------------------------------
procedure InitVirtualScreen()
-------------------------------

    -- Clear the pixmap to all white                        =20
    setPenColor(VirtScrn, BrightWhite)
    drawRectangle(VirtScrn, True, 0, 0, vxScreen, vyScreen)
   =20
    -- Draw a black rectangle in the pixmap
    setPenColor(VirtScrn, Black)
    drawRectangle(VirtScrn, False, 10, 10, 600, 415)
        =20
    -- Draw a red rectangle in the pixmap
    setPenColor(VirtScrn, BrightRed)
    drawRectangle(VirtScrn, False, 320, 240, vxScreen-75, vyScreen-75)
                        =20
    -- Draw a green rectangle in the pixmap
    setPenColor(VirtScrn, Green)
    drawRectangle(VirtScrn, False, 5, 5, vxScreen-5, vyScreen-5)
                           =20
end procedure

-------------------------------
procedure onPaint_MainWin( integer self, integer event, sequence parms )
-------------------------------
            =20
   -- Copy the pixmap to the window.
   bitBlt(MainWin,  0, 0,           -- Dest
          VirtScrn, fromX, fromY,   -- Source=20
          vxMainWin, vyMainWin,     -- width, height
          SRCCOPY )                 -- style
   =20
end procedure
  =20
-------------------------------
procedure onResize_MainWin( integer self, integer event, sequence parms =
)
-------------------------------
    -- Get the new size of the window
    vxMainWin =3D parms[2]
    vyMainWin =3D parms[3]                    =20
   =20
    -- Shift viewport if new area is exposed.
    if fromX + vxMainWin > vxScreen then
        fromX =3D vxScreen - vxMainWin
    end if
    if fromY + vyMainWin > vyScreen then
        fromY =3D vyScreen - vyMainWin
    end if

    -- Adjust scrollbars   =20
    setScrollRange ( {MainWin, SB_HORZ}, 1, (vxScreen - vxMainWin))
    setScrollRange ( {MainWin, SB_VERT}, 1, (vyScreen - vyMainWin))

end procedure

-------------------------------
procedure onScroll_MainWin( integer self, integer event, sequence parms =
)
-------------------------------
    integer pos           =20
   =20
    pos =3D parms[1] - 1
    if parms[3] =3D SB_HORZ then
        if pos + vxMainWin < vxScreen then
            fromX =3D pos
        else
            fromX =3D vxScreen - vxMainWin
        end if
    elsif parms[3] =3D SB_VERT then
        if pos + vyMainWin < vyScreen then
            fromY =3D pos
        else
            fromY =3D vyScreen - vyMainWin
        end if
    end if
                           =20
    -- Only bother redrawing if still scrolling.
    if parms[2] !=3D SB_ENDSCROLL then
        onPaint_MainWin(self, w32HPaint, {})
    end if

end procedure

-------------------------------
procedure RunApp()
-------------------------------

    vxScreen =3D 1280
    vyScreen =3D 960
    fromX =3D 0
    fromY =3D 0
    vxMainWin =3D 640
    vyMainWin =3D 480

    MainWin =3D createEx( Window, "Virtual Window Demo", NULL, 25, 25,=20
                                vxMainWin, vyMainWin, WS_SCROLLBARS, 0)
    VirtScrn =3D createEx( Pixmap, "", 0, 0, 0, vxScreen, vyScreen, 0, =
0)

    InitVirtualScreen()
       =20
    setHandler(MainWin, w32HPaint,  routine_id("onPaint_MainWin"))
    setHandler(MainWin, w32HResize, routine_id("onResize_MainWin"))
    setHandler(MainWin, w32HScroll, routine_id("onScroll_MainWin"))

    WinMain( MainWin, Normal )=20
end procedure


-------------------------------
-------------------------------
-------------------------------

RunApp()

--=20
Derek

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu