ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Returning multiple values, what? (https://www.esoui.com/forums/showthread.php?t=456)

Tingle0x539 04/01/14 03:32 AM

Returning multiple values, what?
 
GetColorAsRGB()

Returns: number red, number green, number blue

Can someone explain how to read this, I have never encountered a function that returns 3 separate values. Printing out what it returns gives me 1 all the time, how do I read the individual ones?

Edit, think I figured it out: local r, g, b = GetColorAsRGB();
But r g and b are all returning 1, so not sure if I did this correctly.

Tajin 04/01/14 05:53 AM

I assume that this function requires some arguments to work, surely it can not pull the RGBcode out of thin air? ;)

Sideshow 04/01/14 05:57 AM

Quote:

Originally Posted by Tingle0x539 (Post 2147)
GetColorAsRGB()

Returns: number red, number green, number blue

Can someone explain how to read this, I have never encountered a function that returns 3 separate values. Printing out what it returns gives me 1 all the time, how do I read the individual ones?

Edit, think I figured it out: local r, g, b = GetColorAsRGB();
But r g and b are all returning 1, so not sure if I did this correctly.

I suspect a color is needed as argument.
local r, g, b = GetColorAsRGB(myColorVariable);

skyraker 04/01/14 06:07 AM

Quote:

Originally Posted by Tingle0x539 (Post 2147)
GetColorAsRGB()

Returns: number red, number green, number blue

Can someone explain how to read this, I have never encountered a function that returns 3 separate values. Printing out what it returns gives me 1 all the time, how do I read the individual ones?

Edit, think I figured it out: local r, g, b = GetColorAsRGB();
But r g and b are all returning 1, so not sure if I did this correctly.

The color code in game is given as an RGB value from 0 to 1, and correlates to a percentage-type of value for each color.

Are you certain that it doesn't return 4 values? When we set colors in controls (ie a label control), we send SetColor(number r, number g, number b, number a), with the first three as discussed and a is the alpha-value.

EDIT: I see which function you are using, and there are only three parameters. But what I said about values is correct.

Pawkette 04/01/14 08:16 AM

Lua Code:
  1. ZO_ColorDef = ZO_Object:Subclass()
  2.  
  3. function ZO_ColorDef:New(r, g, b, a)
  4.     local c = ZO_Object.New(self)
  5.    
  6.     if(type(r) == "string") then            
  7.         c.a, c.r, c.g, c.b = ConvertHTMLColorToFloatValues(r)
  8.     elseif(type(r) == "table") then
  9.         local otherColorDef = r
  10.         c.r = otherColorDef.r or 1
  11.         c.g = otherColorDef.g or 1
  12.         c.b = otherColorDef.b or 1
  13.         c.a = otherColorDef.a or 1
  14.     else
  15.         c.r = r or 1
  16.         c.g = g or 1
  17.         c.b = b or 1
  18.         c.a = a or 1
  19.     end
  20.  
  21.     return c
  22. end
  23.  
  24. function ZO_ColorDef:FromInterfaceColor(colorType, fieldValue)
  25.     return ZO_ColorDef:New(GetInterfaceColor(colorType, fieldValue))
  26. end
  27.  
  28. function ZO_ColorDef:UnpackRGB()
  29.     return self.r, self.g, self.b
  30. end
  31.  
  32. function ZO_ColorDef:UnpackRGBA()
  33.     return self.r, self.g, self.b, self.a
  34. end
  35.  
  36. function ZO_ColorDef:SetRGB(r, g, b)
  37.     self.r = r
  38.     self.g = g
  39.     self.b = b
  40. end
  41.  
  42. function ZO_ColorDef:SetRGBA(r, g, b, a)
  43.     self.r = r
  44.     self.g = g
  45.     self.b = b
  46.     self.a = a
  47. end
  48.  
  49. function ZO_ColorDef:SetAlpha(a)
  50.     self.a = a
  51. end
  52.  
  53. function ZO_ColorDef:Clone()
  54.     return ZO_ColorDef:New(self:UnpackRGBA())
  55. end
  56.  
  57. function ZO_ColorDef:ToHex()
  58.     return string.format("%.2x%.2x%.2x", zo_floor(self.r * 255), zo_floor(self.g * 255), zo_floor(self.b * 255))
  59. end
  60.  
  61. function ZO_ColorDef:Colorize(text)
  62.     local combineTable = { "|c", self:ToHex(), tostring(text), "|r" }
  63.     return table.concat(combineTable)
  64. end
  65.  
  66. function ZO_ColorDef:Lerp(colorToLerpTorwards, amount)
  67.     return ZO_ColorDef:New(
  68.         zo_lerp(self.r, colorToLerpTorwards.r, amount),
  69.         zo_lerp(self.g, colorToLerpTorwards.g, amount),
  70.         zo_lerp(self.b, colorToLerpTorwards.b, amount),
  71.         zo_lerp(self.a, colorToLerpTorwards.a, amount)
  72.     )
  73. end

Tingle0x539 04/01/14 08:42 AM

Sorry I didn't reply, this is the proper usage:
Lua Code:
  1. colorWheel = WINDOW_MANAGER:CreateControl("MyColorWheel", parent, CT_COLORSELECT)
  2. colorWheel:SetAnchor(BOTTOMLEFT, parent, BOTTOMLEFT, -64, 64)
  3. colorWheel:SetDrawLayer(0)
  4. colorWheel:SetDimensions(64, 64)
  5. colorWheel:SetMouseEnabled(true) // This is what was missing, enabling this allows the color selection wheel to accept mouse input for its needed internal functions
  6. colorWheel:SetHidden(false)

Now after clicking, one can retrieve the color with
Lua Code:
  1. local red, green, blue = colorWheel:GetColorAsRGB();

Which are floats ranging from 0.0 also to 1.0 (0-255/0x00-0xFF)

I have not yet gotten the WheelThumb to work, but it is not needed. Clicking plainly on the wheel sets internal variables to the corresponding color one has clicked on.


All times are GMT -6. The time now is 08:33 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI