+ Reply to Thread
Results 1 to 5 of 5

Thread: Colors as tables and constants

  1. #1
    Soulwalker Helphant's Avatar
    Join Date
    Dec 2010
    Posts
    7

    Default Colors as tables and constants

    I'd love to see the various color functions use tables/arrays in addition to discrete values so that we could treat Color as an atomic value when appropriate. Discrete values are great when you want to perform calculations on the color but this is a fairly rare occurance (except for the alpha channel, obviously). If you add a default table of colors (perhaps the HTML/CSS named colors) whose values could be passed by reference through the API you would would have a win/win in terms of both legibility and memory efficiency.

    In code, the useage would change from this:

    myFrame:SetBackgroundColor(0.65,0.16,0.16)


    to this:

    myFrame:SetBackgroundColor(Color.brown)


    I envision combining the RGB values into a table but keeping the alpha separate for easy fade in/fade out animation. This would be in addition to the existing Setter that accepts discrete values. Something like this:

    SetBackgroundColor
    Sets the background color of this frame.
    Frame:SetBackgroundColor(c) -- table
    Frame:SetBackgroundColor(c, a) -- table, number
    Parameters:
    c: Color {
    b: Blue.
    g: Green.
    r: Red.
    }
    a: Alpha. 1 is fully opaque, 0 is fully transparent. Defaults to 1.


    For the Getter function it is less important that we return references to the default table since the typical use case is to re-use the color for another frame and not to compare the return value to that of another frame. Returning color as a table might look something like this:

    GetBackgroundColor
    Retrieves the background color of this frame.
    c, a = Frame:GetBackgroundColor() -- table, number <- void
    Results:
    c:
    {
    b: Blue.
    g: Green.
    r: Red.
    }
    a: Alpha. 1 is fully opaque, 0 is fully transparent.


    The constant table might look something like this if we chose to base it on the HTML/CSS standard named colors:

    Color = {
    AliceBlue={0.94,0.97,1.00},
    AntiqueWhite={0.98,0.92,0.84},
    Aqua={0,1.00,1.00},
    Aquamarine={0.50,1.00,0.83},
    Azure={0.94,1.00,1.00},
    Beige={0.96,0.96,0.86},
    Bisque={1.00,0.89,0.77},
    Black={0,0,0},
    BlanchedAlmond={1.00,0.92,0.80},
    Blue={0,0,1.00},
    BlueViolet={0.54,0.17,0.89},
    Brown={0.65,0.16,0.16},
    BurlyWood={0.87,0.72,0.53},
    CadetBlue={0.37,0.62,0.63},
    Chartreuse={0.50,1.00,0},
    Chocolate={0.82,0.41,0.12},
    Coral={1.00,0.50,0.31},
    CornflowerBlue={0.39,0.58,0.93},
    Cornsilk={1.00,0.97,0.86},
    Crimson={0.86,0.08,0.24},
    Cyan={0,1.00,1.00},
    DarkBlue={0,0,0.55},
    DarkCyan={0,0.55,0.55},
    DarkGoldenRod={0.72,0.53,0.04},
    DarkGray={0.66,0.66,0.66},
    DarkGrey={0.66,0.66,0.66},
    DarkGreen={0,0.39,0},
    DarkKhaki={0.74,0.72,0.42},
    DarkMagenta={0.55,0,0.55},
    DarkOliveGreen={0.33,0.42,0.18},
    Darkorange={1.00,0.55,0},
    DarkOrchid={0.60,0.20,0.80},
    DarkRed={0.55,0,0},
    DarkSalmon={0.91,0.59,0.48},
    DarkSeaGreen={0.56,0.74,0.56},
    DarkSlateBlue={0.28,0.24,0.55},
    DarkSlateGray={0.18,0.31,0.31},
    DarkSlateGrey={0.18,0.31,0.31},
    DarkTurquoise={0,0.81,0.82},
    DarkViolet={0.58,0,0.83},
    DeepPink={1.00,0.08,0.58},
    DeepSkyBlue={0,0.75,1.00},
    DimGray={0.41,0.41,0.41},
    DimGrey={0.41,0.41,0.41},
    DodgerBlue={0.12,0.56,1.00},
    FireBrick={0.70,0.13,0.13},
    FloralWhite={1.00,0.98,0.94},
    ForestGreen={0.13,0.55,0.13},
    Fuchsia={1.00,0,1.00},
    Gainsboro={0.86,0.86,0.86},
    GhostWhite={0.97,0.97,1.00},
    Gold={1.00,0.84,0},
    GoldenRod={0.85,0.65,0.13},
    Gray={0.50,0.50,0.50},
    Grey={0.50,0.50,0.50},
    Green={0,0.50,0},
    GreenYellow={0.68,1.00,0.18},
    HoneyDew={0.94,1.00,0.94},
    HotPink={1.00,0.41,0.71},
    IndianRed={0.80,0.36,0.36},
    Indigo={0.29,0,0.51},
    Ivory={1.00,1.00,0.94},
    Khaki={0.94,0.90,0.55},
    Lavender={0.90,0.90,0.98},
    LavenderBlush={1.00,0.94,0.96},
    LawnGreen={0.49,0.99,0},
    LemonChiffon={1.00,0.98,0.80},
    LightBlue={0.68,0.85,0.90},
    LightCoral={0.94,0.50,0.50},
    LightCyan={0.88,1.00,1.00},
    LightGoldenRodYellow={0.98,0.98,0.82},
    LightGray={0.83,0.83,0.83},
    LightGrey={0.83,0.83,0.83},
    LightGreen={0.56,0.93,0.56},
    LightPink={1.00,0.71,0.76},
    LightSalmon={1.00,0.63,0.48},
    LightSeaGreen={0.13,0.70,0.67},
    LightSkyBlue={0.53,0.81,0.98},
    LightSlateGray={0.47,0.53,0.60},
    LightSlateGrey={0.47,0.53,0.60},
    LightSteelBlue={0.69,0.77,0.87},
    LightYellow={1.00,1.00,0.88},
    Lime={0,1.00,0},
    LimeGreen={0.20,0.80,0.20},
    Linen={0.98,0.94,0.90},
    Magenta={1.00,0,1.00},
    Maroon={0.50,0,0},
    MediumAquaMarine={0.40,0.80,0.67},
    MediumBlue={0,0,0.80},
    MediumOrchid={0.73,0.33,0.83},
    MediumPurple={0.58,0.44,0.85},
    MediumSeaGreen={0.24,0.70,0.44},
    MediumSlateBlue={0.48,0.41,0.93},
    MediumSpringGreen={0,0.98,0.60},
    MediumTurquoise={0.28,0.82,0.80},
    MediumVioletRed={0.78,0.08,0.52},
    MidnightBlue={0.10,0.10,0.44},
    MintCream={0.96,1.00,0.98},
    MistyRose={1.00,0.89,0.88},
    Moccasin={1.00,0.89,0.71},
    NavajoWhite={1.00,0.87,0.68},
    Navy={0,0,0.50},
    OldLace={0.99,0.96,0.90},
    Olive={0.50,0.50,0},
    OliveDrab={0.42,0.56,0.14},
    Orange={1.00,0.65,0},
    OrangeRed={1.00,0.27,0},
    Orchid={0.85,0.44,0.84},
    PaleGoldenRod={0.93,0.91,0.67},
    PaleGreen={0.60,0.98,0.60},
    PaleTurquoise={0.69,0.93,0.93},
    PaleVioletRed={0.85,0.44,0.58},
    PapayaWhip={1.00,0.94,0.84},
    PeachPuff={1.00,0.85,0.73},
    Peru={0.80,0.52,0.25},
    Pink={1.00,0.75,0.80},
    Plum={0.87,0.63,0.87},
    PowderBlue={0.69,0.88,0.90},
    Purple={0.50,0,0.50},
    Red={1.00,0,0},
    RosyBrown={0.74,0.56,0.56},
    RoyalBlue={0.25,0.41,0.88},
    SaddleBrown={0.55,0.27,0.07},
    Salmon={0.98,0.50,0.45},
    SandyBrown={0.96,0.64,0.38},
    SeaGreen={0.18,0.55,0.34},
    SeaShell={1.00,0.96,0.93},
    Sienna={0.63,0.32,0.18},
    Silver={0.75,0.75,0.75},
    SkyBlue={0.53,0.81,0.92},
    SlateBlue={0.42,0.35,0.80},
    SlateGray={0.44,0.50,0.56},
    SlateGrey={0.44,0.50,0.56},
    Snow={1.00,0.98,0.98},
    SpringGreen={0,1.00,0.50},
    SteelBlue={0.27,0.51,0.71},
    Tan={0.82,0.71,0.55},
    Teal={0,0.50,0.50},
    Thistle={0.85,0.75,0.85},
    Tomato={1.00,0.39,0.28},
    Turquoise={0.25,0.88,0.82},
    Violet={0.93,0.51,0.93},
    Wheat={0.96,0.87,0.70},
    White={1.00,1.00,1.00},
    WhiteSmoke={0.96,0.96,0.96},
    Yellow={1.00,1.00,0},
    YellowGreen={0.60,0.80,0.20},
    }
    Go for the eyes Boo, GO FOR THE EYES!

  2. #2
    Soulwalker
    Join Date
    Apr 2011
    Posts
    22

    Default

    you can still make a wrapper.

    Assuming dependencies will be coming, you can do something like

    Code:
    local old_frame_func = UI.CreateFrame
    
    function UI:CreateFrame(type, name, parent)
       local frame = old_frame_func(type, name, parent)
    
       frame.old_bg_func = frame.SetBackgroundColor
    
       function frame:SetBackgroundColor(arg1, arg2, arg3, arg4)
           local r, g, b, a
           -- do argument check, and determine wether it's a single name, or a explicit color
           -- do your stuff
           self:old_bg_func(r,g,b,a)
       end
    
       return frame
    end
    Please note that you must only add features. All existing the same features MUST work the same way with the wrapper.
    Last edited by Alkazar; 06-10-2011 at 08:46 AM.

  3. #3
    Rift Disciple
    Join Date
    Feb 2011
    Posts
    160

    Default

    Quote Originally Posted by Alkazar View Post
    you can still make a wrapper.

    Assuming dependencies will be coming, you can do something like
    [snip]
    Please note that you must only add features. All existing the same features MUST work the same way with the wrapper.
    Eep, that is going to truly break things when Trion adds features, assuming it doesn't break beforehand due to some conflicts with multiple addons doing this.

    A voluntary jQuery-style wrapper would be much better and won't harm us nearly as much if the API changes for any reason.

  4. #4
    Soulwalker Helphant's Avatar
    Join Date
    Dec 2010
    Posts
    7

    Default Wrappers and memory

    While sub-classing and wrapping alone make the code somewhat more readable in the short term they cause long-term maintenance issues and use a lot more memory.
    Go for the eyes Boo, GO FOR THE EYES!

  5. #5
    Soulwalker
    Join Date
    Apr 2011
    Posts
    22

    Default

    Well, I don't see why it would break if TRION add features. If they edit an existing method, yeah it's going to break, but even without a wrapper.

    Well, I'm not for using wrapper and subclassing everywhere I can. But here is truely the only solution I can find to expand natives' functionnality.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts