Hiya,
Did these two last year, and thought I'd share them. First up, a little skins + script that reads the latest Windows 8 Automatic Aero Color from the registry, and then does a little math and color conversion so that when Rainmeter uses that color, it actually matches.
It's within 1/255 of the actual color. Also, calculates two different contrasting colors for use in the skin as well.
Code: Select all
function Initialize()
msMeasureW8Color = SKIN:GetMeasure('MeasureW8Color')
msMeasureW8Balance = SKIN:GetMeasure('MeasureW8ColorBalance')
end -- function Initialize
function Update()
-- Get data from measures
DecColor = msMeasureW8Color:GetValue()
ColorBal = msMeasureW8Balance:GetValue()
-- Split for Processing
HexColor = Dec2Hex(DecColor)
HexRGB = string.sub(HexColor, 3)
HexAlpha = string.sub(HexColor, 1,2)
-- Processing
HexRGB = BalColor(HexRGB, (ColorBal/100), tonumber("0x" .. HexAlpha)/255)
HexRGBInv = InvColor(HexRGB)
HexRGBAlt = AltColor(HexRGB)
-- Save Data
SKIN:Bang("!WriteKeyValue Variables WinColor " .. HexRGB .. SKIN:ReplaceVariables(" #IncFile# "))
SKIN:Bang("!WriteKeyValue Variables WinAlpha " .. HexAlpha .. SKIN:ReplaceVariables(" #IncFile# "))
SKIN:Bang("!WriteKeyValue Variables InvColor " .. HexRGBInv .. SKIN:ReplaceVariables(" #IncFile# "))
SKIN:Bang("!WriteKeyValue Variables AltColor " .. HexRGBAlt .. SKIN:ReplaceVariables(" #IncFile# "))
SetVars()
SetVars("DDWin8\\Process")
return 0
end
function SetVars( Skin )
if Skin == nil then Skin = " " end
local Config = Skin
SKIN:Bang("!SetVariable WinColor " .. HexRGB .. " " .. Config)
SKIN:Bang("!SetVariable WinAlpha " .. HexAlpha .. " " .. Config)
SKIN:Bang("!SetVariable InvColor " .. HexRGBInv .. " " .. Config)
SKIN:Bang("!SetVariable AltColor " .. HexRGBAlt .. " " .. Config)
end -- SetVars
function Dec2Hex(nValue)
-- Convert string to number if needed
if type(nValue) == "string" then
nValue = String.ToNumber(nValue)
end
nHexVal = string.format("%X", nValue)
-- Convert number to string
sHexVal = nHexVal..""
return sHexVal
end
function InvColor(HexRGBString)
local R = tonumber( "0x" .. string.sub(HexRGBString, 1,2) ) / 255
local G = tonumber( "0x" .. string.sub(HexRGBString, 3,4) ) / 255
local B = tonumber( "0x" .. string.sub(HexRGBString, 5,6) ) / 255
-- print("RGB: " .. R .. " " .. G .. " " .. B)
-- RGB to HSV
local H,S,V, Delta
local MAX = math.max(R, G, B)
local MIN = math.min(R, G, B)
V = MAX
Delta = MAX - MIN
if MAX ~= 0 then
S = Delta / MAX
if MAX == R then
H = (G - B) / Delta
elseif MAX == G then
H = 2 + (B - R) / Delta
else
H = 4 + (R - G) / Delta
end
else
S, H = 0, -1
end
H = H * 60
if H < 0 then H = H + 360 end
-- print("HSV: " .. H .. " " .. S .. " " .. V)
-- HSV Invert
H = (H + 180) % 360
S = 1 - S
V = 1 - V
-- HSV to RGB
local Hi = math.floor(H/60)
local H = H / 60
local f = H - Hi
local p = V * (1-S)
local q = V * (1-f*S)
local t = V * (1-(1-f)*S)
if Hi == 0 then
R = V
G = t
B = p
elseif Hi == 1 then
R = q
G = V
B = p
elseif Hi == 2 then
R = p
G = V
B = t
elseif Hi == 3 then
R = p
G = q
B = V
elseif Hi == 4 then
R = t
G = p
B = V
elseif Hi == 5 then
R = V
G = p
B = q
end
R = math.floor(R * 255)
G = math.floor(G * 255)
B = math.floor(B * 255)
-- print("InvRGB: " .. R .. " " .. G .. " " .. B)
-- And back
local HexR = string.format("%02X", R) .. ""
local HexG = string.format("%02X", G) .. ""
local HexB = string.format("%02X", B) .. ""
return HexR .. HexG .. HexB
end
function AltColor(HexRGBString)
local R = tonumber( "0x" .. string.sub(HexRGBString, 1,2) )
local G = tonumber( "0x" .. string.sub(HexRGBString, 3,4) )
local B = tonumber( "0x" .. string.sub(HexRGBString, 5,6) )
-- print("RGB: " .. R .. " " .. G .. " " .. B)
R = math.floor((R + 127) % 256)
G = math.floor((G + 127) % 256)
B = math.floor((B + 127) % 256)
-- print("AltRGB: " .. R .. " " .. G .. " " .. B)
-- And back
local HexR = string.format("%02X", R) .. ""
local HexG = string.format("%02X", G) .. ""
local HexB = string.format("%02X", B) .. ""
return HexR .. HexG .. HexB
end
function BalColor(HexRGBString, Balance, Alpha)
local R = tonumber( "0x" .. string.sub(HexRGBString, 1,2) )
local G = tonumber( "0x" .. string.sub(HexRGBString, 3,4) )
local B = tonumber( "0x" .. string.sub(HexRGBString, 5,6) )
-- print("RGB: " .. R .. " " .. G .. " " .. B)
R = math.floor(( (R * (Balance)) + (218 * (1 - Balance)) ) % 256)
G = math.floor(( (G * (Balance)) + (218 * (1 - Balance)) ) % 256)
B = math.floor(( (B * (Balance)) + (218 * (1 - Balance)) ) % 256)
-- print("BalRGB: " .. R .. " " .. G .. " " .. B)
-- And back
local HexR = string.format("%02X", R) .. ""
local HexG = string.format("%02X", G) .. ""
local HexB = string.format("%02X", B) .. ""
return HexR .. HexG .. HexB
end
It adds new exe files to the .inc file if there are unknowns for you to edit to taste. Uses the ReadIni script I found here for that.
Code: Select all
function Initialize()
msMeasureCPU = SKIN:GetMeasure("MeasureCPUProcs")
msMeasureMem = SKIN:GetMeasure("MeasureMemProcs")
sIncPath = SKIN:GetVariable("CURRENTPATH") .. "ProcessName.inc"
tProcessName = ReadIni(sIncPath)
sSectionName = "ProcessName"
end -- function Initialize
function Update()
-- Get data from measures
local sCPU = msMeasureCPU:GetStringValue()
local sMem = msMeasureMem:GetStringValue()
-- Combine for processing
local sCombined = sCPU .. " \n" .. sMem .. " "
-- Checking for new processes
for sProcessName in sCombined:gmatch("N%:%s(.-)%#?%d?%d?") do
if tProcessName[sProcessName:gsub("%s","")] == nil then
tProcessName[sProcessName:gsub("%s","")] = sProcessName
WriteIni(sIncPath,sSectionName,sProcessName:gsub("%s","")," " .. sProcessName .. " ")
print("Added new process " .. sProcessName .. " to INC file")
end
end
local sCombined = sCombined:gsub("(.-)%#?%d?%d?%s", tProcessName )
-- Split back into variables
local sCPUProcs = sCombined:gsub("%[M%a%:.-%]","")
local sCPUProcsP = sCPUProcs:gsub("%[CN%:.-%]","\n")
local sCPUProcsN = sCPUProcs:gsub("%[CC%:.-%]","\n")
sCPUProcsP = sCPUProcsP:gsub("(%[%a%a%:)(.-)(%])","| %2")
sCPUProcsN = sCPUProcsN:gsub("(%[%a%a%:)(.-)(%])","| %2")
sCPUProcsP = sCPUProcsP:gsub("\n","")
sCPUProcsP = sCPUProcsP:gsub("%s","")
sCPUProcsN = sCPUProcsN:gsub("\n","")
sCPUProcsP = sCPUProcsP:gsub("|","\n")
sCPUProcsN = sCPUProcsN:gsub("|","\n")
local sMemProcs = sCombined:gsub("%[C%a%:.-%]","")
local sMemProcsP = sMemProcs:gsub("%[MN%:.-%]","")
local sMemProcsN = sMemProcs:gsub("%[MC%:.-%]","")
sMemProcsP = sMemProcsP:gsub("(%[%a%a%:)(.-)(%]) ","%2|")
sMemProcsN = sMemProcsN:gsub("(%[%a%a%:)(.-)(%]) ","%2|")
sMemProcsP = sMemProcsP:gsub("\n","")
sMemProcsP = sMemProcsP:gsub("%s","")
sMemProcsN = sMemProcsN:gsub("\n","")
sMemProcsN = sMemProcsN:gsub("%s%s","")
sMemProcsP = sMemProcsP:gsub("|","\n")
sMemProcsN = sMemProcsN:gsub("|","\n")
-- Import into Rainmeter
SKIN:Bang("!SetVariable CPUProcsN \"" .. sCPUProcsN .. "\"")
SKIN:Bang("!SetVariable CPUProcsP \"" .. sCPUProcsP .. "\"")
SKIN:Bang("!SetVariable MemProcsN \"" .. sMemProcsN .. "\"")
SKIN:Bang("!SetVariable MemProcsP \"" .. sMemProcsP .. "\"")
return(sCombined)
end -- function Update
function ReadIni(filename)
local f = io.open(filename,'r')
if not f then return nil, print("ReadIni: Can't open file: "..filename) end
local line_counter=0
local tablename = {}
local section
for fline in f:lines() do
line_counter=line_counter+1
-- Ignore leading and trailing spaces
local line = fline:match("^%s*(.-)%s*$")
-- Ignore comments
if not line:match("^[%;#]") and #line > 0 then
-- Check for [Section]
local sec = line:match("^%[(.*)%]$")
if sec then
section = sec
-- if not tablename[section] then tablename[section]={} end
else
-- parse Key=Value
local key, value = line:match("([^=]*)%=(.*)")
-- Remove white space from Key=Value
key = key:match("^%s*(%S*)%s*$")
value = value:match("^%s*(.-)%s*$")
-- Check for error
if not (key and value) then return nil, print('Error bad key or value in file:'.. filename..': '.. line_counter.."\n line:".. fline) end
-- Set Section/Key/Value in table
if section then
if not tablename[key] then tablename[key]=value end
-- if not tablename[key][value] then tablename[key][value]={} end
end
end
end
end
f:close()
return tablename
end -- function ReadIni
function WriteIni(file,section,key,value)
local hFile=io.input(file,'r')
if not io.type(hFile)=='file' then
print('Cannot open file: '..file)
else
local Text=io.read('*all')
hFile=io.output(file,'w')
local NewText=string.gsub(Text,
'%['..section..']([^%[]+)',
function(a)
if string.match(a,'\n%s-'..key..'%s-=') then
a=string.gsub(a,'\n%s-'..key..'%s-=%s-([^;\n]+)','\n'..key..'='..value)
else
a=(string.match(a,'(.+)\n$') or '')..'\n'..key..'='..value..'\n'
end
return '['..section..']'..a
end
)
io.write(NewText)
io.close(hFile)
end
end -- function WriteIni
Hope this helps someone in the same way this board helped me make these.
$d