Skip to content

Commit c48b0b2

Browse files
committed
Misc cleanup
1 parent 64e1292 commit c48b0b2

File tree

5 files changed

+114
-121
lines changed

5 files changed

+114
-121
lines changed

types/GraphicsOutput.bmx

Lines changed: 71 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ Import "LimbManager.bmx"
44
'//// GRAPHICS OUTPUT ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55

66
Type GraphicsOutput
7-
'Draw Bools
8-
Field m_RedoLimbTiles:Int = False
9-
'Constants
10-
Const c_MaxZoom:Int = 11
117
Const c_MaxFrameCount:Int = 20
12-
Field c_Magenta:Int[] = [255, 0, 255]
13-
'Graphic Assets
148

159
Field m_MaxZoom:Int = 5 'Assume 1366px is the lowest resolution because it's not 1999. 1366px - 260px (left column) = 1106 / 192 (source image width) = 5 (floored)
10+
Field m_Magenta:Int[] = [255, 0, 255]
11+
1612
Field m_SourceImage:TImage
1713
Field m_SourceImageSize:SVec2I
18-
'Output Settings
14+
1915
Field m_InputZoom:Int = g_DefaultInputZoom
2016
Field m_TileSize:Int = 24 * m_InputZoom
2117
Field m_FrameCount:Int = g_DefaultFrameCount
@@ -32,7 +28,7 @@ Type GraphicsOutput
3228

3329
Method New(maxWorkspaceWidth:Int)
3430
SetClsColor(m_BackgroundColor[0], m_BackgroundColor[1], m_BackgroundColor[2])
35-
SetMaskColor(c_Magenta[0], c_Magenta[1], c_Magenta[2])
31+
SetMaskColor(m_Magenta[0], m_Magenta[1], m_Magenta[2])
3632

3733
m_MaxZoom = Int(FloorF(maxWorkspaceWidth / 192))
3834
EndMethod
@@ -49,14 +45,6 @@ Type GraphicsOutput
4945
EndIf
5046
EndMethod
5147

52-
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53-
54-
Method SetBackgroundColor:Int[](rgbValue:Int[])
55-
m_BackgroundColor = rgbValue
56-
ChangeBackgroundColor(m_BackgroundColor)
57-
Return m_BackgroundColor
58-
EndMethod
59-
6048
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6149

6250
Method SetInputZoom:Int(newZoom:Int)
@@ -74,15 +62,10 @@ Type GraphicsOutput
7462

7563
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7664

77-
Method GetFrameCount:Int()
78-
Return m_FrameCount
79-
EndMethod
80-
81-
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82-
83-
Method SetFrameCount:Int(newCount:Int)
84-
m_FrameCount = Utility.Clamp(newCount, 1, c_MaxFrameCount)
85-
Return m_FrameCount
65+
Method SetBackgroundColor:Int[](rgbValue:Int[])
66+
m_BackgroundColor = rgbValue
67+
ChangeBackgroundColor(m_BackgroundColor)
68+
Return m_BackgroundColor
8669
EndMethod
8770

8871
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -101,60 +84,21 @@ Type GraphicsOutput
10184

10285
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10386

104-
Method SetDrawOutputFrameBounds(drawOrNot:Int)
105-
m_DrawOutputFrameBounds = drawOrNot
87+
Method GetFrameCount:Int()
88+
Return m_FrameCount
10689
EndMethod
10790

10891
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10992

110-
Method Update()
111-
'Left mouse to adjust joint markers, click or hold and drag
112-
If MouseDown(1) Then
113-
Local mousePos:SVec2I = New SVec2I(MouseX(), MouseY())
114-
If Utility.PointIsWithinBox(mousePos, New SVec2I(0, 0), m_SourceImageSize * m_InputZoom) Then
115-
m_LimbManager.SetJointMarker(mousePos)
116-
EndIf
117-
EndIf
93+
Method SetFrameCount:Int(newCount:Int)
94+
m_FrameCount = Utility.Clamp(newCount, 1, c_MaxFrameCount)
95+
Return m_FrameCount
11896
EndMethod
11997

12098
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12199

