Skip to content

Commit fa667f3

Browse files
committed
Saving as frames fully functional
Moved grabbing pixmap for saving into separate function Some extra foolproofing when saving
1 parent 0168faa commit fa667f3

File tree

3 files changed

+105
-18
lines changed

3 files changed

+105
-18
lines changed

bender.bmx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Include "types/bitmap-index.bmx"
2525
Global appVersion:String = "1.2.2"
2626
Global appVersionDate:String = "14 Feb 2020"
2727

28+
AppTitle = "CCCP Bender v"+appVersion
29+
2830
Rem
2931
------- BOOT ----------------------------------------------------------------------------------------------------------
3032
EndRem
@@ -40,7 +42,7 @@ Rem
4042
------- EVENT HANDLING ------------------------------------------------------------------------------------------------
4143
EndRem
4244

43-
While True
45+
While True
4446
TAppOutput.FOutputUpdate()
4547

4648
If ButtonState(TAppGUI.editSettingsIndexedCheckbox) = True Then
@@ -50,6 +52,12 @@ While True
5052
fileFilters = "Image Files:png"
5153
TAppFileIO.saveAsIndexed = False
5254
EndIf
55+
56+
If ButtonState(TAppGUI.editSettingsSaveAsFramesCheckbox) = True Then
57+
TAppFileIO.saveAsFrames = True
58+
Else
59+
TAppFileIO.saveAsFrames = False
60+
EndIf
5361

5462
'Debug stuff
5563
'Print "current event: " + CurrentEvent.ToString()
@@ -69,7 +77,6 @@ While True
6977
Case EVENT_MENUACTION
7078
Select EventData()
7179
Case TAppGUI.ABOUT_MENU
72-
AppTitle = "CCCP Bender v"+appversion
7380
Notify(LoadText("Incbin::assets/about-textbox-content"),False)
7481
EndSelect
7582
Case EVENT_GADGETACTION
@@ -83,8 +90,12 @@ While True
8390
TAppOutput.FOutputUpdate()
8491
'Saving
8592
Case TAppGUI.editSaveButton
86-
TAppFileIO.prepForSave = True
87-
TAppOutput.FOutputUpdate()
93+
If TAppOutput.sourceImage <> Null Then
94+
TAppFileIO.prepForSave = True
95+
TAppOutput.FOutputUpdate()
96+
Else
97+
Notify("Nothing to save!",False)
98+
EndIf
8899
'Settings textbox inputs
89100
'Scale
90101
Case TAppGUI.editSettingsZoomTextbox

types/editor-output.bmx

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,11 @@ Type TAppOutput
163163
b = 7 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/INPUTZOOM,ImageHeight(boneImage[b])/INPUTZOOM)
164164
Next
165165
SetRotation(0)
166+
FGrabOutputForSaving()
166167
Else
167168
SetColor(255,230,80)
168-
DrawText("NO IMAGE LOADED!",(GraphicsWidth()/2)-(TextWidth("NO IMAGE LOADED!")/2),GraphicsHeight()/2)
169-
EndIf
170-
'Output copy for saving
171-
If TAppFileIO.saveAsIndexed = True Then
172-
'If saving indexed grab a smaller pixmap to speed up indexing
173-
TAppFileIO.tempOutputImage = GrabPixmap(55,120,34*FRAMES,210)
174-
Else
175-
TAppFileIO.tempOutputImage = GrabPixmap(0,96,768,384)
176-
EndIf
177-
Flip(1)
178-
If TAppFileIO.prepForSave
179-
TAppFileIO.FPrepForSave()
169+
DrawText("NO IMAGE LOADED!",(GraphicsWidth()/2)-(TextWidth("NO IMAGE LOADED!")/2),GraphicsHeight()/2)
170+
Flip(1)
180171
EndIf
181172
EndFunction
182173

