It is currently March 28th, 2024, 9:41 pm

Making a RGB to HEX and vice versa converter with keyboard inputs

Get help with creating, editing & fixing problems with skins
User avatar
AlphaEdd
Posts: 11
Joined: November 24th, 2017, 12:51 am

Making a RGB to HEX and vice versa converter with keyboard inputs

Post by AlphaEdd »

Okay so, hello ! I'm trying to build a little project a bit complicated for me, simple newbie. Namely, I'm trying to make a small converter that I could click on to turn RGB codes into HEX values and vice versa, each depending of one button. I checked this https://forum.rainmeter.net/viewtopic.php?t=21130 this https://docs.rainmeter.net/manual/plugins/inputtext/#Bangs and this https://forum.rainmeter.net/viewtopic.php?p=98462#p98462 as well as this https://forum.rainmeter.net/viewtopic.php?t=18353 but I swear, my brain gotta be a big noodle cause I can't get the code to work-
aesthetically, it looks fine
Image
and the text input meters do pop up when I click on the buttons so that's fine. but after it's the text result display side that is wonky- so I'm assuming I hecked up the setting of variables and I have no idea how to fix this
anyway, code ahead !

Code: Select all

[Variables]
CurrentInput=""
CurrentInput2=""
Maths=""
Maths2=""

