Skip to content

Commit 98b66d5

Browse files
committed
functora-card wip
1 parent 5f700c2 commit 98b66d5

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

pub/functora/cfg/card.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ head = "./fonts/larabiefont.ttf"
1010
icon = "./fonts/devicons.ttf"
1111
note = "./fonts/rondo.ttf"
1212

13+
[[extra]]
14+
width = 2400
15+
height = 1200
16+
vertical = true
17+
1318
[[group]]
1419
[[group.item]]
1520
kind = "Head"

pub/functora/src/card/Functora/Card.hs

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,38 @@ main = withUtf8 $ do
4444
}
4545
let width = cfg ^. #cfgImg . #imgWidth . #unPx
4646
let height = cfg ^. #cfgImg . #imgHeight . #unPx
47-
CP.writePng
48-
( "./img/card-"
49-
<> inspect width
50-
<> "x"
51-
<> inspect height
52-
<> ".png"
53-
)
54-
img
55-
CP.writePng
56-
( "./img/card-"
57-
<> inspect height
58-
<> "x"
59-
<> inspect width
60-
<> ".png"
61-
)
62-
$ JP.rotateRight90 img
47+
forM_ (Extra (Px width) (Px height) False : cfgExtra cfg) $ \ext -> do
48+
let extWidth = ext ^. #extraWidth . #unPx
49+
let extHeight = ext ^. #extraHeight . #unPx
50+
let fin =
51+
R.renderDrawingAtDpi
52+
extWidth
53+
extHeight
54+
(cfg ^. #cfgImg . #imgDpi . #unPx)
55+
white
56+
. R.drawImage img 0
57+
$ R.V2
58+
(unsafeFrom @Int @Float (extWidth - width) / 2)
59+
(unsafeFrom @Int @Float (extHeight - height) / 2)
60+
if extraVertical ext
61+
then
62+
CP.writePng
63+
( "./img/card-"
64+
<> inspect extHeight
65+
<> "x"
66+
<> inspect extWidth
67+
<> ".png"
68+
)
69+
$ JP.rotateRight90 fin
70+
else
71+
CP.writePng
72+
( "./img/card-"
73+
<> inspect extWidth
74+
<> "x"
75+
<> inspect extHeight
76+
<> ".png"
77+
)
78+
fin
6379

6480
mkFont :: Text -> IO TT.Font
6581
mkFont =
@@ -201,6 +217,7 @@ newtype Px = Px
201217
data Cfg = Cfg
202218
{ cfgImg :: Img,
203219
cfgFont :: CfgFont,
220+
cfgExtra :: [Extra],
204221
cfgGroup :: [Group]
205222
}
206223
deriving stock
@@ -254,6 +271,24 @@ data CfgFont = CfgFont
254271
)
255272
via GenericType CfgFont
256273

274+
data Extra = Extra
275+
{ extraWidth :: Px,
276+
extraHeight :: Px,
277+
extraVertical :: Bool
278+
}
279+
deriving stock
280+
( Eq,
281+
Ord,
282+
Show,
283+
Data,
284+
Generic
285+
)
286+
deriving
287+
( HasCodec,
288+
HasItemCodec
289+
)
290+
via GenericType Extra
291+
257292
newtype Group = Group
258293
{ groupItem :: [Item]
259294
}

0 commit comments

Comments
 (0)