It is currently March 29th, 2024, 9:10 am
Making a RGB to HEX and vice versa converter with keyboard inputs
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
In any case, if you want to press forward and get your skin working with the Lua solution, I'm glad to help. I just can't deal with that version with the blizzard of measures and calcs and substitutes, it just makes me die inside a little.
-
- Posts: 11
- Joined: November 24th, 2017, 12:51 am
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
I'll definitely try ! this seems simple enough and I'll have very little to change so it, for example, answers to a button instead so yaaaay- will get back to you once I'm done !!
-
- Rainmeter Sage
- Posts: 16110
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
The code of the rgb and hex converter.ini skin has two small mistakes, but otherwise it works:
- A quotation mark is missing from the Command2 option of the [MeasureInput2] measure: Command2=[!SetVariable CurrentInput2 "$UserInput$"][!SetVariable Maths2 "#CurrentInput2#[color=#FF0000]"[/color]][!Redraw] (that I marked red).
- Even if you fix this issue, the option isn't quite correct (same way the Command1 option of the [MeasureInput] measure isn't correct). I rewrote them, here they are:
With these options both conversions works fine.
Code: Select all
[MeasureInput] ... Command1=[!SetVariable CurrentInput "$UserInput$"][!SetVariable Maths "[MeasureInput]"][!Redraw] [MeasureInput2] ... Command2=[!SetVariable CurrentInput2 "$UserInput$"][!SetVariable Maths2 "[MeasureInput2]"][!Redraw]
It's not a good idea to atribute the entered value to a variable, then atribute the value of this variable, to another variable, too. To be honest, I don't even think the CurrentInput and CurrentInput2 variables would be needed.
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
So here is how I would start to attack it with the Lua solution:
ConvertHEXRGB.ini:
ConvertHEXRGB.lua:
Uses Inline Lua and Nested Variables.
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/
https://docs.rainmeter.net/manual/variables/nesting-variables/
Let me know if you have questions. I didn't do a complete clean-up of the original code, but concentrated on the functionality.
Saves about 100 lines of code and just enormous amounts of complexity over the approach without the Lua. I simply cannot justify 22 more measures in the skin in order to avoid a dozen lines of Lua. That just doesn't make any sense to me. Not all things that can be done, should be done.
BTW, this will work fine either with or without the alpha component on the color code. i.e. 255,255,255,90 or FFFFFF5A. The other way won't.
ConvertHEXRGB.ini:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamnicWindowSize=1
[Variables]
CurrentInputRGB=169,169,169
CurrentInputHEX=696969
[Lua]
Measure=Script
ScriptFile=ConvertHEXRGB.lua
Disabled=1
[MeterInputBepsi]
Meter=String
X=0
Y=75
W=160
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
Text=do your thing my dude
Group=Nonchangingstuff
Hidden=1
[Body]
Meter=IMAGE
ImageName=#@#background.png
Group=Nonchangingstuff
Hidden=1
[Hex]
Meter=IMAGE
ImageName=#@#rgb.png
LeftMouseUpAction=[!CommandMeasure MeasureInputRGB "ExecuteBatch 1-2"]
DynamicVariables=1
X=110
Y=10
[Rgb]
Meter=IMAGE
ImageName=#@#hex.png
LeftMouseUpAction=[!CommandMeasure MeasureInputHEX "ExecuteBatch 1-2"]
DynamicVariables=1
X=110
Y=36
[Button]
Meter=IMAGE
ImageName=#@#reset button.png
ImageAlpha=1
DynamicVariables=1
X=110
Y=10
MouseOverAction=[!ShowMeterGroup Nonchangingstuff][!ShowMeterGroup Random]
MouseLeaveAction=[!HideMeterGroup Nonchangingstuff][!HideMeterGroup Random]
[MeasureInputRGB]
Measure=Plugin
Plugin=InputText
X=4
Y=79
W=161
H=19
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
FocusDismiss=1
DefaultValue=#CurrentInputRGB#
DynamicVariables=1
Command1=$UserInput$
Command2=[!SetVariable CurrentInputRGB "[&MeasureInputRGB]"][!UpdateMeter *][!Redraw]
[MeasureInputHEX]
Measure=Plugin
Plugin=InputText
X=4
Y=79
W=161
H=19
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
FocusDismiss=1
DefaultValue=#CurrentInputHEX#
Command1=$UserInput$
Command2=[!SetVariable CurrentInputHEX "[&MeasureInputHEX]"][!UpdateMeter *][!Redraw]
[styleTwo]
StringAlign=Center
StringCase=Upper
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,255
FontColor=255,255,255,255
FontFace=Courier New
AntiAlias=1
[MeterRGB2HEX]
Meter=STRING
DynamicVariables=1
MeterStyle=styleTwo
FontSize=8
X=55
Y=10
Text=RGB: [#CurrentInputRGB]#CRLF#HEX: [&Lua:ConvertToHex('[#CurrentInputRGB]')]
Group=Nonchangingstuff
Hidden=1
[MeterCodebis]
Meter=STRING
DynamicVariables=1
MeterStyle=styleTwo
FontSize=8
X=55
Y=35
Text=HEX: [#CurrentInputHEX]#CRLF#RGB: [&Lua:ConvertToRGB('[#CurrentInputHEX]')]
Group=Nonchangingstuff
Hidden=1
Code: Select all
function ConvertToHex(color) -- Converts RGB colors to HEX
local hex = {}
for rgb in color:gmatch('%d+') do
table.insert(hex, ('%02X'):format(tonumber(rgb)))
end
return table.concat(hex)
end
function ConvertToRGB(color) -- Converts HEX colors to RGB
local rgb = {}
for hex in color:gmatch('..') do
table.insert(rgb, tonumber(hex, 16))
end
return table.concat(rgb, ',')
end
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/
https://docs.rainmeter.net/manual/variables/nesting-variables/
Let me know if you have questions. I didn't do a complete clean-up of the original code, but concentrated on the functionality.
Saves about 100 lines of code and just enormous amounts of complexity over the approach without the Lua. I simply cannot justify 22 more measures in the skin in order to avoid a dozen lines of Lua. That just doesn't make any sense to me. Not all things that can be done, should be done.
BTW, this will work fine either with or without the alpha component on the color code. i.e. 255,255,255,90 or FFFFFF5A. The other way won't.
You do not have the required permissions to view the files attached to this post.
-
- Rainmeter Sage
- Posts: 16110
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
I don't say your approach wouldn't be good. But believe me, the simple Rainmeter code, also works. And it even can be adapted to work with the Alpha value, too. And it's not even so hard to be understood. Maybe the Rainmeter code itself is longer, but it definitely works.jsmorley wrote:BTW, this will work fine either with or without the alpha component on the color code. i.e. 255,255,255,90 or FFFFFF5A. The other way won't.
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
Well, we will have to agree to disagree. I do not believe that only having a hammers turns all problems into nails.
-
- Rainmeter Sage
- Posts: 16110
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Making a RGB to HEX and vice versa converter with keyboard inputs
Again, I didn't say the lua solution wouldn't be good. Just wanted to show up that other solutions are available as well (as usually).jsmorley wrote:Well, we will have to agree to disagree. I do not believe that only having a hammers turns all problems into nails.