122-
Method Draw()
123-
If m_SourceImage = Null Then
124-
DrawNoSourceImageScreen()
125-
Else
126-
Cls()
127-
128-
SetColor(c_Magenta[0], c_Magenta[1], c_Magenta[2])
129-
DrawRect(0, 0, GraphicsWidth(), (m_SourceImageSize[1] * m_InputZoom) + 1) 'Extend the source image magenta strip all the way to the right and adjust height to input zoom
130-
Utility.ResetDrawColor()
131-
DrawImageRect(m_SourceImage, 0, 0, m_SourceImageSize[0] * m_InputZoom, m_SourceImageSize[1] * m_InputZoom)
132-
133-
m_LimbManager.DrawTileOutlines()
134-
m_LimbManager.DrawJointMarkers()
135-
136-
Local vertOffsetFromSource:Int = (m_SourceImageSize[1] * m_InputZoom) + 34
137-
m_LimbManager.DrawBentLimbs(New SVec2I(100, vertOffsetFromSource), m_FrameCount)
138-
139-
Local drawColor:Int[] = [255, 230, 80]
140-
Utility.DrawTextWithShadow("Arm FG", New SVec2I(10, vertOffsetFromSource), drawColor)
141-
Utility.DrawTextWithShadow("Arm BG", New SVec2I(10, vertOffsetFromSource + 50 - 2), drawColor)
142-
Utility.DrawTextWithShadow("Leg FG", New SVec2I(10, vertOffsetFromSource + (50 * 2) - 4), drawColor)
143-
Utility.DrawTextWithShadow("Leg BG", New SVec2I(10, vertOffsetFromSource + (50 * 3) - 6), drawColor)
144-
145-
If m_DrawOutputFrameBounds Then
146-
drawColor = [0, 0, 80]
147-
m_FrameBoundingBoxSize = New SVec2I(32, 48)
148-
For Local row:Int = 0 Until c_LimbCount
149-
For Local frame:Int = 0 Until m_FrameCount
150-
m_FrameBoundingBoxPosX[row, frame] = 100 - 20 + (frame * (m_TileSize / m_InputZoom + 8))
151-
m_FrameBoundingBoxPosY[row, frame] = vertOffsetFromSource - 12 + (row * 48)
152-
Utility.DrawRectOutline(New SVec2I(m_FrameBoundingBoxPosX[row, frame], m_FrameBoundingBoxPosY[row, frame]), m_FrameBoundingBoxSize, drawColor)
153-
Next
154-
Next
155-
EndIf
156-
Flip(1)
157-
EndIf
100+
Method SetDrawOutputFrameBounds(drawOrNot:Int)
101+
m_DrawOutputFrameBounds = drawOrNot
158102
EndMethod
159103

160104
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -163,9 +107,9 @@ Type GraphicsOutput
163107
If m_SourceImage = Null Then
164108
Notify("Nothing to save!", False)
165109
Else
166-
ChangeBackgroundColor(c_Magenta)
110+
ChangeBackgroundColor(m_Magenta)
167111
Draw()
168-
Flip(1) 'Have to flip again for background color to actually change, not sure why but whatever
112+
Flip(1) 'Have to flip again for background color to actually change (for the grabbed pixmap, not the canvas), not sure why but whatever
169113
Return GrabPixmap(55, 120, 34 * m_FrameCount, 210)
170114
EndIf
171115
EndMethod
@@ -176,9 +120,9 @@ Type GraphicsOutput
176120
If m_SourceImage = Null Then
177121
Notify("Nothing to save!", False)
178122
Else
179-
ChangeBackgroundColor(c_Magenta)
123+
ChangeBackgroundColor(m_Magenta)
180124
Draw()
181-
Flip(1) 'Have to flip again for background color to actually change, not sure why but whatever
125+
Flip(1) 'Have to flip again for background color to actually change (for the grabbed pixmaps, not the canvas), not sure why but whatever
182126

183127
Local framesToSave:TPixmap[c_LimbCount, m_FrameCount]
184128
For Local row:Int = 0 Until c_LimbCount
@@ -198,6 +142,18 @@ Type GraphicsOutput
198142
EndIf
199143
EndMethod
200144

145+
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
146+
147+
Method Update()
148+
'Left mouse to adjust joint markers, click or hold and drag
149+
If MouseDown(1) Then
150+
Local mousePos:SVec2I = New SVec2I(MouseX(), MouseY())
151+
If Utility.PointIsWithinBox(mousePos, New SVec2I(0, 0), m_SourceImageSize * m_InputZoom) Then
152+
m_LimbManager.SetJointMarker(mousePos)
153+
EndIf
154+
EndIf
155+
EndMethod
156+
201157
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202158

