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

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

Get help with creating, editing & fixing problems with skins
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 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.
Glad to help. Lua is not really hard by the way, nothing at all like C++, which is the AntiChrist.
User avatar
balala
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

Post by balala »

AlphaEdd wrote: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
Beside jsmorley's code using the small lua script, as you saw in my first reply on the linked thread, the conversion can be done even without a lua script. Don't misunderstand me, I don't want to say the code using the lua script wouldn't be good, I just want to show a second way to achieve the same conversion, without using a lua code.
There is nothing wrong with your posted code. Its only issue is that a few DynamicVariables=1 options are missing. Add this option to all of the following measures: [MeasureR], [MeasureG], [MeasureB], [MeasureRemainderR1], [MeasureQuotientR1], [MeasureRemainderG1], [MeasureQuotientG1], [MeasureRemainderB1] and [MeasureQuotientB1], respectively [MeasureR1bis], [MeasureR2bis], [MeasureG1bis], [MeasureG2bis], [MeasureB1bis] and [MeasureB2bis]. Setting the dynamic variables is necessary on these measures, because they either are using dynamically set variables (variables set through a !SetVariable bang, like [MeasureR], [MeasureG] or [MeasureB]), or section variables ([MeasureRemainderR1], [MeasureQuotientR1], [MeasureRemainderG1] and so on). In these cases a DynamicVariables=1 option is required, the measures aren't working without them.
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 »

balala wrote:Beside jsmorley's code using the small lua script, as you saw in my first reply on the linked thread, the conversion can be done even without a lua script. Don't misunderstand me, I don't want to say the code using the lua script wouldn't be good, I just want to show a second way to achieve the same conversion, without using a lua code.
There is nothing wrong with your posted code. Its only issue is that a few DynamicVariables=1 options are missing. Add this option to all of the following measures: [MeasureR], [MeasureG], [MeasureB], [MeasureRemainderR1], [MeasureQuotientR1], [MeasureRemainderG1], [MeasureQuotientG1], [MeasureRemainderB1] and [MeasureQuotientB1], respectively [MeasureR1bis], [MeasureR2bis], [MeasureG1bis], [MeasureG2bis], [MeasureB1bis] and [MeasureB2bis]. Setting the dynamic variables is necessary on these measures, because they either are using dynamically set variables (variables set through a !SetVariable bang, like [MeasureR], [MeasureG] or [MeasureB]), or section variables ([MeasureRemainderR1], [MeasureQuotientR1], [MeasureRemainderG1] and so on). In these cases a DynamicVariables=1 option is required, the measures aren't working without them.
Well I mean, the rainmeter maths code itself is neat ! I wasn't worried about that part cause you wrote it and you're a god at this- it's more like the part I had to build myself (the input stuff to create the actual god dang values and basically pushing the value into the maths and getting both to display) that doesn't work, tho after adding the dynamic variables I got the converted part to display (but not the original) so thanks for that !

maybe I should've explained better that it's not the maths part that's problematic. I've been trying to tweak the rest for a while but it's still a struggle. no matter how much I explain the code to my penguins, i'm just still a clumsy noodle at this

Code: Select all

[Variables]
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
Hidden=1

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


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

[Hex]
   Meter=IMAGE
   ImageName=#@#hex.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=#Maths#
OnDismissAction=[!SetVariable Maths "wooo"][!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=#Maths2#
OnDismissAction=[!SetVariable Maths2 "try again boo"][!Redraw]
Command2=[!SetVariable Maths2 "$UserInput$"][!Redraw]


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

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

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

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

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

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

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

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

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

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

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

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

[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"
DynamicVariables=1

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

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

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

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

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

[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
Image

I also have a code that successfully displayed the pre modification code... but not the post maths one. so this is pretty annoying. I wish i god dang knew how to have both cause geeeeee.

also I tried to create another converter using the lua script ! cause I have no patience. but then despite how I literally just copy pasted the .ini and the .lua both into the skin folder before I'd try to modify it to suit my design needs, it didn't work somehow.

Image


nothing is happening on click and I'm baffled over how I can't even copy paste something properly
I have to download the lua libraries or something, do I ?
Image
User avatar
balala
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

Post by balala »

Please AlphaEdd, pack the whole config and upload it. It would be good to have all those images and everything you have in the config. Would make easier to figure out what's going on.
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 »

AlphaEdd wrote:also I tried to create another converter using the lua script ! cause I have no patience. but then despite how I literally just copy pasted the .ini and the .lua both into the skin folder before I'd try to modify it to suit my design needs, it didn't work somehow.

Image


nothing is happening on click and I'm baffled over how I can't even copy paste something properly
I have to download the lua libraries or something, do I ?
No, the likely problem is with Windows and Notepad. By default Windows "hides" the extensions for "known file types" (which is stupid beyond belief and you should change that setting). Then in Notepad, it defaults to saving files as "Text files (.txt). So in Notepad, when you create a .lua file and you put the name MySkin.lua and hit enter, it saves it as MySkin.lua.txt. You won't see this obvious problem in File Explorer, since... see "stupid beyond belief" above...

http://kb.winzip.com/kb/entry/26/
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 »

Code: Select all

No, the likely problem is with Windows and Notepad. By default Windows "hides" the extensions for "known file types" (which is stupid beyond belief and you should change that setting). Then in Notepad, it defaults to saving files as "Text files (.txt). So in Notepad, when you create a .lua file and you put the name MySkin.lua and hit enter, it saves it as MySkin.lua.txt. You won't see this obvious problem in File Explorer, since... see "stupid beyond belief" above...

http://kb.winzip.com/kb/entry/26/
okay so uh, my computer already is setup to NOT hide the extensions due to how i manipulate a lot of same name/different extensions files due to my art programs, and windows would always bitch to me about "changing the extension type" when i modify .txt files into inis and luas.
here's a screenshot to prove that even notepad++ doesn't think its a .txt but that it's definitely a lua, and a few more pics of windows clearly saying it's a lua as well
Image
ImageImage
so yeah I'm fairly sure it's me being an useless penguin and not my file system

also here's the compiled thing ! I hope I didn't screw that up
compiler_4.13.rmskin
the numberless one displays the original input but not the converted result, the 2 is for the .lua based one and the 3 is the one that displays the result but not the original input (that's the one it should open upon install, if I didn't heck that up)
you'll probably notice that in the 3, the original input... well, pops up on clicks after yet, doesn't pop up in the string bands. it's weird honestly



UPD8, i replaced the code for the .ini in the lua one with the second code and that at least fixed the reactive to click part
You do not have the required permissions to view the files attached to this post.
Last edited by AlphaEdd on February 22nd, 2018, 2:33 pm, edited 2 times in total.
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 »

The problem with the .lua is here:
1.png
.lua files need to be encoded as either ANSI or UTF-16 Little Endian (UCS-2 LE BOM in Notepad++). They won't be handled by Rainmeter correctly if they are UTF-8.
You do not have the required permissions to view the files attached to this post.
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 »

BTW, we strongly recommend against having spaces in config names (folders under your Skins folder). While not forbidden, you are going to always have to be extra careful that you quote things correctly when you use config names in bangs.
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 »

Not quite sure how, but it looks like all instances of ":" (colon) have been stripped out of your version of ConvertHEXRGB.lua.

It should be:

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
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 »

alright, will fix that quick ! and will avoid that in the future !

also, I have to say I'm not sure how that happened either ?? what ?? ? ? ?? but it works now thanks to the fixes so it's neat ! thank you !
Image