From 736cdcd3c05df3788c49010a6f1a1feb1105ca7d Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Fri, 24 Nov 2023 11:15:06 -0800 Subject: [PATCH 1/6] reduce panel canvas size --- Panels.lua | 6 +++++- modules/Panel.lua | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Panels.lua b/Panels.lua index 8a1dd56..a380984 100644 --- a/Panels.lua +++ b/Panels.lua @@ -820,7 +820,9 @@ local function drawComic(offset) for i, panel in ipairs(panels) do if (panel:isOnScreen(offset)) then panel:render(offset, sequence.foregroundColor, sequence.backgroundColor) - panel.canvas:draw(panel.frame.x + offset.x, panel.frame.y + offset.y) + -- panel.canvas:draw(panel.frame.x + offset.x, panel.frame.y + offset.y) + -- panel.canvas:draw(panel.frame.x, panel.frame.y) + panel.canvas:draw(0, 0) elseif panel.wasOnScreen then if panel.targetSequenceFunction then @@ -831,6 +833,8 @@ local function drawComic(offset) panel.wasOnScreen = false end end + + playdate.drawFPS(0,0) end diff --git a/modules/Panel.lua b/modules/Panel.lua index 97e78bb..4c94132 100644 --- a/modules/Panel.lua +++ b/modules/Panel.lua @@ -98,8 +98,7 @@ function Panels.Panel.new(data) panel.prevPct = 0 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) + panel.canvas = gfx.image.new( ScreenWidth, ScreenHeight, gfx.kColorClear) if not panel.backgroundColor then panel.backgroundColor = Panels.Color.WHITE end @@ -728,12 +727,19 @@ function Panels.Panel.new(data) self.advanceButton:draw() end end + + function panel:render(offset, borderColor, bgColor) + local frame = self.frame self.wasOnScreen = true gfx.pushContext(self.canvas) - gfx.clear(self.backgroundColor) + gfx.clear(gfx.kColorClear) + gfx.setDrawOffset(offset.x + frame.x, offset.y + frame.y) + gfx.setClipRect(0, 0, frame.width, frame.height) + gfx.clear(self.backgroundColor) + if self.updateFunction then self:updateFunction(offset) end @@ -750,7 +756,7 @@ function Panels.Panel.new(data) end self.borderImage:draw(0, 0) end - + if self.advanceButton then self:updateAdvanceButton() end From baed95617ca1a2779045db747bdcc247f14a7e2d Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Fri, 24 Nov 2023 11:50:28 -0800 Subject: [PATCH 2/6] try cliping in main render function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (it’s not any faster) --- Panels.lua | 8 ++++++-- modules/Panel.lua | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Panels.lua b/Panels.lua index a380984..224dc85 100644 --- a/Panels.lua +++ b/Panels.lua @@ -820,8 +820,10 @@ local function drawComic(offset) for i, panel in ipairs(panels) do if (panel:isOnScreen(offset)) then panel:render(offset, sequence.foregroundColor, sequence.backgroundColor) - -- panel.canvas:draw(panel.frame.x + offset.x, panel.frame.y + offset.y) - -- panel.canvas:draw(panel.frame.x, panel.frame.y) + -- I tried setting clipRect here instead of inside the Panel, but it's not any faster + -- leaving it inside Panel for simplicity + -- local rect = panel:getClipRect(offset) + -- gfx.setClipRect(rect.x, rect.y, rect.width, rect.height) panel.canvas:draw(0, 0) elseif panel.wasOnScreen then @@ -834,6 +836,8 @@ local function drawComic(offset) end end + -- gfx.clearClipRect() + playdate.drawFPS(0,0) end diff --git a/modules/Panel.lua b/modules/Panel.lua index 4c94132..9ef9970 100644 --- a/modules/Panel.lua +++ b/modules/Panel.lua @@ -728,6 +728,28 @@ function Panels.Panel.new(data) end end + + -- function panel:getClipRect(offset) + -- local frame = self.frame + -- local posX = frame.x + offset.x + -- local posY = frame.y + offset.y + -- + -- local x = math.max(posX, 0) + -- local y = math.max(posY, 0) + -- + -- local width = math.min(frame.width, frame.width + posX) + -- local height = math.min(frame.height, frame.height + posY) + -- + -- if width > ScreenWidth then + -- width = ScreenWidth - x + -- end + -- + -- if height > ScreenHeight then + -- height = ScreenHeight - y + -- end + -- + -- return {x = x, y = y, width = width, height = height} + -- end function panel:render(offset, borderColor, bgColor) From 1eb12527a62a272f78cda8752dc088e192eac79c Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Fri, 24 Nov 2023 12:05:21 -0800 Subject: [PATCH 3/6] fix image mask position --- modules/Panel.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/Panel.lua b/modules/Panel.lua index 9ef9970..5560153 100644 --- a/modules/Panel.lua +++ b/modules/Panel.lua @@ -451,8 +451,10 @@ function Panels.Panel.new(data) img:drawFaded(xPos, yPos, layer.alpha, playdate.graphics.image.kDitherTypeBayer8x8) else if layer.maskImg then - local maskX = math.floor((self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p) - panel.frame.margin - local maskY = math.floor((self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p) - panel.frame.margin + local maskX = math.floor((self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.x + panel.frame.x + local maskY = math.floor((self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.y + panel.frame.y + + print(maskX) local maskImg = gfx.image.new(ScreenWidth, ScreenHeight) gfx.lockFocus(maskImg) From 35e851fd10118c79fae53e804c74a8f0cbe3affe Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Fri, 24 Nov 2023 12:40:33 -0800 Subject: [PATCH 4/6] add pixel lock for dithered layers --- Panels.lua | 13 +------------ modules/Panel.lua | 5 +++++ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Panels.lua b/Panels.lua index 224dc85..0f1b1ef 100644 --- a/Panels.lua +++ b/Panels.lua @@ -1,4 +1,4 @@ --- Panels version 1.6.2 +-- Panels version 1.7beta -- https://cadin.github.io/panels/ import "CoreLibs/object" @@ -808,7 +808,6 @@ end local function drawComic(offset) gfx.clear(sequence.backgroundColor) - if shouldFadeBG then local pct = 1 - (transitionInAnimator:currentValue() - transitionInAnimator.startValue) / @@ -820,12 +819,7 @@ local function drawComic(offset) for i, panel in ipairs(panels) do if (panel:isOnScreen(offset)) then panel:render(offset, sequence.foregroundColor, sequence.backgroundColor) - -- I tried setting clipRect here instead of inside the Panel, but it's not any faster - -- leaving it inside Panel for simplicity - -- local rect = panel:getClipRect(offset) - -- gfx.setClipRect(rect.x, rect.y, rect.width, rect.height) panel.canvas:draw(0, 0) - elseif panel.wasOnScreen then if panel.targetSequenceFunction then targetSequence = panel.targetSequenceFunction() @@ -835,11 +829,6 @@ local function drawComic(offset) panel.wasOnScreen = false end end - - -- gfx.clearClipRect() - - playdate.drawFPS(0,0) - end -- Playdate update loop diff --git a/modules/Panel.lua b/modules/Panel.lua index 5560153..2504b02 100644 --- a/modules/Panel.lua +++ b/modules/Panel.lua @@ -414,6 +414,11 @@ function Panels.Panel.new(data) yPos = yPos + shake.y * (1 - p * p) end + if layer.pixelLock then + xPos = math.floor((xPos + offset.x) / layer.pixelLock) * layer.pixelLock - offset.x + self.frame.margin + yPos = math.floor((yPos + offset.y) / layer.pixelLock) * layer.pixelLock - offset.y + self.frame.margin + end + if layer.effect then doLayerEffect(layer, xPos, yPos) end From 68b671445cb58897d32894ff9b571912b8348bbc Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Sat, 25 Nov 2023 10:41:08 -0800 Subject: [PATCH 5/6] set default font families for menus and comic --- Panels.lua | 14 +++++++++++++- modules/Alert.lua | 15 ++++++++++++++- modules/Font.lua | 4 ++-- modules/Menus.lua | 19 +++++++++++++++++-- modules/Panel.lua | 6 +++--- modules/Settings.lua | 9 +++++++-- 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/Panels.lua b/Panels.lua index 0f1b1ef..6e2fd82 100644 --- a/Panels.lua +++ b/Panels.lua @@ -1,4 +1,4 @@ --- Panels version 1.7beta +-- Panels version 1.7 -- https://cadin.github.io/panels/ import "CoreLibs/object" @@ -807,6 +807,8 @@ end local function drawComic(offset) gfx.clear(sequence.backgroundColor) + -- + -- setDefaultFont() if shouldFadeBG then local pct = 1 - @@ -1030,7 +1032,16 @@ local function createCreditsSequence() table.insert(Panels.comicData, seq) end +function setDefaultFont() + if Panels.Settings.defaultFontFamily then + gfx.setFontFamily(Panels.Font.getFamily(Panels.Settings.defaultFontFamily)) + elseif Panels.Settings.defaultFont then + gfx.setFont(Panels.Font.get(Panels.Settings.defaultFont)) + end +end + function Panels.startCutscene(comicData, callback) + setDefaultFont() isCutscene = true cutsceneFinishCallback = callback Panels.comicData = comicData @@ -1051,6 +1062,7 @@ function Panels.startCutscene(comicData, callback) end function Panels.start(comicData) + setDefaultFont() Panels.comicData = comicData maxScrollVelocity = Panels.Settings.maxScrollSpeed alert = Panels.Alert.new("Start Over?", "All progress will be lost.", { "Cancel", "Start Over" }) diff --git a/modules/Alert.lua b/modules/Alert.lua index ebcb4b4..501c157 100644 --- a/modules/Alert.lua +++ b/modules/Alert.lua @@ -26,6 +26,19 @@ function Panels.Alert.new(title, text, options, callback, selection) local x = (ScreenWidth - width) / 2 local y = (ScreenHeight - height) / 2 - 8 local offset = 0 + + if Panels.Settings.menuFontFamily then + local family = Panels.Font.getFamily(Panels.Settings.menuFontFamily) + titleFont = family + textFont = family + listFont = family + + elseif Panels.Settings.defaultFontFamily then + local family = Panels.Font.getFamily(Panels.Settings.defaultFontFamily) + titleFont = family + textFont = family + listFont = family + end gridView = playdate.ui.gridview.new((width - 32) / 2 - 8, 32) gridView:setNumberOfRows(1) @@ -84,7 +97,7 @@ function Panels.Alert.new(title, text, options, callback, selection) function alert:drawText() gfx.setFont(titleFont) - gfx.drawTextInRect(self.title, x + 16, y + 16, width - 32, 32, nil, "...", kTextAlignment.center) + gfx.drawTextInRect("*".. self.title .. "*", x + 16, y + 16, width - 32, 32, nil, "...", kTextAlignment.center) gfx.setFont(textFont) gfx.drawTextInRect(self.text, x + 16, y + 48, width - 32, height - 128, nil, "...", kTextAlignment.center) end diff --git a/modules/Font.lua b/modules/Font.lua index 01cb494..57e623e 100644 --- a/modules/Font.lua +++ b/modules/Font.lua @@ -40,7 +40,7 @@ function Panels.Font.getFamily(paths) if families[key] == nil then clipExtensions(paths) - cache[key] = playdate.graphics.font.newFamily(paths) + families[key] = playdate.graphics.font.newFamily(paths) end - return cache[key] + return families[key] end diff --git a/modules/Menus.lua b/modules/Menus.lua index 49d6d3a..a8a6b2a 100644 --- a/modules/Menus.lua +++ b/modules/Menus.lua @@ -14,8 +14,6 @@ local hideSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. "asset local showSound = playdate.sound.sampleplayer.new(Panels.Settings.path .. "assets/audio/swish-in.wav") local headerFont = gfx.getSystemFont("bold") --- local listFont = Panels.Font.get(Panels.Settings.path .. "assets/fonts/Asheville-Narrow-14-Bold")--gfx.getSystemFont() - local listFont = gfx.getSystemFont() Panels.Menu = {} @@ -42,6 +40,17 @@ function Panels.Menu.new(height, redrawContent, inputHandlers) menu.onDidShow = nil menu.onDidHide = nil + if Panels.Settings.menuFontFamily then + local family = Panels.Font.getFamily(Panels.Settings.menuFontFamily) + headerFont = family + listFont = family + + elseif Panels.Settings.defaultFontFamily then + local family = Panels.Font.getFamily(Panels.Settings.defaultFontFamily) + headerFont = family + listFont = family + end + local function drawBG(yPos) gfx.setColor(Panels.Color.WHITE) gfx.fillRoundRect(0, yPos, 400, ScreenHeight + 5, 4) @@ -168,6 +177,7 @@ local function updateMainMenu(gameDidFinish, gameDidStart) mainMenuList:setSelection(1, 1, #menuOptions) function mainMenuList:drawCell(section, row, column, selected, x, y, width, height) + gfx.pushContext() local text = menuOptions[column] if selected then gfx.setColor(gfx.kColorBlack) @@ -181,6 +191,7 @@ local function updateMainMenu(gameDidFinish, gameDidStart) gfx.setFont(listFont) gfx.drawTextInRect(text, x, y+8, width, height+2, nil, "...", kTextAlignment.center) + gfx.popContext() end end @@ -397,6 +408,7 @@ local function createChapterMenu(data) end function chapterList:drawCell(section, row, column, selected, x, y, width, height) + gfx.pushContext() if selected then gfx.setColor(gfx.kColorBlack) gfx.fillRoundRect(x, y + chapterOffset, width, height, 4) @@ -408,9 +420,11 @@ function chapterList:drawCell(section, row, column, selected, x, y, width, heigh gfx.setFont(listFont) gfx.drawTextInRect("" .. sections[row].title.. "", x + 16, y+8, width -32, height+2, nil, "...", kTextAlignment.left) + gfx.popContext() end function chapterList:drawSectionHeader(section, x, y, width, height) + gfx.pushContext() if Panels.Settings.chapterMenuHeaderImage then headerImage:drawAnchored(x + width / 2, y + 7, 0.5, 0) else @@ -421,6 +435,7 @@ function chapterList:drawSectionHeader(section, x, y, width, height) gfx.drawLine(x, y + 20, x + 120, y + 20) gfx.drawLine(x + width - 120, y + 20, x + width, y + 20) end + gfx.popContext() end diff --git a/modules/Panel.lua b/modules/Panel.lua index 2504b02..ad35517 100644 --- a/modules/Panel.lua +++ b/modules/Panel.lua @@ -591,13 +591,13 @@ function Panels.Panel.new(data) gfx.setFontFamily(Panels.Font.getFamily(layer.fontFamily)) elseif self.fontFamily then gfx.setFontFamily(Panels.Font.getFamily(self.fontFamily)) - end - - if layer.font then + elseif layer.font then gfx.setFont(Panels.Font.get(layer.font)) elseif self.font then gfx.setFont(Panels.Font.get(self.font)) end + -- elseif Panels.Settings.defaultFontFamily then + -- gfx.setFontFamily(Panels.Font.getFamily()) local txt = layer.text if layer.effect then diff --git a/modules/Settings.lua b/modules/Settings.lua index a52ed37..de466e8 100644 --- a/modules/Settings.lua +++ b/modules/Settings.lua @@ -4,17 +4,22 @@ Panels.Settings = { imageFolder = "images/", audioFolder = "audio/", + -- project settings + defaultFont = nil, + defaultFontFamily = nil, + menuFontFamily = nil, + resetVarsOnGameOver = true, + -- panel settings defaultFrame = {gap = 50, margin = 8}, snapToPanels = true, sequenceTransitionDuration = 750, - defaultFont = nil, borderWidth = 2, borderRadius = 2, typingSound = Panels.Audio.TypingSound.DEFAULT, maxScrollSpeed = 8, - resetVarsOnGameOver = true, + -- menu settings menuImage = "menuImage.png", From 4c9e20ea588d9ccd43b198ecc063d1197ea5d6ae Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Sat, 25 Nov 2023 11:07:19 -0800 Subject: [PATCH 6/6] fix text caching; move updateFunction call --- modules/Panel.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/Panel.lua b/modules/Panel.lua index ad35517..442883b 100644 --- a/modules/Panel.lua +++ b/modules/Panel.lua @@ -459,8 +459,6 @@ function Panels.Panel.new(data) local maskX = math.floor((self.parallaxDistance * pct.x - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.x + panel.frame.x local maskY = math.floor((self.parallaxDistance * pct.y - self.parallaxDistance / 2) * p) - panel.frame.margin + offset.y + panel.frame.y - print(maskX) - local maskImg = gfx.image.new(ScreenWidth, ScreenHeight) gfx.lockFocus(maskImg) layer.maskImg:draw(maskX, maskY) @@ -596,8 +594,6 @@ function Panels.Panel.new(data) elseif self.font then gfx.setFont(Panels.Font.get(self.font)) end - -- elseif Panels.Settings.defaultFontFamily then - -- gfx.setFontFamily(Panels.Font.getFamily()) local txt = layer.text if layer.effect then @@ -656,6 +652,7 @@ function Panels.Panel.new(data) gfx.popContext() end layer.cachedTextImg:draw(xPos - textMarginLeft, yPos - textMarginTop) + layer.needsRedraw = false end function panel:drawBorder(color, bgColor) @@ -765,13 +762,14 @@ function Panels.Panel.new(data) gfx.pushContext(self.canvas) gfx.clear(gfx.kColorClear) - gfx.setDrawOffset(offset.x + frame.x, offset.y + frame.y) - gfx.setClipRect(0, 0, frame.width, frame.height) - gfx.clear(self.backgroundColor) - + if self.updateFunction then self:updateFunction(offset) end + + gfx.setDrawOffset(offset.x + frame.x, offset.y + frame.y) + gfx.setClipRect(0, 0, frame.width, frame.height) + gfx.clear(self.backgroundColor) if self.renderFunction then self:renderFunction(offset)