203159
Method DrawNoSourceImageScreen()
@@ -209,4 +165,44 @@ Type GraphicsOutput
209165
SetScale(1, 1)
210166
Flip(1)
211167
EndMethod
168+
169+
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
170+
171+
Method Draw()
172+
If m_SourceImage = Null Then
173+
DrawNoSourceImageScreen()
174+
Else
175+
Cls()
176+
177+
SetColor(m_Magenta[0], m_Magenta[1], m_Magenta[2])
178+
DrawRect(0, 0, GraphicsWidth(), (m_SourceImageSize[1] * m_InputZoom) + 1) 'Extend the source image magenta strip all the way to the right and adjust height to input zoom
179+
Utility.ResetDrawColor()
180+
DrawImageRect(m_SourceImage, 0, 0, m_SourceImageSize[0] * m_InputZoom, m_SourceImageSize[1] * m_InputZoom)
181+
182+
m_LimbManager.DrawTileOutlines()
183+
m_LimbManager.DrawJointMarkers()
184+
185+
Local vertOffsetFromSource:Int = (m_SourceImageSize[1] * m_InputZoom) + 34
186+
m_LimbManager.DrawBentLimbs(New SVec2I(100, vertOffsetFromSource), m_FrameCount)
187+
188+
Local drawColor:Int[] = [255, 230, 80]
189+
Utility.DrawTextWithShadow("Arm FG", New SVec2I(10, vertOffsetFromSource), drawColor)
190+
Utility.DrawTextWithShadow("Arm BG", New SVec2I(10, vertOffsetFromSource + 50 - 2), drawColor)
191+
Utility.DrawTextWithShadow("Leg FG", New SVec2I(10, vertOffsetFromSource + (50 * 2) - 4), drawColor)
192+
Utility.DrawTextWithShadow("Leg BG", New SVec2I(10, vertOffsetFromSource + (50 * 3) - 6), drawColor)
193+
194+
If m_DrawOutputFrameBounds Then
195+
drawColor = [0, 0, 80]
196+
m_FrameBoundingBoxSize = New SVec2I(32, 48)
197+
For Local row:Int = 0 Until c_LimbCount
198+
For Local frame:Int = 0 Until m_FrameCount
199+
m_FrameBoundingBoxPosX[row, frame] = 100 - 20 + (frame * (m_TileSize / m_InputZoom + 8))
200+
m_FrameBoundingBoxPosY[row, frame] = vertOffsetFromSource - 12 + (row * 48)
201+
Utility.DrawRectOutline(New SVec2I(m_FrameBoundingBoxPosX[row, frame], m_FrameBoundingBoxPosY[row, frame]), m_FrameBoundingBoxSize, drawColor)
202+
Next
203+
Next
204+
EndIf
205+
Flip(1)
206+
EndIf
207+
EndMethod
212208
EndType

types/IndexedPixmap.bmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Type IndexedPixmap
4343
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4444

4545
Method WritePixel(x:Int, y:Int, index:Byte)
46-
Assert x >= 0 And x < m_Width And y>=0 And y < m_Height Else "Pixmap coordinates out of bounds!"
46+
Assert x >= 0 And x < m_Width And y >= 0 And y < m_Height Else "Pixmap coordinates out of bounds!"
4747
Local pixel:Byte Ptr = PixelPtr(x, y)
4848
pixel[0] = index
4949
EndMethod

types/JointMarker.bmx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
Type JointMarker
44
Field m_ParentTilePosOnCanvas:SVec2I
5-
65
Field m_PosOnTileX:Int
76
Field m_PosOnTileY:Int
87
Field m_PosOnCanvasX:Int
98
Field m_PosOnCanvasY:Int
10-
119
Field m_Radius:Int
12-
1310
Field m_Selected:Int
1411

1512
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

types/LimbManager.bmx

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,6 @@ Type LimbManager
5454
Next
5555
EndMethod
5656

57-
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58-
59-
Method LawOfCosines:Float[](ab:Float, bc:Float, ca:Float)
60-
Local result:Float[] = [0, 0, 0]
61-
result[0] = ACos((ca ^ 2 + ab ^ 2 - bc ^ 2) / (2 * ca * ab))
62-
result[1] = ACos(( bc ^ 2 + ab ^ 2 - ca ^ 2) / (2 * bc * ab))
63-
result[2] = (180 - (result[0] + result[1]))
64-
Return result
65-
EndMethod
66-
6757
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6858

6959
Method SetJointMarker(mousePos:SVec2I)
@@ -105,27 +95,12 @@ Type LimbManager
10595

10696
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10797

108-
Method BendLimbs(frameCount:Int)
109-
Local stepSize:Float = (c_MaxExtend - c_MinExtend) / (frameCount - 1) '-1 to make inclusive of last value (full range)
110-
For Local limb:Float = 0 Until c_LimbCount
111-
For Local frame:Int = 0 Until frameCount
112-
Local limbPart:Int = limb * 2
113-
Local posX:Float = (frame * 32) 'Drawing position X
114-
Local posY:Float = ((limb * 32) * 1.5 ) 'Drawing position Y
115-
Local upperLength:Float = m_LimbPartLength[limbPart] / m_InputZoom
116-
Local lowerLength:Float = m_LimbPartLength[limbPart + 1] / m_InputZoom
117-
Local airLength:Float = ((stepSize * frame) + c_MinExtend) * (upperLength + lowerLength) 'Sum of the two bones * step scaler for frame (hip-ankle)
118-
Local bendAngle:Float[] = LawOfCosines(airLength, upperLength, lowerLength)
119-
m_LimbPartAngle[limbPart, frame] = bendAngle[1]
120-
m_LimbPartPosX[limbPart, frame] = posX
121-
m_LimbPartPosY[limbPart, frame] = posY
122-
posX :- Sin(m_LimbPartAngle[limbPart, frame]) * upperLength 'Position of knee
123-
posY :+ Cos(m_LimbPartAngle[limbPart, frame]) * upperLength
124-
m_LimbPartAngle[limbPart + 1, frame] = bendAngle[1] + bendAngle[2] + 180
125-
m_LimbPartPosX[limbPart + 1, frame] = posX
126-
m_LimbPartPosY[limbPart + 1, frame] = posY
127-
Next
98+
Method DrawJointMarkers()
99+
SetRotation(0)
100+
For Local marker:JointMarker = EachIn m_JointMarkers
101+
marker.Draw()
128102
Next
103+
Utility.ResetDrawColor()
129104
EndMethod
130105

131106
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -152,12 +127,27 @@ Type LimbManager
152127

153128
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154129

155-
Method DrawJointMarkers()
156-
SetRotation(0)
157-
For Local marker:JointMarker = EachIn m_JointMarkers
158-
marker.Draw()
130+
Method BendLimbs(frameCount:Int)
131+
Local stepSize:Float = (c_MaxExtend - c_MinExtend) / (frameCount - 1) '-1 to make inclusive of last value (full range)
132+
For Local limb:Float = 0 Until c_LimbCount
133+
For Local frame:Int = 0 Until frameCount
134+
Local limbPart:Int = limb * 2
135+
Local posX:Float = (frame * 32) 'Drawing position X
136+
Local posY:Float = ((limb * 32) * 1.5 ) 'Drawing position Y
137+
Local upperLength:Float = m_LimbPartLength[limbPart] / m_InputZoom
138+
Local lowerLength:Float = m_LimbPartLength[limbPart + 1] / m_InputZoom
139+
Local airLength:Float = ((stepSize * frame) + c_MinExtend) * (upperLength + lowerLength) 'Sum of the two bones * step scaler for frame (hip-ankle)
140+
Local bendAngle:Float[] = Utility.LawOfCosines(airLength, upperLength, lowerLength)
141+
m_LimbPartAngle[limbPart, frame] = bendAngle[1]
142+
m_LimbPartPosX[limbPart, frame] = posX
143+
m_LimbPartPosY[limbPart, frame] = posY
144+
posX :- Sin(m_LimbPartAngle[limbPart, frame]) * upperLength 'Position of knee
145+
posY :+ Cos(m_LimbPartAngle[limbPart, frame]) * upperLength
146+
m_LimbPartAngle[limbPart + 1, frame] = bendAngle[1] + bendAngle[2] + 180
147+
m_LimbPartPosX[limbPart + 1, frame] = posX
148+
m_LimbPartPosY[limbPart + 1, frame] = posY
149+
Next
159150
Next
160-
Utility.ResetDrawColor()
161151
EndMethod
162152

163153
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

types/Utility.bmx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
'//// EXTERNAL FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2-
3-
Extern
4-
Function png_set_PLTE(png_ptr:Byte Ptr, info_ptr:Byte Ptr, palette:Byte Ptr, num_palette:Int) = "bmx_png_set_PLTE"
5-
EndExtern
6-
71
'//// UTILITY FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82

93
Type Utility
104

5+
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6+
7+
Function LawOfCosines:Float[](ab:Float, bc:Float, ca:Float)
8+
Local result:Float[] = [0, 0, 0]
9+
result[0] = ACos((ca ^ 2 + ab ^ 2 - bc ^ 2) / (2 * ca * ab))
10+
result[1] = ACos(( bc ^ 2 + ab ^ 2 - ca ^ 2) / (2 * bc * ab))
11+
result[2] = 180 - (result[0] + result[1])
12+
Return result
13+
EndFunction
14+
1115
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1216

1317
Function Clamp:Int(valueToClamp:Int, minValue:Int, maxValue:Int)
@@ -107,4 +111,10 @@ Type Utility
107111
Local outputStream:TStream = TStream(png_get_io_ptr(pngPtr))
108112
FlushStream(outputStream)
109113
EndFunction
110-
EndType
114+
EndType
115+
116+
'//// EXTERNAL FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117+
118+
Extern
119+
Function png_set_PLTE(png_ptr:Byte Ptr, info_ptr:Byte Ptr, palette:Byte Ptr, num_palette:Int) = "bmx_png_set_PLTE"
120+
EndExtern

0 commit comments

Comments
 (0)