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

Post by netmaestro »

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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

thx, very good!

how can i catch a event from custom-button with #PB_Any?

Code: Select all

      ElseIf EventwParam() = mygadget
        Debug "mygadget"   
      EndIf
doesn't work
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.
Image
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 »

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:
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)
Here's what an image strip utilizing the mask looks like:

Image

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.
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 »

Fixed a couple bugs in the region scanner. Should be OK now.

@ts-soft: I can't reproduce that. If you could make a snippet that shows the failure it would help a great deal. Thanks.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

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 
doesn't debug "mygadget"
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.
Image
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 »

Hm. It's working here. Do you have a recent version of CustomButton installed, and if so, what is your OS?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

netmaestro wrote:Hm. It's working here. Do you have a recent version of CustomButton installed, and if so, what is your OS?
with updated version it works fine :D
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.
Image
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Nice work netmaestro 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

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
Padde
New User
New User
Posts: 5
Joined: Wed Apr 11, 2007 2:56 am

Post by Padde »

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.

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)
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 :lol:
But moving that grabimage line inside the for-loop should fix this.. not tested
so still be warned :wink:

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 :lol:
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

Does anyone have these files available? Site appears down...


Thanks in advance!
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

I believe (netmaestro may correct me) it's due to his currently using dial up.

He should have higher bandwidth capabilities soon and will probably resume hosting his site.

cheers
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

I have a VPS I don't use much of so if anyone needs any temp space I can setup an FTP account...
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 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I wondered where you'd gotten to lately netmaestro? Looking forward to having you back soon lad. :)
I may look like a mule, but I'm not a complete ass.
Post Reply