RE: Virtual Window code

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

euman at bellsouth.net wrote:
> Ok, I have about given up on the graphics codeing design built-into
> Win32lib so I have another Question.
> 
> Why do my scrollbars automatically stop, Im sure its not that Im over 
> the 65k limit...
> 
Thank you for the encouraging words about the library. Comments as clear 
and helpful as yours have proven to consolidate organizations that are 
customer-focused, caring, innovative, and open; such as Microsoft.

You are correct, its nothing to do with the 65k (sic) limit. The reason 
is that the code was wrong about calculating the source and destination 
points and the width and heights to copy.

Wayne, I've said this before and its worth repeating... If one is going 
to most of the app using direct API calls, the win32lib is not the right 
tool. Here is a reworking of your example for all the API code removed 
(because its not needed). Your inclusion of the API stuff only made it 
much more complicated that it needed to be. 

I've also added code to handle window resizing and ensuring that we 
don't try to copy non-existant parts of the bitmap.

We have a device here in Australia that is known as an "American 
Screwdriver"; I believe that it is known in other places as a hammer.

-----
without warning

include Win32Lib.ew

integer vxScreen, vyScreen, 
        fromX, fromY, 
        vxMainWin, vyMainWin,
        vxMax, vyMax

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

constant 
    MainWin = createEx( Window, "Virtual Window Demo", NULL, 25, 25, 
vxMainWin, vyMainWin, 0, 0),
    VirtScrn = createEx( Pixmap, "", 0, 0, 0, vxScreen, vyScreen, 0, 0)
                                             
procedure onPaint_MainWin( integer self, integer event, sequence parms )
             
   -- Copy the pixmap to the window.
   bitBlt(MainWin,  0, 0,           -- Dest
          VirtScrn, fromX, fromY,   -- Source 
          vxMainWin, vyMainWin,     -- width, height
          SRCCOPY )                 -- style
    
end procedure
setHandler(MainWin, w32HPaint, routine_id("onPaint_MainWin"))

   
procedure onCreate_MainWin( integer self, integer event, sequence parms 
)

    setScrollRange ( {MainWin, SB_HORZ}, 1, (vxScreen - vxMainWin))
    setScrollRange ( {MainWin, SB_VERT}, 1, (vyScreen - vyMainWin))

    -- Clear the pixmap to all white                         
    setPenColor(VirtScrn, BrightWhite)
    drawRectangle(VirtScrn, True, 0, 0, vxScreen, vyScreen)
    
    -- Draw a black rectangle in the pixmap
    setPenColor(VirtScrn, Black)
    drawRectangle(VirtScrn, False, 10, 10, 600, 415)
         
    -- Draw a red rectangle in the pixmap
    setPenColor(VirtScrn, BrightRed)
    drawRectangle(VirtScrn, False, 320, 240, vxScreen-75, vyScreen-75)
                         
    -- Draw a green rectangle in the pixmap
    setPenColor(VirtScrn, Green)
    drawRectangle(VirtScrn, False, 5, 5, vxScreen-5, vyScreen-5)
                         
    -- Draw the initial window image.
    onPaint_MainWin(self, w32HPaint, {})
   
end procedure
setHandler(MainWin, w32HActivate, routine_id("onCreate_MainWin"))

procedure on_resize( integer self, integer event, sequence parms )
    sequence lCS   
    
    -- Get the new size of the window
    vxMainWin = parms[2]
    vyMainWin = parms[3]                     
    
    -- Shift viewport if new area is exposed.
    if fromX + vxMainWin > vxScreen then
        fromX = vxScreen - vxMainWin
    end if
    if fromY + vyMainWin > vyScreen then
        fromY = vyScreen - vyMainWin
    end if

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

    -- Repaint the images
    onPaint_MainWin(self, w32HPaint, {})

end procedure
setHandler(MainWin, w32HResize, routine_id("on_resize"))

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

end procedure
setHandler(MainWin, w32HScroll, routine_id ("on_scroll"))

WinMain( MainWin, Normal ) 

--
Derek

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

Search



Quick Links

User menu

Not signed in.

Misc Menu