CustomButtons
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Thanks for testing it. I believe it's close enough to suit me. Unless there's a glaring bug in reasonably normal behaviour I'm happy. People holding multiple mouse buttons down and surfing around a screen on and off buttons shouldn't be too surprised by any result, imho. I appreciate your help, it's much tighter now.
thx, very good!
how can i catch a event from custom-button with #PB_Any?
doesn't work
how can i catch a event from custom-button with #PB_Any?
Code: Select all
ElseIf EventwParam() = mygadget
Debug "mygadget"
EndIf
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
There is an update to this library. It has a new (important, imho) feature: optional clipping mask. Here is an excerpt from the help file:

There are no extra parameters to supply, if the mask is found the clipping region will be set to the white portion of the mask, else it will be the full rectangle of the button.
The demo is updated to show the difference in using the mask, one of the buttons uses it and the other doesn't. See how one button detects collisions from the corner when the mouse is still a few mm away. The other one works correctly as it uses the mask feature.
Here's what an image strip utilizing the mask looks like:Optional Mask Image:
If you desire a clipping region, for an elliptical or polygonal-shaped button,
you may add a fifth image to your strip. This image serves as a clipping mask
and should be two colors: White to describe the 'hot' zone(s) and Black to
denote areas you'd like to exclude from collision testing.
This feature is especially useful for round buttons with a background size
larger than the ellipse, say to accomodate a drop shadow, etc. and if you include
a mask image your collision testing will be pixel-perfect on the button.
Images should appear in the strip left-to-right in this order:
Disabled, Unpressed, Hover, Pressed, Mask (optional)

There are no extra parameters to supply, if the mask is found the clipping region will be set to the white portion of the mask, else it will be the full rectangle of the button.
The demo is updated to show the difference in using the mask, one of the buttons uses it and the other doesn't. See how one button detects collisions from the corner when the mouse is still a few mm away. The other one works correctly as it uses the mask feature.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
netmaestro wrote: @ts-soft: I can't reproduce that. If you could make a snippet that shows the failure it would help a great deal. Thanks.
Code: Select all
;=================================
; test1.pb: Solid-color window
;=================================
LoadImage(0,"buttons2.bmp")
Transcolor = RGB(224,223,227) ; Background color of buttons2.bmp
OpenWindow(0,0,0,300,200,"",$C80001)
SetWindowColor(0, 14933984)
CreateGadgetList(WindowID(0))
mygadget = CustomButton(WindowID(0),#PB_Any,40,20,60,60,0,#CB_SolidBrush,Transcolor)
CustomButton(WindowID(0),1,120,20,60,60,0,#CB_SolidBrush,Transcolor)
CustomButton(WindowID(0),2,200,20,60,60,0,#CB_SolidBrush,Transcolor)
DisableGadget(mygadget,1)
Repeat
EventID=WaitWindowEvent()
If EventID = #CB_Button_Click ; This is how you check for button clicks
If EventwParam()=1 ; You don't use #PB_Event_Gadget, EventGadget()
DisableGadget(mygadget,0) ; or EventType(). They don't apply to
ElseIf EventwParam()=2 ; CustomButtons.
DisableGadget(mygadget,1)
ElseIf EventwParam() = mygadget
Debug "mygadget"
EndIf
EndIf
Until EventID=#WM_CLOSE
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
with updated version it works finenetmaestro wrote:Hm. It's working here. Do you have a recent version of CustomButton installed, and if so, what is your OS?

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

i have found a small bug. if you press the right mouse button you have the same events wat you have with the left mouse button.
Normal you dont have events if you press the right mouse button over a ButtonGadget.
regards,
Nico
Normal you dont have events if you press the right mouse button over a ButtonGadget.
regards,
Nico
my live space
Are there any plans to support PNG alphachannel transparency
like DrawAlphaImage does? In my current project i frequently
use your custombuttons with different kind of shapes and especially
not rectangular ones looks crappy with single color transparency.
Almost all image tools like Adobe Photoshop and so on apply some
sort of antialias to give a smoother look and due to this the colors
messed up and you will see some kind of border around the button.
On the other side.. if you dont use antialias your buttons get a chiseled
look.
In the moment i use a dirty hack to use transparent buttons on different
background images without chiseled look or borders.
this is just a snippet and works well for my needs .. but if you
use some cool alphachannel tricks in a button state other than the
first one you will get some trouble because i drawing over and over
again on the same image.. so be warned
But moving that grabimage line inside the for-loop should fix this.. not tested
so still be warned
To cut a long story short... i really would appreciate a native alphachannel
buttonimage support for the custombuttons.
Thank you for your attention.. please enjoy your further forum ride
like DrawAlphaImage does? In my current project i frequently
use your custombuttons with different kind of shapes and especially
not rectangular ones looks crappy with single color transparency.
Almost all image tools like Adobe Photoshop and so on apply some
sort of antialias to give a smoother look and due to this the colors
messed up and you will see some kind of border around the button.
On the other side.. if you dont use antialias your buttons get a chiseled
look.
In the moment i use a dirty hack to use transparent buttons on different
background images without chiseled look or borders.
Code: Select all
button = LoadImage(#PB_Any,"C:\alphachannelimage.png")
background = LoadImage(#PB_Any,"c:\mybackground.bmp")
countofsubpictures = 5 ; disabled, normal, mouseover, pressed and the mask
buttonheight = ImageHeight(button)
buttonwidth = ImageWidth(button)/countofsubpictures
;get the part of the background image where the button will be placed
buttonbackground = GrabImage(background, #PB_Any, buttonx, buttony, buttonwidth, buttonheight)
;create the new button image with the smooth transparency for THIS background image
newbuttonimage = CreateImage(#PB_Any, ImageWidth(button), buttonheigth)
;walk through all button states in the button image and place them on the new buttonbackground with alphachannel
For x = 0 To countofsubpictures - 1
StartDrawing(ImageOutput(buttonbackground))
DrawAlphaImage(ImageID(button), -buttonwidth * x, 0)
StopDrawing()
StartDrawing(ImageOutput(newbuttonimage))
DrawImage(ImageID(buttonbackground),x*buttonwidth,0)
StopDrawing()
Next
; and finaly our custombutton
newcustombutton = CustomButton(WindowID(#mywindow), #PB_Any, buttonx, buttony, buttonwidth, buttonheight, newbuttonimage, #CB_SolidBrush, 0)
use some cool alphachannel tricks in a button state other than the
first one you will get some trouble because i drawing over and over
again on the same image.. so be warned

But moving that grabimage line inside the for-loop should fix this.. not tested
so still be warned

To cut a long story short... i really would appreciate a native alphachannel
buttonimage support for the custombuttons.
Thank you for your attention.. please enjoy your further forum ride

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
I don't have any connection to the internet at all since we moved to the farm. I get to the library or an internet cafe usually once a day for a half-hour or so and that's it. I could have signed up for a dialup account but that would have meant getting a landline phone which we haven't had for three years now. A communications company in our area is rolling out a rural broadband service via wireless hotpoints that will service our place and we're scheduled for an installation on the 15th of November, so I should have everything back up and running by then.
BERESHEIT