Skip to content

Commit 287b285

Browse files
author
MaximDude
committed
Fixed bad output when zooming
Zooming fully functional Added preperations for saving Minor refactoring
1 parent 1d2106a commit 287b285

File tree

1 file changed

+87
-66
lines changed

1 file changed

+87
-66
lines changed

cccp-bender-main.bmx

Lines changed: 87 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Type TAppOutput
3434
Global outputWindow:TGraphics
3535
'Draw Bools
3636
Global doDraw:Int = False
37-
Global redoBoneImage:Int = False
37+
Global redoLimbTiles:Int = False
38+
Global prepForSave:Int = False
39+
Global rdyForSave:Int = False
3840
'Constants
3941
Const BONES:Int = 8
4042
Const LIMBS:Int = BONES/2
@@ -68,52 +70,65 @@ Type TAppOutput
6870
Function FCreateLimbTiles()
6971
Local b:Int, i:Int
7072
For b = 0 To BONES-1 'Because I (arne) can't set handles on inidividial anim image frames, I must use my own frame sys
71-
boneImage[b] = CreateImage(TILESIZE,TILESIZE,1,MASKEDIMAGE)
73+
boneImage[b] = CreateImage(TILESIZE,TILESIZE,1,DYNAMICIMAGE|MASKEDIMAGE)
7274
GrabImage(boneImage[b],b*TILESIZE,0)
7375
Next
7476
'Set up default bone sizes
7577
For i = 0 To BONES-1
7678
jointX[i] = TILESIZE/2
77-
jointY[i] = TILESIZE/3.6
78-
boneLength[i] = ((TILESIZE/2-jointY[i])*2)
79-
SetImageHandle(boneImage[i],jointX[i],jointY[i])
79+
jointY[i] = TILESIZE/3.3 '3.6
80+
boneLength[i] = (TILESIZE/2-jointY[i])*2
81+
SetImageHandle(boneImage[i],jointX[i]/ZOOM,jointY[i]/ZOOM)
8082
Next
8183
EndFunction
8284

8385
'Create output window and draw assets
8486
Function FOutputBoot()
8587
'SetGraphicsDriver GLGraphicsDriver()
86-
outputWindow = Graphics(640,480,0,0,0)
88+
outputWindow = Graphics(768,480,0,0,0)
8789
'Window background color
8890
SetClsColor(BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE)
8991
SetMaskColor(255,0,255)
9092
DrawImage(logoImage,0,480-ImageHeight(logoImage))
9193
DrawImageRect(sourceImage,0,0,ImageWidth(sourceImage)*ZOOM,ImageHeight(sourceImage)*ZOOM)
9294
FCreateLimbTiles()
9395
FLimbBend()
94-
'Flip(1)
9596
doDraw = True
9697
EndFunction
97-
98-
'Sprite rotation
98+
99+
'Set Joint Marker
100+
Function FSetJointMarker()
101+
Local xm:Int = MouseX()
102+
Local ym:Int = MouseY()
103+
If ym < (TILESIZE/2-2) And ym > 0 And xm > 0 And xm < TILESIZE*BONES Then
104+
Local b:Int = xm/TILESIZE
105+
jointX[b] = TILESIZE/2 'X is always at center, so kinda pointless to even bother - at the moment
106+
jointY[b] = ym 'Determines length
107+
boneLength[b] = (TILESIZE/2 -ym)*2
108+
SetImageHandle(boneImage[b],jointX[b]/ZOOM,jointY[b]/ZOOM) 'Rotation handle.
109+
EndIf
110+
EndFunction
111+
112+
'Rotation Calc
99113
Function FLawOfCosines(ab:Float,bc:Float,ca:Float)
100114
angA = ACos((ca^2+ab^2-bc^2)/(2*ca*ab))
101115
angB = ACos((bc^2+ab^2-ca^2)/(2*bc*ab))
102116
angC = (180-(angA+angB))
103117
EndFunction
104118

