From c770c88f981ec37a0db43ef8f6427d60c019b52f Mon Sep 17 00:00:00 2001 From: 1029chris <1029chris@gmail.com> Date: Fri, 10 Jun 2016 12:45:11 -0700 Subject: Finished video player --- main.lua | 2 ++ var.lua | 7 +++++++ viewer.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- window.lua | 10 +++++----- 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/main.lua b/main.lua index 7c44244..dad4fa1 100644 --- a/main.lua +++ b/main.lua @@ -94,7 +94,9 @@ function love.mousereleased(x, y, button) end file.p = false mplay.drag = false + vplay.drag = false mplay.pr = false + vplay.pr = false end function love.draw() if scene == 1 then diff --git a/var.lua b/var.lua index 6e69fea..5848ac5 100644 --- a/var.lua +++ b/var.lua @@ -266,6 +266,13 @@ function loadVar() vplay = {} vplay.v = 0 vplay.p = false + vplay.pr = false + vplay.volx = 232+150 + vplay.volpx = mplay.volx + vplay.volxmax = 10+38+38+38+150+108 + vplay.volxmin = 10+38+38+38+150 + vplay.voly = win[8].h-39 + vplay.drag = false end function loadPre() love.graphics.setDefaultFilter("nearest", "nearest") diff --git a/viewer.lua b/viewer.lua index 943bd5a..1a0221a 100644 --- a/viewer.lua +++ b/viewer.lua @@ -8,16 +8,18 @@ function drawVideo() drawDownBox(8, 31, win[8].w-16, win[8].h-82, 4) love.graphics.setColor(20,20,20) love.graphics.rectangle("fill",8,31,win[8].w-16,win[8].h-82) - drawControls(8+38,win[8].h-34-8) + drawControls(8+38,win[8].h-34-8,8) if vplay.v ~= 0 then love.graphics.draw(vplay.v,8,31) end + drawDownBox(10+38+38+38+150,win[8].h-34+5,118,5,2) + drawUpBox(vplay.volx,vplay.voly,10,25,2) end function drawMusic() drawDownBox(8,31,win[9].w-17,win[9].h-82,4) love.graphics.setColor(20,20,20) love.graphics.rectangle("fill",8,31,win[9].w-17,win[9].h-82) - drawControls(8+38,win[9].h-34-8) + drawControls(8+38,win[9].h-34-8,9) drawDownBox(10+38+38+38,win[9].h-34+5,118,5,2) drawUpBox(mplay.volx,mplay.voly,10,25,2) love.graphics.setColor(0,256,0) @@ -43,10 +45,16 @@ function drawMusic() end love.graphics.setFont(pressstart) end -function drawControls(x,y) +function drawControls(x,y,id) love.graphics.setColor(256,256,256) drawUpBox(x,y,32,32,2) - love.graphics.draw(but.but, x, y) + if id == 9 then + love.graphics.draw(but.but,x,y) + elseif id == 8 and vplay.p == true then + love.graphics.draw(but.pause,x,y) + elseif id == 8 and vplay.p == false then + love.graphics.draw(but.play,x,y) + end drawUpBox(x+38,y,32,32,2) love.graphics.draw(but.stop, x+38, y) drawUpBox(x-38,y,32,32,2) @@ -58,9 +66,54 @@ function updateVideo() win[8].update = true end if win[8].ex == true and vplay.v ~= 0 then - vplay.v:stop() + vplay.v:seek(0) + vplay.v:pause() vplay.v = 0 end + if mouseClick(win[8].x+8+38,win[8].y+win[8].h-34-8,32,32) == true and vplay.v ~= 0 and vplay.pr == false then + if vplay.p == true then + vplay.v:pause() + vplay.p = false + win[8].update = true + elseif vplay.p == false then + vplay.p = true + win[8].update = true + vplay.v:play() + end + vplay.pr = true + elseif mouseClick(win[8].x+8+38-38,win[8].y+win[8].h-34-8,32,32) == true and vplay.v ~= 0 and vplay.pr == false then + vplay.v:rewind() + vplay.p = true + win[8].update = true + vplay.pr = true + elseif mouseClick(win[8].x+8+38+38,win[8].y+win[8].h-34-8,32,32) == true and vplay.m ~= 0 and vplay.pr == false then + vplay.v:seek(0) + vplay.v:pause() + vplay.p = false + win[8].update = true + vplay.pr = true + end + if mouseClick(win[8].x+vplay.volx,win[8].y+vplay.voly,10,25) == true and layer[1] == 8 then + vplay.drag = true + end + if vplay.v ~= 0 then + local d = vplay.volx - vplay.volxmin + local v = 0.00806451612903226 * d + vplay.v:getSource():setVolume(v) + end + if vplay.drag == true then + if vplay.volpx + (sys.mouse.x - sys.mouse.p.x) <= vplay.volxmax + and vplay.volpx + (sys.mouse.x - sys.mouse.p.x) >= vplay.volxmin then + vplay.volx = vplay.volpx + (sys.mouse.x - sys.mouse.p.x) + elseif vplay.volpx + (sys.mouse.x - sys.mouse.p.x) > vplay.volxmax then + vplay.volx = vplay.volxmax + elseif mplay.volpx + (sys.mouse.x - sys.mouse.p.x) < vplay.volxmin then + vplay.volx = vplay.volxmin + end + win[8].update = true + else + vplay.volpx = vplay.volx + end end function updateMusic() if mouseClick(win[9].x+8+38,win[9].y+win[9].h-34-8,32,32) == true and mplay.m ~= 0 and mplay.pr == false then diff --git a/window.lua b/window.lua index 268762e..150ee0c 100644 --- a/window.lua +++ b/window.lua @@ -121,14 +121,14 @@ function drawWindow(id) win[id].ex = true end if win[id].ex == true and win[id].s ~= 0 then - win[id].s = win[id].s - 0.2 + win[id].s = win[id].s - 0.2*sys.s elseif win[id].ex == false and win[id].s ~= 0 then - win[id].s = win[id].s + 0.2 + win[id].s = win[id].s + 0.2*sys.s end - if win[id].s <= 0 then - win[id].s = 0 - elseif win[id].s >= 1 then + if win[id].s > 1 then win[id].s = 1 + elseif win[id].s < 0 then + win[id].s = 0 end if (win[id].min == false and sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+win[id].w-40 and sys.mouse.p.x <= (win[id].x+win[id].w-40)+16 and sys.mouse.drag == false and sys.mouse.p.y >= win[id].y+5 -- cgit