ButtonGadgetEx - Images as Button

Share your advanced PureBasic knowledge/code with the community.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ButtonGadgetEx - Images as Button

Post by IdeasVacuum »

...wow, that looks really excellent, fabulous piece of work. Thanks for sharing. 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ButtonGadgetEx - Images as Button

Post by infratec »

Hi mevedia,

try this:

Code: Select all

Procedure GrayscaleCallback(x, y, SourceColor, TargetColor)
  Define Gray.i
  Gray = (Red(SourceColor) * 77 + Green(SourceColor) * 150 + Blue(SourceColor) * 29) >> 8
  ProcedureReturn RGBA(Gray, Gray, Gray, Alpha(SourceColor))
EndProcedure
You can not add the alpha to each colour.
It is an extra byte wich defines the transparancy for the complete pixel.

If you want it a bit faster, you can use

Code: Select all

ProcedureReturn Gray|Gray<<8|Gray<<16|Alpha(SourceColor)<<24
But I think this is not working on all plattforms.

Bernd
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ButtonGadgetEx - Images as Button

Post by Andre »

...avoiding the GetSysColor_() WinAPI function it also works on MacOS. Thanks! :D

(Don't know if it works exactly like on Windows, as I don't have my PC running at the moment...)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: ButtonGadgetEx - Images as Button

Post by luis »

It's nice code and another good example for the canvas gadget, thank you for sharing it :)

But what the "Toggle" button should do ? I saw it should toggle the gadget (_ex) status but I don't see anything happen when I press the button. Maybe I didn't understand it...

A side note about something you probably are already aware of: in a real program keep in mind you should trap the alt-tab in some way to navigate to the _ex buttons too, or a user would find strange not being able to do so.
"Have you tried turning it off and on again ?"
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: ButtonGadgetEx - Images as Button

Post by Trond »

When you press the mouse outside the button, then drag it inside and release, the button gets pressed. It should only get pressed when the click is both started and ended inside the gadget.
Post Reply