LB Booster
Programming >> BASIC code examples >> Resizing a Graphicbox
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1474053698

Resizing a Graphicbox
Post by Richard Russell on Sep 16th, 2016, 7:21pm

A question has been asked over at the LB Community Forum about resizing a graphicbox. My immediate reaction was "what's the problem?" because surely you can simply use the LOCATE command to change the position and size of a graphicbox, just like any other control. The code below works in LBB but for some reason it doesn't work in LB 4 - the bitmap never seems to show. Am I doing something wrong, or is there an incompatibility that I'm not aware of?

Richard.

Code:
    nomainwin
    WindowWidth = 800
    WindowHeight = 600
    graphicbox #w.gb, 0, 0, 0, 0
    open "Graphicbox resize" for window as #w
    do
        filedialog "Select a BMP file", "*.bmp", bmpfile$
        #w.gb "cls; down; fill buttonface"
        #w "refresh"
        if bmpfile$ = "" then close #w : end
        loadbmp "bitmap", bmpfile$
        hbitmap = hbmp("bitmap")
        struct bitmap, bmType as long, bmWidth as long, bmHeight as long, _
                       bmWidthBytes as long, bmPlanes as word, _
                       bmBitsPixel as word, bmBits as ptr 
        size = len(bitmap.struct)
        calldll #gdi32, "GetObjectA", hbitmap as ulong, size as long, _
                                      bitmap as struct, ret as long
        width = bitmap.bmWidth.struct
        height = bitmap.bmHeight.struct
        xpos = int((WindowWidth - width) / 2)
        ypos = int((WindowHeight - height) / 2)
        #w.gb "locate ";xpos;" ";ypos;" ";width;" ";height
        #w.gb "drawbmp bitmap 0 0"
        #w "refresh" 
    loop until 0
    wait 

Re: Resizing a Graphicbox
Post by Rod on Sep 16th, 2016, 8:32pm

Think it is the FLUSH command that is less necessary in LBB.
Re: Resizing a Graphicbox
Post by Richard Russell on Sep 16th, 2016, 9:28pm

on Sep 16th, 2016, 8:32pm, Rod wrote:
Think it is the FLUSH command that is less necessary in LBB.

You're right, but it also seems that the order in which you do things is important: if I put the refresh immediately after the locate like this it still doesn't work in LB 4 even with a flush:

Code:
        #w.gb "locate ";xpos;" ";ypos;" ";width;" ";height
        #w "refresh"
        #w.gb "drawbmp bitmap 0 0"
        #w.gb "flush" 

But if I move the refresh to after the drawbmp it starts working:

Code:
        #w.gb "locate ";xpos;" ";ypos;" ";width;" ";height
        #w.gb "drawbmp bitmap 0 0"
        #w "refresh"
        #w.gb "flush" 

This isn't what I would expect, and anyway flush is usually only necessary to make graphics 'stick' rather than to cause them to display initially.

Maybe you could tell the OP that, with care, he can resize the graphicbox.

Richard.

Re: Resizing a Graphicbox
Post by Rod on Sep 17th, 2016, 4:08pm

I vaguely recall this issue coming up before. It seems as if the refresh command in LB is like issuing an event. But LB needs to handle the event so needs a scan or wait or some other drawing action to recognise the refresh event has been asked for. Scan catches it, but its probably not a useful solution. A LB bug I think.


Code:
nomainwin
    WindowWidth = 800
    WindowHeight = 600
    graphicbox #w.gb, 0, 0, 0, 0
    open "Graphicbox resize" for window as #w
    do
        filedialog "Select a BMP file", "*.bmp", bmpfile$
        #w.gb "cls; down; fill buttonface"
        #w "refresh"
        if bmpfile$ = "" then close #w : end
        loadbmp "bitmap", bmpfile$
        hbitmap = hbmp("bitmap")
        struct bitmap, bmType as long, bmWidth as long, bmHeight as long, _
                       bmWidthBytes as long, bmPlanes as word, _
                       bmBitsPixel as word, bmBits as ptr
        size = len(bitmap.struct)
        calldll #gdi32, "GetObjectA", hbitmap as ulong, size as long, _
                                      bitmap as struct, ret as long
        width = bitmap.bmWidth.struct
        height = bitmap.bmHeight.struct
        xpos = int((WindowWidth - width) / 2)
        ypos = int((WindowHeight - height) / 2)
        #w.gb "locate ";xpos;" ";ypos;" ";width;" ";height
        #w "refresh"
        scan
        #w.gb "drawbmp bitmap 0 0; flush"
    loop until 0
    wait
 

Re: Resizing a Graphicbox
Post by Richard Russell on Sep 17th, 2016, 5:24pm

on Sep 17th, 2016, 4:08pm, Rod wrote:
It seems as if the refresh command in LB is like issuing an event. But LB needs to handle the event so needs a scan or wait or some other drawing action to recognise the refresh event has been asked for. Scan catches it, but its probably not a useful solution.

Interesting. This is an aspect of LB that I wasn't previously aware of. I can often guess what's going on behind the scenes to explain its behaviour, but I can't this time. sad

Richard.