[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

[Body]
	Meter=IMAGE
	ImageName=#@#background.png
	Group=Nonchangingstuff
	Hidden=1


[Hex]
	Meter=IMAGE
	ImageName=#@#hex.png
	LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1"]
	DynamicVariables=1
	X=110
	Y=10

[Rgb]
	Meter=IMAGE
	ImageName=#@#rgb.png
	LeftMouseUpAction=[!CommandMeasure MeasureInput2 "ExecuteBatch 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][!Redraw]
	MouseLeaveAction=[!HideMeterGroup Nonchangingstuff][!HideMeterGroup Random][!Redraw]

[MeasureInput]
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=#CurrentInput#
OnDismissAction=[!SetVariable CurrentInput ""][!Redraw]
Command1=[!SetVariable Maths "$UserInput$"][!Redraw]

[MeasureInput2]
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=#CurrentInput#
OnDismissAction=[!SetVariable CurrentInput2 ""]
Command2=[!SetVariable Maths2 "$UserInput$"]


[MeasureR]
Measure=String
String=#Maths#
RegExpSubstitute=1
Substitute="^(\d{1,3}),(\d{1,3}),(\d{1,3})$":"\1"

[MeasureG]
Measure=String
String=#Maths#
RegExpSubstitute=1
Substitute="^(\d{1,3}),(\d{1,3}),(\d{1,3})$":"\2"

[MeasureB]
Measure=String
String=#Maths#
RegExpSubstitute=1
Substitute="^(\d{1,3}),(\d{1,3}),(\d{1,3})$":"\3"

[MeasureRemainderR1]
Measure=Calc
Formula=( [MeasureR] % 16 )
Substitute="10":"a","11":"b","12":"c","13":"d","14":"e","15":"f"

[MeasureQuotientR1]
Measure=Calc
Formula=(( [MeasureR] - MeasureRemainderR1 ) / 16 )

[MeasureRemainderR2]
Measure=Calc
Formula=( MeasureQuotientR1 % 16 )
Substitute="10":"a","11":"b","12":"c","13":"d","14":"e","15":"f"

[MeasureRemainderG1]
Measure=Calc
Formula=( [MeasureG] % 16 )
Substitute="10":"a","11":"b","12":"c","13":"d","14":"e","15":"f"

[MeasureQuotientG1]
Measure=Calc
Formula=(( [MeasureG] - MeasureRemainderG1 ) / 16 )

[MeasureRemainderG2]
Measure=Calc
Formula=( MeasureQuotientG1 % 16 )
Substitute="10":"a","11":"b","12":"c","13":"d","14":"e","15":"f"

[MeasureRemainderB1]
Measure=Calc
Formula=( [MeasureB] % 16 )
Substitute="10":"a","11":"b","12":"c","13":"d","14":"e","15":"f"

[MeasureQuotientB1]
Measure=Calc
Formula=(( [MeasureB] - MeasureRemainderB1 ) / 16 )

[MeasureRemainderB2]
Measure=Calc
Formula=( MeasureQuotientB1 % 16 )
Substitute="10":"a","11":"b","12":"c","13":"d","14":"e","15":"f"

[MeasureConverted]
Measure=String
String=#[MeasureRemainderR2][MeasureRemainderR1][MeasureRemainderG2][MeasureRemainderG1][MeasureRemainderB2][MeasureRemainderB1]
DynamicVariables=1

[MeasureR1bis]
Measure=String
String=#Maths2#
RegExpSubstitute=1
Substitute="^#(.)(.)(.)(.)(.)(.)$":"\1","a":"10","b":"11","c":"12","d":"13","e":"14","f":"15"

[MeasureR2bis]
Measure=String
String=#Maths2#
RegExpSubstitute=1
Substitute="^#(.)(.)(.)(.)(.)(.)$":"\2","a":"10","b":"11","c":"12","d":"13","e":"14","f":"15"

[MeasureG1bis]
Measure=String
String=#Maths2#
RegExpSubstitute=1
Substitute="^#(.)(.)(.)(.)(.)(.)$":"\3","a":"10","b":"11","c":"12","d":"13","e":"14","f":"15"

[MeasureG2bis]
Measure=String
String=#Maths2#
RegExpSubstitute=1
Substitute="^#(.)(.)(.)(.)(.)(.)$":"\4","a":"10","b":"11","c":"12","d":"13","e":"14","f":"15"

[MeasureB1bis]
Measure=String
String=#Maths2#
RegExpSubstitute=1
Substitute="^#(.)(.)(.)(.)(.)(.)$":"\5","a":"10","b":"11","c":"12","d":"13","e":"14","f":"15"

[MeasureB2bis]
Measure=String
String=#Maths2#
RegExpSubstitute=1
Substitute="^#(.)(.)(.)(.)(.)(.)$":"\6","a":"10","b":"11","c":"12","d":"13","e":"14","f":"15"

[MeasureRbis]
Measure=Calc
Formula=( 16 * [MeasureR1bis] + [MeasureR2bis] )
DynamicVariables=1

[MeasureGbis]
Measure=Calc
Formula=( 16 * [MeasureG1bis] + [MeasureG2bis] )
DynamicVariables=1

[MeasureBbis]
Measure=Calc
Formula=( 16 * [MeasureB1bis] + [MeasureB2bis] )
DynamicVariables=1

[MeasureConvertedbis]
Measure=String
String=[MeasureRbis],[MeasureGbis],[MeasureBbis]
DynamicVariables=1

[styleTwo]
StringAlign=Center
StringCase=Upper
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,255
FontColor=255,255,255,255
FontFace=Courier New
AntiAlias=1


[MeterCode]
Meter=STRING
MeasureName=MeasureConverted
MeterStyle=styleTwo
FontSize=8
X=55
Y=10
Text=RGB: #Maths##CRLF#HEX: %1
Group=Nonchangingstuff
Hidden=1

[MeterCodebis]
Meter=STRING
MeasureName=MeasureConvertedbis
MeterStyle=styleTwo
FontSize=8
X=55
Y=35
Text=HEX: #Maths2##CRLF#RGB: %1
Group=Nonchangingstuff
Hidden=1
(huge chunks of codes stolen from the sources above, especially the conversion stuff)
anyway, if anyone could help me on that one to fix my diggy dang variables, it'd be awesome ! thanks !
Image
ChicknwithNoName
Posts: 18
Joined: February 17th, 2018, 11:08 pm

Re: Making a RGB to HEX and vice versa converter with keyboard inputs

Post by ChicknwithNoName »

I haven't had a chance to run your code or analyze it yet, but this is a similar project I was looking to tackle. However, I was looking to use a different approach by using a Lua Script which I came across here: https://docs.rainmeter.net/snippets/colors/.

I know it's not exactly the solution you're looking for ATM, but I thought I would share my find.
User avatar
AlphaEdd
Posts: 11
Joined: November 24th, 2017, 12:51 am

Re: Making a RGB to HEX and vice versa converter with keyboard inputs

Post by AlphaEdd »

Ah ! I found this during my reseach as well ! I just happen not to be familiar with lua yet, nor do I know how to integrate it to rainmeter, hence why I didn't jump into that. but with how short it can make codes, it's temptating... I'm reallyyyyy a beginner. good luck with your project !!

also, I realised that maybe it'd be easier to deal with this all if I dropped the image files

Image Image Image Image
(background, hex, reset button and rgb in order)
Image
User avatar
jsmorley
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

Post by jsmorley »

Here is an example of how you might integrate that Lua with a skin:

Skin:

Code: Select all

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

[Variables]
MyRGBColor=210,0,75
MyHEXColor=207bff

[Lua]
Measure=Script
ScriptFile=ConvertHEXRGB.lua
Disabled=1

[MeterRGBToHex]
Meter=String
W=170
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
StringCase=Upper
Text=#MyRGBColor# = #[Lua:ConvertToHex('#MyRGBColor#')]
DynamicVariables=1

[MeterHexToRGB]
Meter=String
Y=0R
W=170
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
StringCase=Upper
Text=##MyHexColor# = [Lua:ConvertToRGB('#MyHEXColor#')]
DynamicVariables=1
ConvertHEXRGB.lua:

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
So just create ConvertHEXRGB.lua in the same folder with your skin .ini file, and paste in that code.
1.png
You do not have the required permissions to view the files attached to this post.
ChicknwithNoName
Posts: 18
Joined: February 17th, 2018, 11:08 pm

Re: Making a RGB to HEX and vice versa converter with keyboard inputs

Post by ChicknwithNoName »

Thanks for the Lua Script example, jsmorley.

I get what AlphaEdd is trying to do, by using InputText to change the value(s) in Variables. The value does change and I could get it to display, but I couldn't figure out how to get MeasureConverted to update according to the new value.
User avatar
jsmorley
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

Post by jsmorley »

ChicknwithNoName wrote:Thanks for the Lua Script example, jsmorley.

I get what AlphaEdd is trying to do, by using InputText to change the value(s) in Variables. The value does change and I could get it to display, but I couldn't figure out how to get MeasureConverted to update according to the new value.
Sorry, but I just can't wade through that blizzard of code that can be done with one measure and some section variables that call the Lua. All things being equal, I'm all for trying to do stuff purely in Rainmeter .ini code, but all things are not equal in this case...
User avatar
jsmorley
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

Post by jsmorley »

Code: Select all

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

[Variables]
MyHEXColor=5aa2ff

[Lua]
Measure=Script
ScriptFile=ConvertHEXRGB.lua
Disabled=1

[MeterInputText]
Meter=String
W=201
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
StringCase=Upper
Text=Enter a HEX color code
LeftMouseUpAction=[!CommandMeasure "MeasureInputCode" "ExecuteBatch 1"]

[MeasureInputCode]
Measure=Plugin
Plugin=InputText
X=5
Y=3
W=201
H=18
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontSize=11
AntiAlias=1
FocusDismiss=1
UpdateDivider=-1
Command1=[!SetVariable MyHEXColor "$UserInput$"][!UpdateMeter *][!Redraw]

[MeterHexToRGB]
Meter=String
Y=5R
W=201
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
StringCase=Upper
Text=##MyHEXColor# = [Lua:ConvertToRGB('#MyHEXColor#')]
DynamicVariables=1
GIF.gif
You do not have the required permissions to view the files attached to this post.
ChicknwithNoName
Posts: 18
Joined: February 17th, 2018, 11:08 pm

Re: Making a RGB to HEX and vice versa converter with keyboard inputs

Post by ChicknwithNoName »

jsmorley wrote:Sorry, but I just can't wade through that blizzard of code that can be done with one measure and some section variables that call the Lua. All things being equal, I'm all for trying to do stuff purely in Rainmeter .ini code, but all things are not equal in this case...
I tried it for a challenge, but I shortly gave up. Your solution is much more elegant and less of a nightmare to debug. Although, I don't understand lua scripting at all, so your (update to your) Lua solution is much appreciated.
User avatar
jsmorley
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

Post by jsmorley »

ChicknwithNoName wrote:I tried it for a challenge, but I shortly gave up. Your solution is much more elegant and less of a nightmare to debug. Although, I don't understand lua scripting at all, so your (update to your) Lua solution is much appreciated.
Sure, you almost don't need to understand the Lua code, just that you pass either a HEX (RRGGBB) or RGB (RRR,GGG,BBB) value to the appropriate function in the Lua, and it will return the converted value, which will replace the [&Lua:FunctionName('StringValue')] where it is used.

https://docs.rainmeter.net/manual/lua-scripting/inline-lua/
ChicknwithNoName
Posts: 18
Joined: February 17th, 2018, 11:08 pm

Re: Making a RGB to HEX and vice versa converter with keyboard inputs

Post by ChicknwithNoName »

jsmorley wrote:Sure, you almost don't need to understand the Lua code, ...
I just meant that I have zero knowledge of Lua to be able to write my own code which is why I appreciate people, like yourself, who contribute Lua Scripts for the rest of us to use.