Thread: snippets/plugin
View Single Post
Unread 06-16-11, 10:08 AM   #5
phoenik
Bomani Harbinger
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 7
For those who like to use hex colors and are off put by the RGB we have now here you go
Code:
local function GetRGB(hex)
	local tbl = {}
	tbl.r = tonumber("0x" .. string.sub(hex, 1, 2)) / 255
	tbl.g = tonumber("0x" .. string.sub(hex, 3, 4)) / 255
	tbl.b = tonumber("0x" .. string.sub(hex, 5, 6)) / 255
	return tbl
end
Pretty simple. Returns a table with r, g, b values that you can use to easily set a color for your element.

Example Use:
Code:
local context = UI.CreateContext("SampleContext")
local frame = UI.CreateFrame("Frame", "SampleFrame", context)
local rgb = GetRGB("FF00DD")
frame:SetBackgroundColor(rgb.r, rgb.g, rgb.b, 1)
Can probably implement this in a way that lets users enter a hex number into the console for a color .

Last edited by phoenik : 06-16-11 at 10:10 AM. Reason: thought!
phoenik is offline   Reply With Quote