Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadin committed Feb 17, 2023
2 parents cc3ed2f + a10082d commit f8850b4
Showing 1 changed file with 85 additions and 63 deletions.
148 changes: 85 additions & 63 deletions modules/Panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function Panels.Panel.new(data)
panel.frame = createFrameFromPartialFrame(panel.frame)
panel.buttonsPressed = {}
panel.canvas = gfx.image.new(panel.frame.width, panel.frame.height, gfx.kColorBlack)
-- panel.canvas = gfx.image.new(ScreenWidth, ScreenHeight, gfx.kColorBlack)

if not panel.backgroundColor then panel.backgroundColor = Panels.Color.WHITE end

Expand Down Expand Up @@ -438,13 +439,14 @@ function Panels.Panel.new(data)
end
end

local globalX = xPos + offset.x + self.frame.x
local globalY = yPos + offset.y + self.frame.y

if img then
if layer.visible then
local globalX = xPos + offset.x + self.frame.x
local globalY = yPos + offset.y + self.frame.y


if globalX + img.width > 0 and globalX < ScreenWidth and globalY + img.height > 0 and globalY < ScreenHeight then

if layer.alpha and layer.alpha < 1 then
img:drawFaded(xPos, yPos, layer.alpha, playdate.graphics.image.kDitherTypeBayer8x8)
else
Expand All @@ -469,8 +471,10 @@ function Panels.Panel.new(data)

elseif layer.text then
if layer.visible then
if layer.alpha == nil or layer.alpha > 0.5 then
self:drawTextLayer(layer, xPos, yPos, cntrlPct)
if globalX + ScreenWidth > 0 and globalX < ScreenWidth and globalY + ScreenHeight > 0 and globalY < ScreenHeight then
if layer.alpha == nil or layer.alpha > 0.5 then
self:drawTextLayer(layer, xPos, yPos, cntrlPct)
end
end
end
elseif layer.animationLoop then
Expand Down Expand Up @@ -500,8 +504,6 @@ function Panels.Panel.new(data)
end

function panel:reset()
if self.name then print(self.name) end

if self.resetFunction then
self:resetFunction()
end
Expand Down Expand Up @@ -534,6 +536,11 @@ function Panels.Panel.new(data)
if layer.textAnimator then
layer.textAnimator = nil
end
if layer.cachedTextImg then
if(self.prevPct < 0.5) then
layer.cachedTextImg = nil
end
end
if layer.images then
layer.currentImage = 1
end
Expand All @@ -559,74 +566,89 @@ function Panels.Panel.new(data)
end
end


local textMarginLeft<const> = 4
local textMarginTop<const> = 1
function panel:drawTextLayer(layer, xPos, yPos, cntrlPct)
gfx.pushContext()

if layer.fontFamily then
gfx.setFontFamily(Panels.Font.getFamily(layer.fontFamily))
elseif self.fontFamily then
gfx.setFontFamily(Panels.Font.getFamily(self.fontFamily))
end

if layer.font then
gfx.setFont(Panels.Font.get(layer.font))
elseif self.font then
gfx.setFont(Panels.Font.get(self.font))
end

local txt = layer.text
if layer.effect then
if layer.effect.type == Panels.Effect.TYPE_ON then

if layer.textAnimator == nil then
if self.prevPct == 1 then
-- don't replay text animation (and sound) when backing into a frame
txt = layer.text
layer.textAnimator = gfx.animator.new(1, string.len(layer.text), string.len(layer.text))
elseif layer.effect.scrollTrigger == nil or cntrlPct >= layer.effect.scrollTrigger then
layer.isTyping = true
layer.textAnimator = gfx.animator.new(layer.effect.duration or 500, 0, string.len(layer.text),
playdate.easingFunctions.linear, layer.effect.delay or 0)
playdate.timer.performAfterDelay(layer.effect.delay or 0, startLayerTypingSound, layer)
else
txt = ""
if(layer.cachedTextImg == nil) then
layer.cachedTextImg = gfx.image.new(ScreenWidth, ScreenHeight)
layer.needsRedraw = true
end


if(layer.isTyping or layer.needsRedraw) then
gfx.pushContext(layer.cachedTextImg)
gfx.clear(gfx.kColorClear)

if layer.fontFamily then
gfx.setFontFamily(Panels.Font.getFamily(layer.fontFamily))
elseif self.fontFamily then
gfx.setFontFamily(Panels.Font.getFamily(self.fontFamily))
end

if layer.font then
gfx.setFont(Panels.Font.get(layer.font))
elseif self.font then
gfx.setFont(Panels.Font.get(self.font))
end

local txt = layer.text
if layer.effect then
if layer.effect.type == Panels.Effect.TYPE_ON then

if layer.textAnimator == nil then
if self.prevPct == 1 then
-- don't replay text animation (and sound) when backing into a frame
txt = layer.text
layer.needsRedraw = false
layer.textAnimator = gfx.animator.new(1, string.len(layer.text), string.len(layer.text))
elseif layer.effect.scrollTrigger == nil or cntrlPct >= layer.effect.scrollTrigger then
layer.isTyping = true
layer.textAnimator = gfx.animator.new(layer.effect.duration or 500, 0, string.len(layer.text),
playdate.easingFunctions.linear, layer.effect.delay or 0)
playdate.timer.performAfterDelay(layer.effect.delay or 0, startLayerTypingSound, layer)
else
txt = ""
end
end
end

if layer.isTyping then
local j = math.ceil(layer.textAnimator:currentValue())
txt = string.sub(layer.text, 1, j)
if layer.isTyping then
local j = math.ceil(layer.textAnimator:currentValue())
txt = string.sub(layer.text, 1, j)

if txt == layer.text then
layer.isTyping = false
Panels.Audio.stopTypingSound()
if txt == layer.text then
layer.isTyping = false
layer.needsRedraw = false
Panels.Audio.stopTypingSound()
end
end
end
end
end

if layer.background then
local w, h = gfx.getTextSize(txt)
gfx.setColor(layer.background)
if layer.background == Panels.Color.BLACK then
if layer.background then
local w, h = gfx.getTextSize(txt)
gfx.setColor(layer.background)
if layer.background == Panels.Color.BLACK then
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
end
if w > 0 and h > 0 then
gfx.fillRect(0, 0, w + 8, h + 2)
end
end
if layer.color == Panels.Color.WHITE then
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
end
if w > 0 and h > 0 then
gfx.fillRect(xPos - 4, yPos - 1, w + 8, h + 2)

if layer.rect then
gfx.drawTextInRect(txt, textMarginLeft, textMarginTop, layer.rect.width, layer.rect.height, layer.lineHeightAdjustment or 0, "...",
layer.alignment or Panels.TextAlignment.LEFT)
else
gfx.drawText(txt, textMarginLeft, textMarginTop)
end
end
if layer.color == Panels.Color.WHITE then
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
end

if layer.rect then
gfx.drawTextInRect(txt, xPos, yPos, layer.rect.width, layer.rect.height, layer.lineHeightAdjustment or 0, "...",
layer.alignment or Panels.TextAlignment.LEFT)
else
gfx.drawText(txt, xPos, yPos)
gfx.popContext()
end

gfx.popContext()
layer.cachedTextImg:draw(xPos - textMarginLeft, yPos - textMarginTop)
end

function panel:drawBorder(color, bgColor)
Expand Down

0 comments on commit f8850b4

Please sign in to comment.