119+
'Bending
105120
Function FLimbBend()
106-
Local maxExtend:Float = 0.99 'Possibly make definable in settings (slider)
107-
Local minExtend:Float = 0.30 'Possibly make definable in settings (slider)
121+
Local maxExtend:Float = 0.99 'Possibly make definable in settings (slider) -- maybe not, because large number of frames can be rendered and you can just take the ones you need
122+
Local minExtend:Float = 0.30 'Possibly make definable in settings (slider) -- maybe not, because large number of frames can be rendered and you can just take the ones you need
108123
Local stepSize:Float = (maxExtend-minExtend)/(FRAMES-1) ' -1 to make inclusive of last value (full range)
109124
Local b:Int, f:Int, l:Float, x:Float, y:Float, airLength:Float, upperLength:Float, lowerLength:Float
110125
For l = 0 To LIMBS-1
111126
For f = 0 To FRAMES-1
112127
b = l*2
113-
x = f * TILESIZE + 96
114-
y = l * TILESIZE * 1.5 + 200
115-
upperLength = boneLength[b] 'e.g. upper leg
116-
lowerLength = boneLength[b+1] 'e.g. lower leg
128+
x = (f * 32) + 80 'Drawing position X
129+
y = ((l * 32) * 1.5 ) + 144 'Drawing position Y
130+
upperLength = boneLength[b]/ZOOM 'e.g. upper leg
131+
lowerLength = boneLength[b+1]/ZOOM 'e.g. lower leg
117132
airLength = (stepSize * f + minExtend) * (upperLength + lowerLength) 'Sum of the two bones * step scaler for frame (hip-ankle)
118133
FLawOfCosines(airLength,upperLength,lowerLength)
119134
angle[b,f] = angB
@@ -127,20 +142,7 @@ Type TAppOutput
127142
Next
128143
Next
129144
EndFunction
130-
131-
'Set Joint Marker
132-
Function FSetJointMarker()
133-
Local xm:Int = MouseX()
134-
Local ym:Int = MouseY()
135-
If ym < (TILESIZE/2-2) And ym > 0 And xm > 0 And xm < TILESIZE*BONES Then
136-
Local b:Int = xm/TILESIZE
137-
jointX[b] = TILESIZE/2 'X is always at center, so kinda pointless to even bother - at the moment
138-
jointY[b] = ym 'Determines length
139-
boneLength[b] = (TILESIZE/2 -ym)*2
140-
SetImageHandle(boneImage[b],jointX[b],jointY[b]) 'Rotation handle.
141-
EndIf
142-
EndFunction
143-
145+
144146
'Create Joint Markers
145147
Function FCreateJointMarker(x:Float,y:Float)
146148
SetRotation(0)
@@ -163,12 +165,16 @@ Type TAppOutput
163165
EndIf
164166
If doDraw
165167
Cls
166-
SetClsColor(BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE)
168+
If Not prepForSave
169+
SetClsColor(BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE)
170+
ElseIf prepForSave
171+
SetClsColor(255,0,255)
172+
EndIf
167173
SetColor(255,255,255)
168174
DrawImageRect(sourceImage,0,0,ImageWidth(sourceImage)*ZOOM,ImageHeight(sourceImage)*ZOOM)
169-
If redoBoneImage Then
175+
If redoLimbTiles Then
170176
FCreateLimbTiles()
171-
redoBoneImage = False
177+
redoLimbTiles = False
172178
EndIf
173179
FLimbBend()
174180
'Footer image and text
@@ -186,20 +192,22 @@ Type TAppOutput
186192
Local f:Int, b:Int
187193
For f = 0 To FRAMES-1
188194
'These might be in a specific draw-order for joint overlapping purposes
189-
b = 0 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f]) 'DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
190-
b = 1 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
191-
b = 2 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
192-
b = 3 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
193-
b = 4 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
194-
b = 5 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
195-
b = 6 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
196-
b = 7 SetRotation(angle[b,f]) DrawImage(boneImage[b],xBone[b,f],yBone[b,f])
195+
b = 0 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
196+
b = 1 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
197+
b = 2 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
198+
b = 3 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
199+
b = 4 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
200+
b = 5 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
201+
b = 6 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
202+
b = 7 SetRotation(angle[b,f]) DrawImageRect(boneImage[b],xBone[b,f],yBone[b,f],ImageWidth(boneImage[b])/ZOOM,ImageHeight(boneImage[b])/ZOOM)
197203
Next
198204
SetRotation(0)
199-
Flip(1)
200-
doDraw = False
201-
'Else
202-
'Delay(20)
205+
Flip(0)
206+
If Not prepForSave
207+
doDraw = False
208+
ElseIf prepForSave
209+
rdyForSave = True
210+
EndIf
203211
EndIf
204212
EndFunction
205213
EndType
@@ -242,7 +250,7 @@ Type TAppGUI
242250
'Workspace Window Instructions
243251
Global editHelpPanel:TGadget
244252
Global editHelpTextbox:TGadget
245-
253+
'Textboxes content
246254
Global aboutTextboxContent:String[8]
247255
Global helpTextboxContent:String[]
248256

@@ -269,7 +277,7 @@ Type TAppGUI
269277

