CustomButtons

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

CustomButtons

Post by netmaestro »

This is a PureBasic library that allows you to create buttons with any look or shape you want, perfect for applying to skinned windows. All functions in the lib should be W9x compatible, so you don't need XP to create cool custom buttons. Here's a quick test:

http://www.networkmaestro.com/CustomButtonTest.exe

And here is the library package:

http://www.networkmaestro.com/CustomButton.zip

Basically you supply an image strip with four equal-sized images, one to display each of the button states Disabled, Unpressed, Hover, Pressed. You create the gadget with one call, so it's very easy to use.

In the demo, the second button enables the first one, and the third disables it again. It just shows all four looks.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Great work as always.

That is brilliant. :)
I may look like a mule, but I'm not a complete ass.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Thanks man :wink:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Thanks for the kind words and backatcha, srod!

My apologies, in the course of the last couple days I reworked the logic in this library and I notice that the version I released on the forum still asks for a background color parameter (second last parameter) This is not used by the lib anymore and is completely ignored. I've updated the lib and help file/examples, so if you'd rather not put redundant parameters in, you can download the updated version. Again, sorry for my inattention to this particular detail.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Thanks netmaestro - very nice work as usual. I wondered about the mouse down action though. Unless I'm mistaken, when you press a button and hold the mouse button down and move off the button, then move back over it (while the mouse button is still down) the mouse down artwork should show. In that case, I think yours shows the mouse hover artwork. If the intention is that your button is a windows button replacement, it should behave like a regular windows button. Then again that might not be the intention, so in that case, please disregard the comment.

If I can nitpick just a little bit more - the only other nice thing to have would be an alpha-blended edge, then it would be absolutely perfect. [edit: I could be wrong.. that was just judging from the demo - I haven't tried it with the lib - in that case, apologies]
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

It reverts immediately to unpushed when you move off while pressed, on my computer anyway. That's identical to the normal button behaviour afaik.

Some tips are probably in order for achieving good results regarding transparency. All the tools are provided to skin the button either transparently or based on window background. If I had a round button that I wanted to show alphablended on a patterned background, I probably wouldn't use transparency for that. I'd make the button images in a good quality photo editor against the patterned background and call the CustomButton function with #CB_SolidBrush, which tells it that it's to draw the full button rectangle without transparency. That way, your round button will look as nice as you were able to achieve in the photo editor because its background is a snippet of the window pattern brush.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

netmaestro wrote:It reverts immediately to unpushed when you move off while pressed, on my computer anyway. That's identical to the normal button behaviour afaik.
As I wrote, I'm talking about when you rollback over the button with the mouse down.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Yes, I just saw that part, I didn't see it the first time, I'll definitely take a look, thanks for pointing it out.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I wondered about the mouse down action though.
Fixed. Thanks for the report. I hadn't noticed it before.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Thanks alot. I'm not sure, did you update the demo exe? I just redownloaded it, but I think it still does the same thing.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Good point, the demo exe. I might take a few minutes and make a nice alphablended example for that.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Demo is updated, shows alphablending and correct mousemove behaviour. The second button toggles the first one enabled and disabled to show all four states.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

netmaestro wrote:correct mousemove behaviour
Almost correct. Holding the mouse down should only affect the button you originally pressed. Yours will apply the mouse down affect to the neighbouring button, which is not what Windows does. To confirm what does happen, open up calculator and press and hold a button, then move over to the next button (while the mouse button is depressed) and you'll see nothing happens to neighbouring buttons.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Ok, I think I have it. Could you redownload and test all the combinations and permutations of mousebutton-up and mousebutton-down surfing over the buttons and see if everything works as it should? I've tried it a lot and can't make it do anything unexpected, but I could easily miss something. Thanks!
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

On my machine, the first couple of passes moving from pressing the left graphic button, holding the mouse button down and moving to the right button (with mouse still held down) & back to the left button again worked ok (i.e. only showing mouse-down artwork on the left button) but after several repetitions of moving to the right button and back to the left and vice-versa, all with the mouse held down, eventually I could see the same issue again (right button's mouse down art appearing when it shouldn't). I could see the same issue if I started from the right button. Running XP Pro.
Post Reply