-- @docclass UIRadialProgress = extends(UIWidget, "UIRadialProgress") function UIRadialProgress.create() local progressbar = UIRadialProgress.internalCreate() progressbar.progress = 100 progressbar.radial = false return progressbar end function UIRadialProgress:onStyleApply(name, node) for name,value in pairs(node) do if name == 'radial' then self:setRadial(value) end end end function UIRadialProgress:setProgress(value) self.progress = tonumber(value) or 100 self:updateProgressbar() end function UIRadialProgress:getProgress() return self.progress end function UIRadialProgress:setRadial(value) self.radial = not not value end function UIRadialProgress:isRadial() return self.radial end function UIRadialProgress:updateProgressbar() local progress1 = self:getChildById('progress1') local progress2 = self:getChildById('progress2') if not (progress1 and progress2) then return end local radius = progress1:getImageTextureWidth() local height = radius * 2 local progressRad = self.progress / 100 * math.pi * 2 -- calculate progressbar heights local height1 = radius * 2 local height2 = 0 if self.radial then if progressRad < math.pi then height1 = radius - math.cos(progressRad) * radius else progressRad = progressRad - math.pi height2 = radius - math.cos(progressRad) * radius end else if self.progress < 50 then height1 = self.progress / 50 * height else height2 = (self.progress-50) / 50 * height end end -- set image rects if height1 == 0 then progress1:hide() else progress1:show() progress1:setImageRect({x=0, y=0, width=radius, height=height1}) progress1:setImageClip({x=0, y=0, width=radius, height=height1}) end if height2 == 0 then progress2:hide() else progress2:show() progress2:setImageRect({x=0, y=height-height2, width=radius, height=height2}) progress2:setImageClip({x=0, y=height-height2, width=radius, height=height2}) end end