Inverting Buttons

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Inverting Buttons

Post by richmond62 » Sun Jan 30, 2022 7:47 pm

SShot 2022-01-30 at 20.45.18.png
SShot 2022-01-30 at 20.45.18.png (3.64 KiB) Viewed 6106 times
-
I would like to invert the colour of a button . . . so that any thing behind it does NOT show through.

I have played around with inks, backGroundColor and foreGroundColor to no avail.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Inverting Buttons

Post by bn » Sun Jan 30, 2022 9:14 pm

Hi Richmond,

does this do what you want when you put this script into the button?

Code: Select all

local sBGColor, sFGColor

on mouseDown
   lock screen
   put the effective backgroundcolor of me into sBGColor
   put sBGColor into tBGColor
   repeat with i = 1 to 3
      put 255 - item i of tBGColor into item i of tBGColor
   end repeat
   set the hiliteColor of me to tBGColor
   
   put the effective foregroundColor of me into sFGColor
   put sFGColor into tFGColor
   repeat with i = 1 to 3
      put 255 - item i of tFGColor into item i of tFGColor
   end repeat
   set the foregroundColor of me to tFGColor
end mouseDown

on mouseUp
   lock screen
   set the backgroundColor of me to sBGColor
   set the foregroundColor of me to sFGColor
end mouseUp
Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Inverting Buttons

Post by richmond62 » Sun Jan 30, 2022 9:30 pm

SShot 2022-01-30 at 22.28.35.png
SShot 2022-01-30 at 22.28.35.png (6.39 KiB) Viewed 6085 times
-
Not really.
-
WARNING: this stack will muck up your interface.
Attachments
Strike Me Pink.livecode.zip
Here's the stack.
(2.59 KiB) Downloaded 123 times

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: Inverting Buttons

Post by stam » Mon Jan 31, 2022 9:55 am

FerrusLogic recently posted an LC version of the JS tinyColor library - that probably will give you the colour alternatives you need…

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Inverting Buttons

Post by richmond62 » Mon Jan 31, 2022 12:13 pm

FerrusLogic recently posted an LC version of the JS tinyColor library - that probably will give you the colour alternatives you need…
I know, and I have played around with it.

But I would like to know how to invert the colour of buttons . . .

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Inverting Buttons

Post by dunbarx » Mon Jan 31, 2022 3:24 pm

Richmond.

I have your stack, which changes the color of the revmenubar. What has that got to do with buttons?

But I still do not understand what you are asking for. Controls behind an opaque button do not "show through" in any case. And what does "invert the color" mean?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Inverting Buttons

Post by richmond62 » Mon Jan 31, 2022 3:52 pm

But I still do not understand what you are asking for.
"many a slip twixt cup abd lip"

I should like to make buttons like this:
-
SShot 2022-01-31 at 16.50.05.png
SShot 2022-01-31 at 16.50.05.png (3.03 KiB) Viewed 5924 times
-
Go like this:
-
SShot 2022-01-31 at 16.50.05BTF.png
SShot 2022-01-31 at 16.50.05BTF.png (11.41 KiB) Viewed 5924 times
-
on a temporary basis.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Inverting Buttons

Post by dunbarx » Mon Jan 31, 2022 4:23 pm

Richmond.

So let us say you have a button with something like this in its script:

Code: Select all

on mouseUp
   if the backColor of me = "" then set the backColor of me to "yellow" else set the backColor of me to ""
end mouseUp
But you know this.

???

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Inverting Buttons

Post by richmond62 » Mon Jan 31, 2022 5:24 pm

The problem re a backColor is that that will not invert the colour of an icon in a button.

And if the ink of the source image (for the icon) is set to blendExclusion, as soon
as one modifies the backColor the image displays inwith the button as srcCopy:
-
SShot 2022-01-31 at 18.20.04.png
-
No dice. :roll:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Inverting Buttons

Post by dunbarx » Mon Jan 31, 2022 5:26 pm

Aha.

Invert the ICON. Why didn't you say so?

I bet that icons are drawn by the underlying OS, so you cannot futz with them. Others may tell me I am wrong...

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Inverting Buttons

Post by richmond62 » Mon Jan 31, 2022 5:29 pm

I bet that icons are drawn by the underlying OS
Neither in my example in the previous post nor in the "revmenuBar" stack:
-
SShot 2022-01-31 at 18.27.59.png

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Inverting Buttons

Post by jacque » Tue Feb 01, 2022 6:59 pm

If you want to change the appearance of the icon, you need to alter the source image. Changing the button itself won't do it, though you might be able to get away with setting a color overlay in the special effects pane of the property inspector.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: Inverting Buttons

Post by stam » Tue Feb 01, 2022 7:23 pm

One way around this may be to use the Universal Button widget, which allows you to set different icons for normal and hilited states (so, less coding...), plus set colours as you'd expect from a normal button...

https://github.com/revig/universal-button-widget

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Inverting Buttons

Post by richmond62 » Wed Feb 02, 2022 11:15 am

Indeed, Jacque and Stam both; and thank you for your suggestions.

However I should like to alter the colours of buttons and their icons in a
NON-DESTRUCTIVE fashion, so that "with the flick of a switch" on could
flip back and forth between 2 colour states.

And, when push comes to shove, all I am really looking
for is a way to INVERT all colours of an object.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Inverting Buttons

Post by jacque » Wed Feb 02, 2022 7:05 pm

If none of the inks work as desired you'll need to code it. Set up the button in its unaltered state and store its properties in a custom property:

Code: Select all

set the cUpColors of btn x to the properties of btn x
Now change the button to look like it's inverted state and:

Code: Select all

set the cDownColors of btn x to the properties of btn x
Now in a mouseDown handler:

Code: Select all

set the properties of btn x to the cDownColors of btn x
And the reverse on mouseUp and mouseRelease.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply