ButtonGadgetEx.pbi (buttons with image and text), v0.4

Share your advanced PureBasic knowledge/code with the community.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Perkin »

Is there any way to use *.png images with this?
I've tried and although they load and the buttons are created, the images are missing, but text is offset.
%101010 = $2A = 42
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Perkin »

@Rook - For text overlaying an Icon, I've managed it.

Adding a few line to the 'ButtonGadgetEx.pbi' file.

Add

Code: Select all

#BIGE_Overlay
in the Enumeration section.

and add

Code: Select all

          Case #BIGE_Overlay
            ImageX = (Width-ImageWidth(*Prop\ImageID))/2
            ImageY = (Height-ImageHeight(*Prop\ImageID))/2
            TextX = (Width-SZ\cx)/2
            TextY = (Height-FontHeight)/2
into the WndProc() procedure in the Select *Prop\ImagePosition section (Around line 160)

Then use the #BIGE_Overlay constant when creating your gadget.
%101010 = $2A = 42
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Inf0Byt3 »

It should work with any image format in theory. The only problem is that I used the DrawIconEx_ API to draw the images on the buttons. This is because we need to draw on a system-offered HDC (which we get by using GetDC_). In order to draw other image formats we should use a function like PB's internal DrawImage(), but this function can't draw on HDCs, it can only draw on PureBasic objects. I know that when we still used PB3.94 some people played with the PB internals in such way that they could force the DrawImage() function to draw on such HDCs but I couldn't get it to work after the drawing lib was rewritten in latter PB versions.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Perkin »

I've discovered Trond' thread, which has the ability to use png's
http://www.purebasic.fr/english/viewtop ... 12&t=41045

So I'm going to have a play, and see if I can have the best abilities of both.

Thanks.
%101010 = $2A = 42
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Perkin »

I've also noticed, when pressing a ButtonGadgetEx, the image is not displayed.
Is that fixable?
%101010 = $2A = 42
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Inf0Byt3 »

That's rather strange, could you give me more info about that? Does the example in the archive work well for you?
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Perkin »

When running example, button 2 is disabled (as programmed), button 1 is displayed as expected, but when 'pressing' (and holding left mouse button) button1, the image disappears, when releasing LMB the image re-appears.
%101010 = $2A = 42
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Perkin »

:oops:

My Mistake :roll: , I must have changed something in the include which broke it :oops: .
I re-extracted them both and now works as it should.

Sorry!
%101010 = $2A = 42
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Post by Inf0Byt3 »

:D

No problem at all, i'm glad it's ok. I thought that maybe it was an OS problem (I use XP here) :D.

BTW, i uploaded a new version online that supports using your own callback... Check the example to see how to use it :).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.4

Post by Perkin »

Thanks.
%101010 = $2A = 42
Post Reply