Opened 6 years ago

Closed 6 years ago

#1110 closed defect (fixed)

Wierd chili issues with colorbars

Reported by: beherith Owned by:
Priority: major Milestone:
Component: BAR Version:
Keywords: Cc:

Description

I needed some colorbars, so I decided to try chili.

I didnt like the small slivers of colorbar that chili renders, and they are hard to click too, so I tried changing the rendering function of Colorbars:DrawControl().

The issue:

No matter what I change in the Colorbars:DrawControl(), it doesnt have ANY effect. If i intentionally put a syntax error in it, it crashes chili.

Here is the changed Colorbars:DrawControl():

--//=============================================================================

--- Colorbars module

--- Colorbar fields.
-- Inherits from Control.
-- @see control.Control
-- @table Colorbars
-- @tparam {r,g,b,a} color color table, (default {1,1,1,1})
-- @tparam {func1,func2,...} OnChange listener functions for color changes, (default {})
Colorbars = Control:Inherit{
  classname = "colorbars",
  color     = {1,1,1,1},

  defaultWidth = 100,
  defaultHeight = 20,

  OnChange = {},
}

local this = Colorbars
local inherited = this.inherited

--//=============================================================================

--- Sets the new color
-- @tparam {r,g,b,a} c color table 
function Colorbars:SetColor(c)
Spring.Echo("function Colorbars:SetColor()")
  self.value = c
  self:CallListeners(self.OnChange,c)
  self:Invalidate()
end

--//=============================================================================

local GL_LINE_LOOP = GL.LINE_LOOP
local GL_LINES = GL.LINES
local glPushMatrix = gl.PushMatrix
local glPopMatrix  = gl.PopMatrix
local glTranslate  = gl.Translate
local glVertex   = gl.Vertex
local glRect     = gl.Rect
local glColor    = gl.Color
local glBeginEnd = gl.BeginEnd

function Colorbars:DrawControl()
	Spring.Echo("function Colorbars:DrawControl()")
  local barswidth  = self.width - (self.height + 4)

  local color = self.color
  local step = self.height/7

  --bars
  local rX1,rY1,rX2,rY2 = 0,0*step,color[1]*barswidth,0.5*step
  local gX1,gY1,gX2,gY2 = 10,2*step,color[2]*barswidth,4*step
  local bX1,bY1,bX2,bY2 = 0,4*step,color[3]*barswidth,5*step
  local aX1,aY1,aX2,aY2 = 0,6*step,(color[4] or 1)*barswidth,7*step

  glColor(1,0,1,1)
  glRect(rX1,rY1,rX2,rY2)

  glColor(0,1,0,1)
  glRect(gX1,gY1,gX2,gY2)

  glColor(0,0,1,1)
  glRect(bX1,bY1,bX2,bY2)

  glColor(1,1,0,1)
  -- glRect(aX1,aY1,aX2,aY2)

  -- glColor(self.color)
  --glColor(0,1,0,1)
  glRect(barswidth + 2,self.height,self.width - 2,0)

  gl.BeginEnd(GL.TRIANGLE_STRIP, theme.DrawBorder_, barswidth + 2,0,self.width - barswidth - 4,self.height, 1, self.borderColor, self.borderColor2)
end

--//=============================================================================

function Colorbars:HitTest()
  return self
end

function Colorbars:MouseDown(x,y)
  local step = self.height/7
  local yp = y/step
  local r  = yp%2
  local barswidth = self.width - (self.height + 4)

  if (x<=barswidth)and(r<=1) then
    local barIdx = (yp-r)/2 + 1
    local newvalue = x/barswidth
    if (newvalue>1) then newvalue=1 elseif (newvalue<0) then newvalue=0 end
    self.color[barIdx] = newvalue
    self:SetColor(self.color)
    return self
  end
end

function Colorbars:MouseMove(x,y,dx,dy,button)
  if (button==1) then
    return self:MouseDown(x,y)
  end
end

--//=============================================================================

Change History (3)

comment:1 by Bluestone, 6 years ago

I will look at this but I'm busy with real life until probably next weekend. Things to check might be (1) chili lives in /libs, idk if that gets reloaded with a luaui reload (2) inheritance might be overruling your changes

comment:2 by beherith, 6 years ago

Thanks man, you were right. It was overridden in \libs\chili\skins\default\skin.lua

comment:3 by beherith, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.