LB Booster
« Resizing a Graphicbox »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:31am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Resizing a Graphicbox  (Read 610 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Resizing a Graphicbox
« Thread started 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 
« Last Edit: Sep 16th, 2016, 7:34pm by Richard Russell » User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: Resizing a Graphicbox
« Reply #1 on: Sep 16th, 2016, 8:32pm »

Think it is the FLUSH command that is less necessary in LBB.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Resizing a Graphicbox
« Reply #2 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.
« Last Edit: Sep 16th, 2016, 9:34pm by Richard Russell » User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: Resizing a Graphicbox
« Reply #3 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
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Resizing a Graphicbox
« Reply #4 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls