@@ -10,21 +10,36 @@ Strict
10
10
Import MaxGUI.Drivers
11
11
Import BRL.FileSystem
12
12
13
- AppTitle = " CCCP Bender v0.1"
14
-
15
- 'App quitting bool
16
- Global quitResult = False
13
+ 'Version
14
+ Global appVersion:String = " 0.1"
17
15
18
16
'File I/O
19
17
Global importedFile:String = Null
20
18
Global fileFilers:String = " Image Files:png,jpg,bmp"
21
19
22
20
'Output Settings
23
- Global SCALE:String = " 1"
24
- Global FRAMES:String = " 7"
25
- Global BACKGROUND_RED:String = " 255"
26
- Global BACKGROUND_GREEN:String = " 200"
27
- Global BACKGROUND_BLUE:String = " 255"
21
+ Global SCALE:Int = 1
22
+ Global FRAMES:Int = 7
23
+ Global BACKGROUND_RED:Int = 50
24
+ Global BACKGROUND_GREEN:Int = 170
25
+ Global BACKGROUND_BLUE:Int = 255
26
+ Global TILESIZE:Int = 32
27
+
28
+ 'Bools
29
+ Global quitResult = False
30
+ Global mainToWork = False
31
+ Global doDraw = False
32
+
33
+ 'Transition between windows
34
+ Function FAppUpdate ()
35
+ If mainToWork = False
36
+ If importedFile <> Null Then
37
+ FAppWork()
38
+ TGraphicOutput.FGraphicBoot()
39
+ mainToWork = True
40
+ EndIf
41
+ EndIf
42
+ EndFunction
28
43
29
44
'GUI Elements
30
45
Type TAppGUI
@@ -62,26 +77,183 @@ Type TAppGUI
62
77
'Workspace Window Instructions Panel
63
78
Global workHelpPanel:TGadget
64
79
Global workHelpTextbox:TGadget
80
+ EndType
81
+
82
+ 'Output Window Title
83
+ AppTitle = " CCCP Bender v" + appVersion+ " - Output"
84
+
85
+ 'Output Window Elements
86
+ Type TGraphicOutput
87
+ 'Graphic Assets
88
+ Global sourceImage:TImage
89
+ Global boneImage:TImage [BONES]
90
+ 'sourceImage = LoadImage(importedFile,0)
65
91
66
- 'Tansition between windows bool
67
- Global mainToWork = False
92
+ 'Limb Parts
93
+ Global JointX:Float [BONES]
94
+ Global JointY:Float [BONES]
95
+ Global BoneLength:Float [BONES]
96
+
97
+ 'Precalc for drawing
98
+ Global Angle[BONES,FRAMES]
99
+ Global XBone[BONES,FRAMES]
100
+ Global YBone[BONES,FRAMES]
68
101
69
- 'Transition between windows
70
- Function FAppUpdate ()
71
- If mainToWork = False
72
- If importedFile <> Null Then
73
- FAppWork()
74
- mainToWork = True
75
- EndIf
102
+ 'Constants
103
+ Const BONES = 8
104
+ Const LIMBS = BONES/2
105
+ Const UPPER_BONE = 0
106
+ Const LOWER_BONE = 1
107
+ Const REL_ANG = 180
108
+
109
+ 'Variables
110
+ Global AngA:Float
111
+ Global AngB:Float
112
+ Global AngC:Float
113
+
114
+ Function FLawOfCosines (ab,bc,ca)
115
+ AngA = ACos((ca^ 2 + ab^ 2 - bc^ 2 )/(2 *ca*ab))
116
+ AngB = ACos((bc^ 2 + ab^ 2 - ca^ 2 )/(2 *bc*ab))
117
+ AngC = 180 - (AngA+ AngB)
118
+ End Function
119
+
120
+ 'Create output window and draw assets
121
+ Function FGraphicBoot ()
122
+ SetGraphicsDriver GLMax2DDriver()
123
+ Graphics(640 ,480 ,0 ,0 ,0 )
124
+ 'SetScale(SCALE,SCALE)
125
+ 'Window background color
126
+ SetClsColor(BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE)
127
+ SetMaskColor(255 ,0 ,255 )
128
+ DrawImage(sourceImage,0 ,0 )
129
+
130
+ For Local b = 0 To BONES- 1 ' Because I can't (?) set handles on inidividial anim image frames, I must use my own frame sys.
131
+ boneImage[ b] = CreateImage(TILESIZE, TILESIZE, 1 , MASKEDIMAGE)
132
+ GrabImage boneImage[ b] , b*TILESIZE, 0
133
+ Next
134
+
135
+ ' Bones should be centered on image by setting up a TILESIZE grid in photoshop with a subdiv of 2.
136
+ ' However, I rotate around the upper end of bone.
137
+
138
+ For Local i = 0 To BONES- 1 ' Set up default bone sizes.
139
+ JointX[ i] = TILESIZE/2
140
+ JointY[ i] = TILESIZE/3.6
141
+ boneLength[ i] = (TILESIZE/2 - JointY[ i] )*2
142
+ SetImageHandle(boneImage[ i] , JointX[ i] , JointY[ i] )
143
+ Next
144
+
145
+ FBend()
146
+ FDraw()
147
+ doDraw = True
148
+ Flip(1 )
149
+ Cls
150
+ EndFunction
151
+
152
+ 'Sprite rotation
153
+ Function FBend ()
154
+ Local frm = 0
155
+ Local MaxExtend:Float = 0.99 ' 1.0 is not a triangle and might cause trouble?
156
+ Local MinExtend:Float = 0.30 ' Possibly make definable in GUI (slider)
157
+ Local StepSize:Float = (MaxExtend- MinExtend)/(FRAMES- 1 ) ' -1 to make inclusive of last value (full range)
158
+ Local b, l, f, x, y, AirLen, UpperLen, LowerLen
159
+ For Local l = 0 To LIMBS- 1
160
+ For Local f = 0 To FRAMES- 1
161
+ b = l*2
162
+ x = f * TILESIZE + 96
163
+ y = l * TILESIZE * 1.5 + 200
164
+ UpperLen = BoneLength[ b] ' e.g. upper leg
165
+ LowerLen = BoneLength[ b+ 1 ] ' e.g. lower leg
166
+ AirLen = (StepSize*f + MinExtend) * (UpperLen + LowerLen) ' Sum of the two bones * step scaler for frame. (hip-ankle)
167
+ FLawOfCosines(AirLen, UpperLen, LowerLen)
168
+ Angle[ b,f] = AngB ' Geez this was kinda tricky, angles upon angles.
169
+ XBone[ b,f] = x
170
+ YBone[ b,f] = y
171
+ x:- Sin(Angle[ b,f] )*UpperLen ' Position of knee.
172
+ y:+ Cos(Angle[ b,f] )*UpperLen ' Could just use another angle of the triangle though, but I didn't.
173
+ Angle[ b+ 1 ,f] = AngC + AngB + 180 ' It looks correct on screen so I'm just gonna leave it at that!
174
+ XBone[ b+ 1 ,f] = x
175
+ YBone[ b+ 1 ,f] = y
176
+ Next
177
+ Next
178
+ EndFunction
179
+
180
+ Function FSetSpot ()
181
+ Local xm = MouseX()
182
+ Local ym = MouseY()
183
+ If ym < (TILESIZE/2 - 2 ) And ym > 0 And xm > 0 And xm < TILESIZE*BONES ' Clicked in region? Possibly dupe points for rear limbs.
184
+ Local b = xm/TILESIZE
185
+ JointX[ b] = TILESIZE/2 ' X is always at center, so kinda pointless to even bother.
186
+ JointY[ b] = ym ' Determines length
187
+ boneLength[ b] = (TILESIZE/2 - ym)*2
188
+ SetImageHandle(boneImage[ b] , JointX[ b] , JointY[ b] ) ' Rotation handle.
76
189
EndIf
77
190
EndFunction
191
+
192
+ 'Draw bone marks
193
+ Function FDrawMark (x,y)
194
+ SetRotation(0 )
195
+ SetColor(0 ,0 ,80 )
196
+ x:+ 1 y:+ 1 'add a shade for clarity on bright colours
197
+ DrawLine(x- 2 ,y,x+ 2 ,y)
198
+ DrawLine(x,y- 2 ,x,y+ 2 )
199
+ x:- 1 y:- 1 'Cross
200
+ SetColor(255 ,230 ,80 )
201
+ DrawLine(x- 2 ,y,x+ 2 ,y)
202
+ DrawLine(x,y- 2 ,x,y+ 2 )
203
+ End Function
204
+
205
+ Function FDraw ()
206
+ SetColor(255 ,255 ,255 )
207
+ DrawImage(sourceImage,0 ,0 )
208
+ SetColor(255 ,230 ,80 )
209
+ 'Footer text
210
+ DrawText(" TBA" ,0 ,480 - 15 )
211
+ 'Draw the + marks.
212
+ For Local i = 0 To BONES- 1
213
+ FDrawMark(JointX[ i] + i*TILESIZE,JointY[ i] )
214
+ FDrawMark(JointX[ i] + i*TILESIZE,JointY[ i] + BoneLength[ i] )
215
+ Next
216
+
217
+ SetColor(255 ,255 ,255 )
218
+ For Local f = 0 To FRAMES- 1
219
+ ' These might be in a specific draw-order for joint overlapping purposes
220
+ Local b
221
+ b = 0 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
222
+ b = 1 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
223
+ b = 2 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
224
+ b = 3 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
225
+ b = 4 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
226
+ b = 5 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
227
+ b = 6 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
228
+ b = 7 SetRotation(Angle[ b,f] ) DrawImage(boneImage[ b] ,XBone[ b,f] ,YBone[ b,f] )
229
+ Next
230
+
231
+ SetRotation(0 )
232
+ End Function
233
+
234
+ Function FOutputUpdate ()
235
+ If MouseDown(1 ) Then ' Left mouse to adjust bone spots.
236
+ FSetSpot()
237
+ FBend()
238
+ doDraw = True
239
+ EndIf
240
+ If doDraw
241
+ SetClsColor(BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE)
242
+ FDraw()
243
+ Flip(1 )
244
+ Cls
245
+ doDraw = False
246
+ Else
247
+ Delay(20 )
248
+ EndIf
249
+ End Function
78
250
EndType
79
251
80
252
FAppMain()
81
253
82
254
Function FAppMain ()
83
255
'Create main app window
84
- TAppGUI.mainWindow = CreateWindow(" CCCP Bender v0.1 " ,DesktopWidth()/2 - 150 ,DesktopHeight()/2 - 180 ,300 ,360 ,Null ,WINDOW_TITLEBAR)
256
+ TAppGUI.mainWindow = CreateWindow(" CCCP Bender v " + appVersion ,DesktopWidth()/2 - 150 ,DesktopHeight()/2 - 180 ,300 ,360 ,Null ,WINDOW_TITLEBAR)
85
257
86
258
'TAppGUI.mainWindowLabel = CreateLabel("",0,0,GadgetWidth(TAppGUI.mainWindow),100,TAppGUI.mainWindow,LABEL_LEFT)
87
259
@@ -96,7 +268,9 @@ EndFunction
96
268
97
269
Function FAppWork ()
98
270
'Create workspace window
99
- TAppGUI.workWindow = CreateWindow(" CCCP Bender v0.1 - Editor" ,DesktopWidth()/2 - 152 ,DesktopHeight()/2 - 222 ,305 ,455 ,Null ,WINDOW_TITLEBAR)
271
+ 'TAppGUI.workWindow = CreateWindow("CCCP Bender v0.1 - Editor",DesktopWidth()/2-152,DesktopHeight()/2-222,305,455,Null,WINDOW_TITLEBAR)
272
+ TAppGUI.workWindow = CreateWindow(" CCCP Bender v" + appversion+ " - Editor" ,DesktopWidth()/2 - 640 ,DesktopHeight()/2 - 240 ,305 ,455 ,Null ,WINDOW_TITLEBAR)
273
+
100
274
TAppGUI.workWindowButtonPanel = CreatePanel(10 ,7 ,280 ,57 ,TAppGUI.workWindow,PANEL_GROUP)
101
275
TAppGUI.workLoadButton = CreateButton(" Load" ,5 ,0 ,80 ,30 ,TAppGUI.workWindowButtonPanel,BUTTON_PUSH)
102
276
TAppGUI.workSaveButton = CreateButton(" Save" ,95 ,0 ,80 ,30 ,TAppGUI.workWindowButtonPanel,BUTTON_PUSH)
@@ -133,7 +307,8 @@ Function FAppWork()
133
307
EndFunction
134
308
135
309
While True
136
- TAppGUI.FAppUpdate()
310
+ FAppUpdate()
311
+ TGraphicOutput.FOutputUpdate()
137
312
138
313
'Print appState
139
314
'Print SCALE
@@ -145,7 +320,7 @@ While True
145
320
146
321
'Event responses
147
322
148
- If TAppGUI. mainToWork = False Then
323
+ If mainToWork = False Then
149
324
Select EventID()
150
325
'Quitting
151
326
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
@@ -157,10 +332,11 @@ While True
157
332
End
158
333
'Loading
159
334
Case TAppGUI.mainLoadButton
160
- importedFile = RequestFile(" Select graphic file to open" ,fileFilers)
335
+ importedFile = RequestFile(" Select graphic file to open" ,fileFilers)
336
+ TGraphicOutput.sourceImage = LoadImage(importedFile,0 )
161
337
EndSelect
162
338
EndSelect
163
- ElseIf TAppGUI. mainToWork = True Then
339
+ ElseIf mainToWork = True Then
164
340
165
341
'Quitting
166
342
If quitResult Then
@@ -180,22 +356,33 @@ While True
180
356
'Loading
181
357
Case TAppGUI.workLoadButton
182
358
importedFile = RequestFile(" Select graphic file to open" ,fileFilers)
183
-
359
+ If importedFile = Null Then
360
+ TGraphicOutput.sourceImage = LoadImage(" no-input.png" ,0 )
361
+ Else
362
+ TGraphicOutput.sourceImage = LoadImage(importedFile,0 )
363
+ EndIf
184
364
'Saving
185
365
Case TAppGUI.workSaveButton
186
366
RequestFile(" Save graphic file" ,fileFilers,True )
187
367
188
368
'Settings textbox input
189
369
Case TAppGUI.settingsScaleTextbox
190
370
SCALE = GadgetText(TAppGUI.settingsScaleTextbox).ToInt()
371
+ SetScale(SCALE,SCALE)
372
+ TILESIZE = 32 * SCALE
373
+ doDraw = True
191
374
Case TAppGUI.settingFramesTextbox
192
375
FRAMES = GadgetText(TAppGUI.settingFramesTextbox).ToInt()
376
+ doDraw = True
193
377
Case TAppGUI.settingsColorRTextbox
194
378
BACKGROUND_RED = GadgetText(TAppGUI.settingsColorRTextbox).ToInt()
379
+ doDraw = True
195
380
Case TAppGUI.settingsColorGTextbox
196
381
BACKGROUND_GREEN = GadgetText(TAppGUI.settingsColorGTextbox).ToInt()
382
+ doDraw = True
197
383
Case TAppGUI.settingsColorBTextbox
198
384
BACKGROUND_BLUE = GadgetText(TAppGUI.settingsColorBTextbox).ToInt()
385
+ doDraw = True
199
386
EndSelect
200
387
EndSelect
201
388
EndIf
0 commit comments