It is currently March 28th, 2024, 11:08 pm

Is it possible to invert Text compared to the back ground?

Get help with creating, editing & fixing problems with skins
andy99000
Posts: 11
Joined: March 12th, 2017, 4:15 pm

Is it possible to invert Text compared to the back ground?

Post by andy99000 »

As in, say I have a black background with white text on it, and the background switched to white I want the text to be black so it can be seen. Anyone know how to do this?

Thanks for your help! :welcome:

Edit: for clarity
If I didn't say it, thank you for the help, and your cooperation. Greatly Appreciated! :thumbup:
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Is it possible to invert Text compared to the back ground?

Post by balala »

Yes, it is:

Code: Select all

[Rainmeter]
Update=-1
DynamicWindowSize=1
AccurateText=1

[Variables]
Color=1
FontColor=255
SolidColor=255

[MeterString]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=(#FontColor#*#Color#),(#FontColor#*#Color#),(#FontColor#*#Color#)
SolidColor=(#SolidColor#*(1-#Color#)),(#SolidColor#*(1-#Color#)),(#SolidColor#*(1-#Color#)),150
FontSize=24
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=My string
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Color "(1-#Color#)"][!UpdateMeter "MeterString"][!Redraw]
The FontColor and SolidColor variables (defined into the [Variables] section) will determine the color of the text and the color of the background, respectively. When you click the string, the value of the Color variable toggles between 0 and 1 and this will give new colors to both, the string and the background.
andy99000
Posts: 11
Joined: March 12th, 2017, 4:15 pm

Re: Is it possible to invert Text compared to the back ground?

Post by andy99000 »

Thank you for the reply!

Is that possible to do under the entire color spectrum, so that way the text can be seen, no matter the color behind it? Also, is this possible to do passively (without interaction from the user)?

PS: I am still learning, so sorry if this is what your code does and I just don't realize it. :confused:

EDIT: And is this possible to do when only part of a string is exposed to the new background?
If I didn't say it, thank you for the help, and your cooperation. Greatly Appreciated! :thumbup:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is it possible to invert Text compared to the back ground?

Post by jsmorley »

That's a much more complicated thing, and not entirely possible in its entirety.

First, the "inverse" of any given color code, if you simply make each component of the font and solid the "inverse" of each other, will make for some strange colors, it won't be "dark" and "light", but entirely different.

For example, if I have 0,0,255 (primary blue) and I apply that reasoning, I would get 255,255,0 (primary yellow), not some kind of dark blue and light blue. Don't forget as well that as you approach the "middle" of the values for any given color component, the "inverse" isn't going to be much different. The inverse of 127 in the RGB world is ... 127.

Instead what you need to do is get the "luminescence" value of the entire color using an HSB (Hue Saturation Brightness) formula and simply change the "brightness". Rainmeter has no ability to deal with HSB natively, and it would take a moderately complicated Lua script to do this.

Second, there is no way for the string meter to know what color it is "on top of" automatically, and in any case while you can use InlineSetting to have different colors for different parts of the string, it is based on entire "characters", and can't split the color in a single character. There is just no good way to really even get close, as you can't know the length of a string in characters, which are variable width characters anyway, but only in pixels, which is of no use with InlineSetting. So while you can in theory say "color the first 5 characters red, and the rest blue", that has no relationship to what the background is or isn't.

I don't want to discourage, but you are going down a path that will quickly get very complicated, and the chances of it really working as you want are slim.
andy99000
Posts: 11
Joined: March 12th, 2017, 4:15 pm

Re: Is it possible to invert Text compared to the back ground?

Post by andy99000 »

Ah, I see. Well, while I do have some (little) experience in Lua, that is a path I think best not to go down. Hopefully someday I will be able to make my own plugin for this type of thing. It won't be anytime soon, however :uhuh:

Thank you again for your help! Greatly Appreciated!
If I didn't say it, thank you for the help, and your cooperation. Greatly Appreciated! :thumbup:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is it possible to invert Text compared to the back ground?

Post by jsmorley »

andy99000 wrote:Ah, I see. Well, while I do have some (little) experience in Lua, that is a path I think best not to go down. Hopefully someday I will be able to make my own plugin for this type of thing. It won't be anytime soon, however :uhuh:

Thank you again for your help! Greatly Appreciated!
It's reasonably complicated. It's really not the HSB "brightness" that should be considered, but the Lab "luminance" value that really returns the perceived "lightness" of a color.

For instance 0,0,255 (primary blue) has a "brightness" of 100%. However, if you look at it, it's not a "light" color at all. The perceived lightness of it is around 30% or actually fairly dark. That's because red, green, and blue each have different "weights" when applied to perceived lightness.
1.jpg
https://en.wikipedia.org/wiki/Relative_luminance

There are some pretty hideous formulas involved in translating RGB to HSB, HSB to RGB and getting and changing the perceived lightness.
You do not have the required permissions to view the files attached to this post.