| Home Page | Recent Changes | Preferences

Color Selection Dialog

Basic Color Selection Dialog

This class lets you provide color configuration. I haven't seen too many things that could use it, but who knows... Anyways, to use it, make a GUIPage, or whatever. The important point is having a GUILabel on it, and having a LastClicked property. Before you use OpenMenu to open the Color Chooser, set the LastClicked property of your class to the index in Controls of a GUILabel. The Color Chooser will initialize itself with the BackColor of this GUILabel, allow the user to edit that color, and then save the selected color back to the GUILabel. Add some code to load the label BackColor from defaults, and save it to an ini, and you have configurable colors.

class GUIColorEdit extends GUIPage;

var GUILabel SetTo;

function InitComponent(GUIController MyController, GUIComponent MyOwner)
{
    Super.InitComponent(MyController, MyOwner);
    SetTo=GUILabel(ParentPage.Controls[int(ParentPage.GetPropertyText("LastClicked"))]);
    InitColors();
    return;
}

function bool SetAndClose(GUIComponent Sender)
{
    Controller.CloseMenu(False);
    SetTo.BackColor = GUILabel(Controls[10]).BackColor;
    Return True;
}

function InitColors()
{
    GUILabel(Controls[10]).BackColor=SetTo.BackColor;
    GUISlider(Controls[4]).SetValue(SetTo.BackColor.R);
    GUISlider(Controls[5]).SetValue(SetTo.BackColor.G);
    GUISlider(Controls[6]).SetValue(SetTo.BackColor.B);
    GUINumericEdit(Controls[7]).SetValue(SetTo.BackColor.R);
    GUINumericEdit(Controls[8]).SetValue(SetTo.BackColor.G);
    GUINumericEdit(Controls[9]).SetValue(SetTo.BackColor.B);
}

function OnSliderChange(GUIComponent Sender)
{
    local int i;

    for (i=0; i<Controls.Length; i++)
        if (Controls[i] == Sender)
            break;
    if (i>3 && i<7)
    {
        GUINumericEdit(Controls[i+3]).SetValue(int(GUISlider(Controls[i]).Value));
        ColorUpdate();
    }
    return;
}

function OnREditChange(GUIComponent Sender)
{
    GUISlider(Controls[4]).SetValue(float(GUINumericEdit(Controls[7]).Value));
    ColorUpdate();
}

function OnGEditChange(GUIComponent Sender)
{
    GUISlider(Controls[5]).SetValue(float(GUINumericEdit(Controls[8]).Value));
    ColorUpdate();
}

function OnBEditChange(GUIComponent Sender)
{
    GUISlider(Controls[6]).SetValue(float(GUINumericEdit(Controls[9]).Value));
    ColorUpdate();
}

function ColorUpdate()
{
    GUILabel(Controls[10]).BackColor.R = int(GUISlider(Controls[4]).Value);
    GUILabel(Controls[10]).BackColor.G = int(GUISlider(Controls[5]).Value);
    GUILabel(Controls[10]).BackColor.B = int(GUISlider(Controls[6]).Value);
    return;
}

defaultproperties
{
    Begin Object Class=GUIButton name=DialogBackground
        WinWidth=1.0
        WinHeight=1.0
        WinTop=0
        WinLeft=0
        bAcceptsInput=false
        bNeverFocus=true
        StyleName="ComboListBox"
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(0)=GUIButton'DialogBackground'
    Begin Object Class=GUILabel name=RLabel
        Caption="R"
        WinWidth=0.142857
        WinHeight=0.111111
        WinLeft=0.071429
        WinTop=0.055556
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(1)=GUILabel'RLabel'
    Begin Object Class=GUILabel name=GLabel
        Caption="G"
        WinWidth=0.142857
        WinHeight=0.111111
        WinLeft=0.071429
        WinTop=0.222222
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(2)=GUILabel'GLabel'
    Begin Object Class=GUILabel name=BLabel
        Caption="B"
        WinWidth=0.142857
        WinHeight=0.111111
        WinLeft=0.071429
        WinTop=0.388889
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(3)=GUILabel'BLabel'
    Begin Object Class=GUISlider name=RSlider
        bIntSlider=True
        MinValue=0
        MaxValue=255
        WinWidth=0.357143
        WinHeight=0.111111
        WinLeft=0.285714
        WinTop=0.055556
        OnChange=OnSliderChange;
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(4)=GUISlider'RSlider'
    Begin Object Class=GUISlider name=GSlider
        bIntSlider=True
        MinValue=0
        MaxValue=255
        WinWidth=0.357143
        WinHeight=0.111111
        WinLeft=0.285714
        WinTop=0.222222
        OnChange=OnSliderChange;
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(5)=GUISlider'GSlider'
    Begin Object Class=GUISlider name=BSlider
        bIntSlider=True
        MinValue=0
        MaxValue=255
        WinWidth=0.357143
        WinHeight=0.111111
        WinLeft=0.285714
        WinTop=0.388889
        OnChange=OnSliderChange;
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(6)=GUISlider'BSlider'
    Begin Object Class=GUINumericEdit name=REdit
        MinValue=0
        MaxValue=255
        Step=1
        WinWidth=0.214286
        WinHeight=0.111111
        WinLeft=0.714286
        WinTop=0.055556
        OnChange=OnREditChange;
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(7)=GUINumericEdit'REdit'
    Begin Object Class=GUINumericEdit name=GEdit
        MinValue=0
        MaxValue=255
        Step=1
        WinWidth=0.214286
        WinHeight=0.111111
        WinLeft=0.714286
        WinTop=0.222222
        OnChange=OnGEditChange;
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(8)=GUINumericEdit'GEdit'
    Begin Object Class=GUINumericEdit name=BEdit
        MinValue=0
        MaxValue=255
        Step=1
        WinWidth=0.214286
        WinHeight=0.111111
        WinLeft=0.714286
        WinTop=0.388889
        OnChange=OnBEditChange;
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(9)=GUINumericEdit'BEdit'
    Begin Object Class=GUILabel name=ColorBox
        WinWidth=0.857143
        WinHeight=0.222222
        WinLeft=0.071429
        WinTop=0.555556
        bTransparent=False
        bAcceptsInput=False
        bNeverFocus=True
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(10)=GUILabel'ColorBox'
    Begin Object Class=GUIButton name=OkButton
        Caption="OK"
        WinWidth=0.214286
        WinHeight=0.111111
        WinLeft=0.392857
        WinTop=0.833333
        OnClick=SetAndClose
        bBoundToParent=True
        bScaleToParent=True
    End Object
    Controls(11)=GUIButton'OkButton'
    WinWidth=0.5
    WinHeight=0.5
    WinLeft=0.25
    WinTop=0.25
}

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In