270278
'Create Editor Window
271279
Function FAppEditor()
272-
editWindow = CreateWindow("CCCP Bender v"+appversion+" - Editor",DesktopWidth()/2-640,DesktopHeight()/2-240,300,430,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
280+
editWindow = CreateWindow("CCCP Bender v"+appversion+" - Editor",DesktopWidth()/2-700,DesktopHeight()/2-240,300,430,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
273281
editWindowButtonPanel = CreatePanel(10,7,280,57,editWindow,PANEL_GROUP)
274282
editLoadButton = CreateButton("Load",6,0,80,30,editWindowButtonPanel,BUTTON_PUSH)
275283
editSaveButton = CreateButton("Save",96,0,80,30,editWindowButtonPanel,BUTTON_PUSH)
@@ -293,35 +301,38 @@ Type TAppGUI
293301
SetGadgetText(editSettingsColorRTextbox,TAppOutput.BACKGROUND_RED)
294302
SetGadgetText(editSettingsColorGTextbox,TAppOutput.BACKGROUND_GREEN)
295303
SetGadgetText(editSettingsColorBTextbox,TAppOutput.BACKGROUND_BLUE)
304+
'Instructions textbox content
296305
SetGadgetText(TAppGUI.editHelpTextbox,"TBA");
297306
'Delete no longer used MainWindow
298307
FreeGadget(mainWindow)
299308
EndFunction
309+
310+
'Transition between windows
311+
Function FAppUpdate()
312+
If Not mainToEdit And importedFile <> Null Then
313+
FAppEditor()
314+
TAppOutput.FOutputBoot()
315+
mainToEdit = True
316+
EndIf
317+
EndFunction
300318
EndType
301319

302-
'Transition between windows
303-
Function FAppUpdate()
304-
If Not TAppGUI.mainToEdit And importedFile <> Null Then
305-
TAppGUI.FAppEditor()
306-
TAppOutput.FOutputBoot()
307-
TAppGUI.mainToEdit = True
308-
EndIf
309-
EndFunction
310-
311320
'Everything set up, run app
312321
New TAppGUI
313322
New TAppOutput
314323
TAppGUI.FAppMain()
315324

316325
While True
317326
If Not TAppGUI.mainToEdit Then
318-
FAppUpdate()
327+
TAppGUI.FAppUpdate()
319328
Else
320329
TAppOutput.FOutputUpdate()
321330
EndIf
322331

323332
WaitEvent
324-
Print CurrentEvent.ToString()
333+
'Print CurrentEvent.ToString()
334+
'Print "prep "+TAppOutput.prepForSave
335+
'Print "rdy "+TAppOutput.rdyForSave
325336

326337
'Event Responses
327338
'In Main Window
@@ -342,7 +353,7 @@ While True
342353
EndSelect
343354
EndSelect
344355
'In Editor Window
345-
ElseIf TAppGUI.mainToEdit Then
356+
ElseIf TAppGUI.mainToEdit Then
346357
Select EventID()
347358
Case EVENT_APPRESUME
348359
ActivateWindow(TAppGUI.editWindow)
@@ -365,17 +376,27 @@ While True
365376
TAppOutput.sourceImage = TAppOutput.sourceImage
366377
Else
367378
TAppOutput.sourceImage = LoadImage(importedFile,0)
368-
TAppOutput.redoBoneImage = True
379+
TAppOutput.redoLimbTiles = True
369380
TAppOutput.doDraw = True
370381
EndIf
371382
'Saving
372383
Case TAppGUI.editSaveButton
373-
exportedFile = RequestFile("Save graphic file",fileFilers,True)
374-
'Foolproofing
375-
If exportedFile <> Null Then
376-
'Writing new file
377-
Local tempOutputImage:TPixmap = GrabPixmap(0,0,640,480)
378-
SavePixmapPNG(tempOutputImage,exportedFile)
384+
'Prepare for saving
385+
TAppOutput.prepForSave = True
386+
TAppOutput.doDraw = True
387+
If TAppOutput.rdyForSave = True Then
388+
TAppOutput.doDraw = True
389+
Delay(100)
390+
exportedFile = RequestFile("Save graphic file",fileFilers,True)
391+
'Foolproofing
392+
If exportedFile <> Null Then
393+
'Writing new file
394+
Local tempOutputImage:TPixmap = GrabPixmap(0,0,768,480)
395+
SavePixmapPNG(tempOutputImage,exportedFile)
396+
EndIf
397+
TAppOutput.prepForSave = False
398+
TAppOutput.rdyForSave = False
399+
TAppOutput.doDraw = True
379400
EndIf
380401
'Settings textbox inputs
381402
'Scale
@@ -391,7 +412,7 @@ While True
391412
EndIf
392413
SetGadgetText(TAppGUI.editSettingsZoomTextbox,TAppOutput.ZOOM)
393414
TAppOutput.TILESIZE = 24 * TAppOutput.ZOOM
394-
TAppOutput.redoBoneImage = True
415+
TAppOutput.redoLimbTiles = True
395416
TAppOutput.doDraw = True
396417
'Frames
397418
Case TAppGUI.editSettingsFramesTextbox

0 commit comments

Comments
 (0)