scaling mostly working

This commit is contained in:
Paul Liverman III 2017-07-26 23:08:50 -07:00
parent c0bf02ccc1
commit 8869727321
2 changed files with 57 additions and 80 deletions

View File

@ -38,6 +38,7 @@ function love.draw()
profiler:draw() profiler:draw()
-- temporary -- temporary
love.graphics.setColor(255, 255, 255, 255)
love.graphics.line(w/2, 0, w/2, h) love.graphics.line(w/2, 0, w/2, h)
love.graphics.line(0, h/2, w, h/2) love.graphics.line(0, h/2, w, h/2)
end end
@ -61,3 +62,13 @@ function love.keypressed(key)
profiler:keypressed(key) profiler:keypressed(key)
end end
function love.wheelmoved(x, y)
if y < 0 then
-- up
profiler.scale = profiler.scale - 0.1
else
-- down
profiler.scale = profiler.scale + 0.1
end
end

View File

@ -63,9 +63,9 @@ function piefiller:new(settings)
self.timer = 0 self.timer = 0
self.depth = 2 self.depth = 2
self.small = false self.small = false
self.x = 0.5 self.x = 0
self.y = 0.5 self.y = 0
self.scale = 0.5 self.scale = 0.4
self.font = love.graphics.newFont(16 / self.scale) self.font = love.graphics.newFont(16 / self.scale)
self.visible = true self.visible = true
self.step = 1 self.step = 1
@ -74,8 +74,8 @@ function piefiller:new(settings)
reset = "r", reset = "r",
increase_depth = "down", increase_depth = "down",
decrease_depth = "up", decrease_depth = "up",
increase_step_size = "=", increase_step_size = "-",
decrease_step_size = "-", decrease_step_size = "=",
shorten_names = "z", shorten_names = "z",
show_hidden = "h", show_hidden = "h",
save_to_file = "e", save_to_file = "e",
@ -239,37 +239,37 @@ function piefiller:draw(args)
local loading local loading
local oldFont = love.graphics.getFont() local oldFont = love.graphics.getFont()
local oldLineJoin = love.graphics.getLineJoin() local oldLineJoin = love.graphics.getLineJoin()
local args = args or {}
local rad = args.radius
local mode = args.mode or "list" -- "original" for the original style
local pi = math.pi local pi = math.pi
local arc = love.graphics.arc local arc = love.graphics.arc
local w,h = love.graphics.getDimensions() local w,h = love.graphics.getDimensions()
if not args.radius then local args = args or {}
if mode == "list" then local rad = args.radius or (h * self.scale - 2 / self.scale)
rad = h * self.scale - 2 / self.scale local mode = args.mode or "original" -- "original" for the original style
elseif mode == "original" then
rad = 200
end
end
love.graphics.push() love.graphics.push()
love.graphics.translate(self.x * w - w/2, self.y * h - h/2) love.graphics.translate(self.x, self.y)
love.graphics.scale(self.scale) love.graphics.scale(self.scale)
love.graphics.setLineJoin("bevel") love.graphics.setLineJoin("bevel")
love.graphics.setFont(self.font) love.graphics.setFont(self.font)
local cx = w/2 + (rad*2 - w)/2 + 2 / self.scale
local cy = h * self.scale
local maxLength = 0
for i,v in ipairs(self.parsed) do
local s = self.font:getWidth(self:getText(v))
if s > maxLength then maxLength = s end
end
setColor(self.background) setColor(self.background)
love.graphics.rectangle("fill", 0, 0, w, h) love.graphics.rectangle("fill", 0, 0, cx * 2 + 2 / self.scale + maxLength, cy * 2)
if self.parsed and self.totaltime > 0 then if self.parsed and self.totaltime > 0 then
local lastangle = 0 local lastangle = 0
for i,v in ipairs(self.parsed) do for i,v in ipairs(self.parsed) do
local color = v.color local color = v.color
local cx,cy = w/2,h/2
local angle = math.rad(3.6*v.prc) local angle = math.rad(3.6*v.prc)
setColor(color) setColor(color)
arc("fill",cx,cy,rad,lastangle,lastangle + angle) arc("fill",cx,cy,rad,lastangle,lastangle + angle)
@ -280,11 +280,12 @@ function piefiller:draw(args)
lastangle = lastangle + angle lastangle = lastangle + angle
end end
love.graphics.circle("line", w/2, h/2, rad) -- make sure there is an outer white border love.graphics.circle("line", cx, cy, rad) -- make sure there is an outer white border
if mode == "list" then local x = cx + rad + 2 / self.scale
local x = w/2 + rad + 2 / self.scale local y = cy - rad
local y = h/2 - rad love.graphics.print("Depth: "..self.depth.." Step: "..self.step, x, y)
y = y + self.font:getHeight()
local sorted = {} local sorted = {}
for i,v in ipairs(self.parsed) do for i,v in ipairs(self.parsed) do
@ -303,49 +304,14 @@ function piefiller:draw(args)
y = y + self.font:getHeight() y = y + self.font:getHeight()
end end
elseif mode == "original" then else
local font = love.graphics.getFont() -- REFACTOR
lastangle = 0
for i,v in ipairs(self.parsed) do
local color = v.color
local cx,cy = w/2,h/2
local angle = math.rad(3.6*v.prc)
local x = cx + rad * math.cos(lastangle + angle/2)
local y = cy + rad * math.sin(lastangle + angle/2)
local txt = self:getText(v)
local fw = font:getWidth(txt)
local sx = 1
if cx < x then
sx = -1
fw = 0
end
if cy + rad/2 < y then
y = y + font:getHeight()
elseif cy + rad/2 > y then
y = y - font:getHeight()
end
love.graphics.print(txt,((x) + (-(fw+20))*sx),y)
lastangle = lastangle + angle
end
setColor() setColor()
local t = "Depth: "..self.depth.." with step: "..self.step local t = "Loading..."
local fw = self.font:getWidth(t)
local fh = self.font:getHeight() local fh = self.font:getHeight()
love.graphics.print(t,w/2 - fw/2,(fh+5)) -- TODO re-position this
if loading then
t = "Loading..."
fw = self.font:getWidth(t) fw = self.font:getWidth(t)
love.graphics.print("Loading...", w/2 - fw/2, h/2) love.graphics.print("Loading...", w/2 - fw/2, h/2)
end -- END
else
error("Invalid draw mode. Should be 'list' or 'original'.")
end
else
loading = true
end end
-- our timing is handled in draw... why? My guess is because we aren't called in update -- our timing is handled in draw... why? My guess is because we aren't called in update