Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge with zk + chobby chili. #2

Merged
merged 2 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions luaui/chili/chili/controls/button.lua
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
--//=============================================================================
--// =============================================================================

--- Button module

--- Button fields.
-- Inherits from Control.
-- @see control.Control
-- @table Button
-- @string[opt="button"] caption caption to be displayed
-- @string[opt = "button"] caption caption to be displayed
Button = Control:Inherit{
classname= "button",
caption = 'button',
defaultWidth = 70,
defaultHeight = 20,
classname = "button",
caption = 'button',
captionAlign = nil,
defaultWidth = 70,
defaultHeight = 20,

align = "center",
valign = "center",
align = "center",
valign = "center",
}

local this = Button
local inherited = this.inherited

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

--- Sets the caption of the button
-- @string caption new caption of the button
function Button:SetCaption(caption)
if (self.caption == caption) then return end
self.caption = caption
self:Invalidate()
if (self.caption == caption) then
return
end
self.caption = caption
self:Invalidate()
end

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

function Button:DrawControl()
--// gets overriden by the skin/theme
--// gets overriden by the skin/theme
end

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

function Button:HitTest(x,y)
return self
function Button:HitTest(x, y)
return self
end

function Button:MouseDown(...)
self.state.pressed = true
inherited.MouseDown(self, ...)
self:Invalidate()
return self
self.state.pressed = true
inherited.MouseDown(self, ...)
self:Invalidate()
return self
end

function Button:MouseUp(...)
if (self.state.pressed) then
self.state.pressed = false
inherited.MouseUp(self, ...)
self:Invalidate()
return self
end
if (self.state.pressed) then
self.state.pressed = false
inherited.MouseUp(self, ...)
self:Invalidate()
return self
end
end

--//=============================================================================
--// =============================================================================
73 changes: 37 additions & 36 deletions luaui/chili/chili/controls/checkbox.lua
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
--//=============================================================================
--// =============================================================================

--- Checkbox module

--- Checkbox fields.
-- Inherits from Control.
-- @see control.Control
-- @table Checkbox
-- @bool[opt=true] checked checkbox checked state
-- @string[opt="text"] caption caption to appear in the checkbox
-- @string[opt="left"] textalign text alignment
-- @string[opt="right"] boxalign box alignment
-- @int[opt=10] boxsize box size
-- @tparam {r,g,b,a} textColor text color, (default {0,0,0,1})
-- @tparam {func1,func2,...} OnChange listener functions for checked state changes, (default {})
-- @bool[opt = true] checked checkbox checked state
-- @string[opt = "text"] caption caption to appear in the checkbox
-- @string[opt = "left"] textalign text alignment
-- @string[opt = "right"] boxalign box alignment
-- @int[opt = 10] boxsize box size
-- @tparam {r, g, b, a} textColor text color, (default {0, 0, 0, 1})
-- @tparam {func1, func2, ...} OnChange listener functions for checked state changes, (default {})
Checkbox = Control:Inherit{
classname = "checkbox",
checked = true,
caption = "text",
textalign = "left",
boxalign = "right",
boxsize = 10,
classname = "checkbox",
checked = true,
caption = "text",
textalign = "left",
valign = "linecenter",
boxalign = "right",
boxsize = 10,

textColor = {0,0,0,1},
textColor = {0, 0, 0, 1},

defaultWidth = 70,
defaultHeight = 18,
defaultWidth = 70,
defaultHeight = 18,

OnChange = {}
OnChange = {}
}

local this = Checkbox
local inherited = this.inherited

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

function Checkbox:New(obj)
obj = inherited.New(self,obj)
obj = inherited.New(self, obj)
obj.state.checked = obj.checked
return obj
end

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

--- Toggles the checked state
function Checkbox:Toggle()
self:CallListeners(self.OnChange,not self.checked)
self.checked = not self.checked
self.state.checked = self.checked
self:Invalidate()
self:CallListeners(self.OnChange, not self.checked)
self.checked = not self.checked
self.state.checked = self.checked
self:Invalidate()
end

function Checkbox:SetToggle(value)
self:CallListeners(self.OnChange, value)
self.checked = value
self.state.checked = self.checked
self:Invalidate()
self:CallListeners(self.OnChange, value)
self.checked = value
self.state.checked = self.checked
self:Invalidate()
end

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

function Checkbox:DrawControl()
--// gets overriden by the skin/theme
--// gets overriden by the skin/theme
end

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

function Checkbox:HitTest()
return self
return self
end

function Checkbox:MouseDown()
self:Toggle()
return self
self:Toggle()
return self
end

--//=============================================================================
--// =============================================================================
112 changes: 58 additions & 54 deletions luaui/chili/chili/controls/colorbars.lua
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
--//=============================================================================
--// =============================================================================

--- 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 {})
-- @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},
classname = "colorbars",
color = {1, 1, 1, 1},

defaultWidth = 100,
defaultHeight = 20,
defaultWidth = 100,
defaultHeight = 20,

OnChange = {},
OnChange = {},
}

local this = Colorbars
local inherited = this.inherited

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

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

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

local GL_LINE_LOOP = GL.LINE_LOOP
local GL_LINES = GL.LINES
Expand All @@ -44,61 +44,65 @@ local glColor = gl.Color
local glBeginEnd = gl.BeginEnd

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

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

--bars
local rX1,rY1,rX2,rY2 = 0,0*step,color[1]*barswidth,1*step
local gX1,gY1,gX2,gY2 = 0,2*step,color[2]*barswidth,3*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
--bars
local rX1, rY1, rX2, rY2 = 0, 0*step, color[1]*barswidth, 1*step
local gX1, gY1, gX2, gY2 = 0, 2*step, color[2]*barswidth, 3*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,0,1)
glRect(rX1,rY1,rX2,rY2)
glColor(1, 0, 0, 1)
glRect(rX1, rY1, rX2, rY2)

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

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

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

glColor(self.color)
glRect(barswidth + 2,self.height,self.width - 2,0)
glColor(self.color)
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)
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
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
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
function Colorbars:MouseMove(x, y, dx, dy, button)
if (button == 1) then
return self:MouseDown(x, y)
end
end

--//=============================================================================
--// =============================================================================
Loading