Why doesn't SetGadgetState work properly with ImageGadget?

Just starting out? Need help? Post your questions and find answers here.
paleozord
User
User
Posts: 12
Joined: Wed Mar 15, 2006 8:30 pm

Why doesn't SetGadgetState work properly with ImageGadget?

Post by paleozord »

In the manual it states:

Code: Select all

- SetGadgetState(): Change the current Image of the gadget. A valid ImageID can be easily obtained with the UseImage() or ImageID() commands. If the ImageID is 0, then the image is removed from the gadget. 
But if I have an image currently displayed in a ImageGadget (#Image_0) from whatever source (it doesn't matter), and I try:

Code: Select all

SetGadgetState (#Image_0,0)
It does not remove the currently displayed image from the gadget at all, as it states in the manual. Instead nothing happens and the image is left intact and displayed, as before.

Why doesn't specifying zero as the ImageID remove the image from the gadget, as the manual states it should? Thanks!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Why doesn't SetGadgetState work properly with ImageGadge

Post by PB »

Here's an example that shows how to do it, and proves the manual is correct:

Code: Select all

If OpenWindow(0,300,200,300,200,"test",#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(0))
  pic1=CreateImage(1,50,50) ; Small black square.
  pic2=CreateImage(2,100,100) ; Large black square.
  ImageGadget(1,20,20,100,100,pic1)
  ButtonGadget(2,20,130,130,25,"Click to switch images")
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget And EventGadget()=2
      count+1
      If count=1
        SetGadgetState(1,pic2)
        SetGadgetText(2,"Click to clear image")
      ElseIf count=2
        SetGadgetState(1,0)
      EndIf
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
paleozord
User
User
Posts: 12
Joined: Wed Mar 15, 2006 8:30 pm

Post by paleozord »

Hi, thanks for your reply and help with the example. However, when I run that code in PB (after fixing the minor error in the OpenWindow statement that prevented it from running) I can confirm that clicking the button the second time does NOT remove/clear the "large black square" image from the gadget. Instead the image just stays there forever, until the program is terminated.

I am running PB4 on Windows XP (SP2). What am I doing wrong? Does it actually blank out the larger square for you, when you click the button the second time?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@paleozord
are you using SmartWindowRefresh()? it has some problems with images/icons http://www.purebasic.fr/english/viewtopic.php?t=24195 i hope this will be fixed soon.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
paleozord
User
User
Posts: 12
Joined: Wed Mar 15, 2006 8:30 pm

Post by paleozord »

nco2k wrote:@paleozord
are you using SmartWindowRefresh()? it has some problems with images/icons http://www.purebasic.fr/english/viewtopic.php?t=24195 i hope this will be fixed soon.
Hi.. no I haven't deliberately enabled SmartWindowRefresh, just running PB the default way with no such special command. But even when I deliberately did:

Code: Select all

SmartWindowRefresh(0,#False)
... it made no difference. Same result, large black square doesn't go away on second button click.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

download the latest beta image lib from http://www.purebasic.com/beta/ install it and restart the compiler.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
paleozord
User
User
Posts: 12
Joined: Wed Mar 15, 2006 8:30 pm

Post by paleozord »

nco2k wrote:download the latest beta image lib from http://www.purebasic.com/beta/ install it and restart the compiler.
I downloaded the newest image lib, copied-and-pasted it over my old version in PureLibraries, restarted the compiler but no difference. Large black square still isn't cleared with second button click.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

hm.. try the beta gadget lib aswell, because its a gadget after all. if that doesnt work i really dont know why it doesnt work for you properly.

have you installed pb4 into a new empty folder or over an existing older pb version?

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
paleozord
User
User
Posts: 12
Joined: Wed Mar 15, 2006 8:30 pm

Post by paleozord »

nco2k wrote:hm.. try the beta gadget lib aswell, because its a gadget after all. if that doesnt work i really dont know why it doesnt work for you properly.

have you installed pb4 into a new empty folder or over an existing older pb version?
Tried the newest gadget lib but no luck there either. I installed PB4 into a new
empty folder. I still have my older version (3.9x) intact in its old folder.

It's quite a mystery why it isn't working for me, and I guess there's nothing to do about it for the time being. Thank you for the help though really, I do appreciate the attempt.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

PB's example works fine for me right out of the page - no window error anything.

small box
larger box
clear

don't know what it might be.

I'm PB 4 final with no beta libs.

cheers
paleozord
User
User
Posts: 12
Joined: Wed Mar 15, 2006 8:30 pm

Post by paleozord »

Okay, I re-installed PB4 completely and now it does in fact seem to work fine. I'm not sure why this was happening, but I think the compiler was still referencing some of my older 3.9x files in the old directory, as evidenced by the fact that the initially posted code produced an old-time error on the OpenWindow statement, wanting the text name of the window to come after the flags, as it used to be in older versions of PB.

Anyway, thanks again to all for the help.. off I go to make some more progress....
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Yes, you should always install new versions into their own folder.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply