View Single Post
06-09-05, 10:05 AM   #13
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
try the following code.

Your skinnable bar ----------
Code:
<Frame name="DiivSkins_hbar1" frameStrata="BACKGROUND" inherits="DiivSkins_hbarTemplate" parent="UIParent">
	<Size><AbsDimension x="512" y="46"/></Size>
	<Layers><Layer level="ARTWORK"><Texture name="DiivSkins_hbar1Texture" file="Interface\AddOns\DiivSkins\Skins\diivskins_01"><TexCoords left="0.0019531" right="1.0" top="0.0" bottom="0.0898437"/></Texture></Layer></Layers>
	<Anchors><Anchor point="BOTTOM"><Offset><AbsDimension x="215" y="550"/></Offset></Anchor></Anchors>
    <Scripts><OnLoad>this:RegisterEvent("VARIABLES_LOADED");</OnLoad><OnEvent>DS_TextureOnEvent();</OnEvent></Scripts>
</Frame>
your slider ------------------------
Code:
<Slider name="DiivSkins_hbar1Slider" inherits="OptionsSliderTemplate" minValue="2" maxValue="12" defaultValue="2" valueStep="1">
	<Size><AbsDimension x="160" y="17"/></Size>
	<Anchors><Anchor point="CENTER"/></Anchors>
	<Scripts>
		<OnLoad>
			getglobal(this:GetName().."Text"):SetText("Horizontal Bar 1");
			getglobal(this:GetName().."High"):SetText("12 slots");
			getglobal(this:GetName().."Low"):SetText("2 slot");
		</OnLoad>
		<OnShow>this:SetValue(DiivSkinSettings.hbar1);</OnShow>
		<OnValueChanged>
			DiivSkinSettings.hbar1 = this:GetValue();
			DiivSkins_TextureUpdate();
		</OnValueChanged>
	</Scripts>
</Slider>
and finally, the lua code ----------
Code:
-- Global Functions ---------------------------------------
function DS_FirstLoad()
	GameMenuFrame:Show();
	DS_Init:Show();
	DS_GameMenuButton:Hide();
	DS_GameMenuButton_Init:Show();
end
function DS_TextureOnEvent()
	if (event == "VARIABLES_LOADED") then 
		if (not DiivSkinSettings) then 
			DiivSkinSettings = {};
			DiivSkinSettings.hbar1 = 2;
			DS_FirstLoad();
		end
		DS_TextureUpdate();
	end
end
function DS_TextureUpdate()
	local key = DiivSkinSettings.hbar1;
	local var = DiivSkinTextures[key];
	DiivSkins_hbar1Texture:SetTexCoord(var.a, var.b, var.c, var.d);
end
-- Configuration Variables ---------------------------------
DiivSkinTextures = {};
DiivSkinTextures[2] = {a = 0.0, b = 1.0, c = 0.8984375, d = 0.9882812);
DiivSkinTextures[3] = {a = 0.0, b = 1.0, c = 0.8085937, d = 0.8984375);
DiivSkinTextures[4] = {a = 0.0, b = 1.0, c = 0.71875, d = 0.8085937);
DiivSkinTextures[5] = {a = 0.0, b = 1.0, c = 0.6289062, d = 0.71875);
DiivSkinTextures[6] = {a = 0.0, b = 1.0, c = 0.5390625, d = 0.6289062);
DiivSkinTextures[7] = {a = 0.0, b = 1.0, c = 0.4492187, d = 0.5390625);
DiivSkinTextures[8] = {a = 0.0, b = 1.0, c = 0.359375, d = 0.4492187);
DiivSkinTextures[9] = {a = 0.0, b = 1.0, c = 0.2695312, d = 0.359375);
DiivSkinTextures[10] = {a = 0.0, b = 1.0, c = 0.1796875, d = 0.2695312);
DiivSkinTextures[11] = {a = .0, b = 1.0, c = 0.0898437, d = 0.1796875);
DiivSkinTextures[12] = {a = 0.0, b = 1.0, c = 0.0, d = 0.0898437);
As an aside, I assume you plan to create multiple bars, and therefore plan to make each one skinnable. Let me know if this is teh case, as I have simple code that can be plugged into the existing functions to make them work for ANY bar you want. Makes sense to use a single function for all your bars, and make that function work based on which bar is being passed to it. Smaller footprint = good

Last edited by Beladona : 06-09-05 at 10:10 AM.
  Reply With Quote