import "Turbine";
Turbine.Shell.WriteLine("ColorPicker demo");
-- Import the source code. If you would like to move the source code to a
-- different directory, edit the global 'Thurallor' variable.
ThurallorDir = "Thurallor.Common";
import (ThurallorDir .. ".UI.ColorPicker");
-- First let's create a window with some text in it. We'll use the ColorPicker
-- to adjust the text color.
testWindow = Turbine.UI.Window();
testWindow:SetVisible(true);
testWindow:SetSize(400, 100);
testText = Turbine.UI.Label();
testText:SetParent(testWindow);
testText:SetSize(testWindow:GetSize());
testText:SetFont(Turbine.UI.Lotro.Font.TrajanPro28);
testText:SetText("What color would you like this text to be?");
testText:SetForeColor(Turbine.UI.Color(0.5, 1.0, 1.0));
-- Now create a ColorPicker. No need to call SetVisible() or SetPosition().
colorPicker = Thurallor.UI.ColorPicker(testText:GetForeColor());
-- The ColorChanged event occurs whenever the user changes the current color
-- selection, either by moving the slider, moving the magnifier, or entering
-- a hex value. [If you don't want to handle real-time color updates, you can
-- ignore this event, and call the GetColor() method inside your Accepted and
-- Canceled event handlers.]
colorPicker.ColorChanged = function(picker)
testText:SetForeColor(picker:GetColor());
end
-- The Accepted event occurs when the user clicks the "OK" button. After
-- your handler returns, the ColorPicker instance is destroyed.
colorPicker.Accepted = function(picker)
local color = picker:GetColor();
testText:SetText(string.format("Accepted!\nNew color: (%.2f, %.2f, %.2f)", color.R, color.G, color.B));
end
-- The Canceled event occurs when the user clicks the "X" button. After
-- your handler returns, the ColorPicker instance is destroyed.
colorPicker.Canceled = function(picker)
local color = picker:GetColor();
testText:SetText(string.format("Canceled. Restored original\ncolor: (%.2f, %.2f, %.2f)", color.R, color.G, color.B));
end
-- The ColorPicker class is derived from Turbine.UI.Lotro.Window, so it
-- exposes all of the methods and events thereof. However, it specifies its
-- own handlers for some events. If you want to use these events, you should
-- modify the existing event handlers (in ColorPicker.lua) rather than
-- overwriting them:
-- SizeChanged
-- PositionChanged
-- Closing
Turbine.Plugin.Unload = function(sender, args)
colorPicker:Close();
end