@@ -206,4 +197,41 @@ Type TAppOutput
206197
FLimbBend()
207198
FOutputUpdate()
208199
EndFunction
200+
201+
'Output copy for saving
202+
Function FGrabOutputForSaving()
203+
If TAppFileIO.saveAsFrames = True Then
204+
Local row:Int, frame:Int
205+
Local tile:TImage = LoadImage("Incbin::assets/tile")
206+
For row = 0 To 3
207+
For frame = 0 To FRAMES-1
208+
'Draw a tile outline around all frames to see we are within bounds.
209+
DrawImage(tile,62+(frame*(TILESIZE/INPUTZOOM+8)),138+(row*48)) 'Doing this with an image because cba doing the math with DrawLine. Offsets are -1px because tile image is 26x26 for outline and tile is 24x24.
210+
'Draw names of rows
211+
SetColor(255,230,80)
212+
DrawText("Arm FG",8,145)
213+
DrawText("Arm BG",8,145+48)
214+
DrawText("Leg FG",8,145+(48*2))
215+
DrawText("Leg BG",8,145+(48*3))
216+
'Grab pixmap inside tile bounds for saving
217+
TAppFileIO.tempOutputFrame[row,frame] = GrabPixmap(63+(frame*(TILESIZE/INPUTZOOM+8)),139+(row*48),TILESIZE/INPUTZOOM,TILESIZE/INPUTZOOM)
218+
'HFlip the legs so they're facing right
219+
If row >= 2 Then
220+
TAppFileIO.tempOutputFrame[row,frame] = XFlipPixmap(TAppFileIO.tempOutputFrame[row,frame])
221+
EndIf
222+
Next
223+
Next
224+
Else
225+
If TAppFileIO.saveAsIndexed = True Then
226+
'If saving indexed grab a smaller pixmap to speed up indexing
227+
TAppFileIO.tempOutputImage = GrabPixmap(55,120,34*FRAMES,210)
228+
Else
229+
TAppFileIO.tempOutputImage = GrabPixmap(0,96,768,384)
230+
EndIf
231+
EndIf
232+
Flip(1)
233+
If TAppFileIO.prepForSave
234+
TAppFileIO.FPrepForSave()
235+
EndIf
236+
EndFunction
209237
EndType

types/file-io.bmx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ Type TAppFileIO
1515

1616
'Save Bools
1717
Global saveAsIndexed:Int = False
18+
Global saveAsFrames:Int = False
1819
Global prepForSave:Int = False
1920
Global rdyForSave:Int = False
2021
Global runOnce:Int = False
2122

2223
'Output copy for saving
2324
Global tempOutputImage:TPixmap
25+
Global tempOutputFrame:TPixmap[4,20] 'noice
2426

2527
'Load Source Image
2628
Function FLoadFile()
@@ -48,7 +50,11 @@ Type TAppFileIO
4850
runOnce = True
4951
TAppOutput.FOutputUpdate()
5052
Else
51-
FSaveFile()
53+
If Not saveAsFrames Then
54+
FSaveFile()
55+
Else
56+
FSaveFileAsFrames()
57+
EndIf
5258
EndIf
5359
EndIf
5460
EndFunction
@@ -66,7 +72,7 @@ Type TAppFileIO
6672
'Foolproofing
6773
If exportedFile = importedFile Then
6874
Notify("Cannot overwrite source image!",True)
69-
ElseIf exportedFile <> importedFile Then
75+
ElseIf exportedFile <> importedFile And exportedFile <> Null Then
7076
'Writing new file
7177
If saveAsIndexed = True
7278
TBitmapIndex.FPixmapToIndexedBitmap(tempOutputImage,exportedFile)
@@ -79,4 +85,46 @@ Type TAppFileIO
7985
FRevertPrep()
8086
EndIf
8187
EndFunction
88+
89+
'Save Output Content As Frames
90+
Function FSaveFileAsFrames()
91+
exportedFile = RequestFile("Save graphic output","",True) 'No file extensions here, we add them later manually otherwise exported file name is messed up.
92+
'Foolproofing
93+
If exportedFile = importedFile Then
94+
Notify("Cannot overwrite source image!",True)
95+
ElseIf exportedFile <> importedFile And exportedFile <> Null Then
96+
'Writing new file
97+
Local row:Int, frame:Int
98+
For row = 0 To 3
99+
'Name the rows - by default: ArmFG, ArmBG, LegFG, LegBG in this order.
100+
Local rowName:String
101+
If row = 0 Then
102+
rowName = "ArmFG"
103+
ElseIf row = 1 Then
104+
rowName = "ArmBG"
105+
ElseIf row = 2 Then
106+
rowName = "LegFG"
107+
ElseIf row = 3 Then
108+
rowName = "LegBG"
109+
EndIf
110+
For frame = 0 To TAppOutput.FRAMES-1
111+
Local exportedFileTempName:String
112+
If frame < 10 Then
113+
exportedFileTempName = exportedFile+rowName+"00"+frame
114+
Else
115+
exportedFileTempName = exportedFile+rowName+"0"+frame
116+
EndIf
117+
If saveAsIndexed = True
118+
TBitmapIndex.FPixmapToIndexedBitmap(tempOutputFrame[row,frame],exportedFileTempName+".bmp")
119+
Else
120+
SavePixmapPNG(tempOutputFrame[row,frame],exportedFileTempName+".png")
121+
EndIf
122+
Next
123+
Next
124+
FRevertPrep()
125+
Else
126+
'On Cancel
127+
FRevertPrep()
128+
EndIf
129+
EndFunction
82130
EndType

0 commit comments

Comments
 (0)