Skip to content

Commit e8239b5

Browse files
committed
Add utility to rotate pixmap
1 parent c439bb1 commit e8239b5

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

types/Utility.bmx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Type Utility
2121

2222
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2323

24-
Function DrawTextWithShadow(text:String, pos:Svec2I, color:Int[])
24+
Function DrawTextWithShadow(text:String, pos:SVec2I, color:Int[])
2525
SetColor(0, 0, 80)
2626
DrawText(text, pos[0] + 1, pos[1] + 1)
2727
SetColor(color[0], color[1], color[2])
@@ -53,4 +53,38 @@ Type Utility
5353
Function PointIsWithinBox:Int(point:SVec2I, boxPos:SVec2I, boxSize:SVec2I)
5454
Return point[0] >= boxPos[0] And point[0] < (boxPos[0] + boxSize[0]) And point[1] >= boxPos[1] And point[1] < (boxPos[1] + boxSize[1])
5555
EndFunction
56+
57+
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58+
59+
Function RotatePixmap:TPixmap(sourcePixmap:TPixmap, angle:Int)
60+
Local outputPixmap:TPixmap
61+
62+
'This is pretty garbage but BlitzMax life is hard
63+
Select angle
64+
Case 90
65+
outputPixmap = CreatePixmap(sourcePixmap.Height, sourcePixmap.Width, sourcePixmap.Format)
66+
For Local x:Int = 0 Until sourcePixmap.Width
67+
For Local y:Int = 0 Until sourcePixmap.Height
68+
WritePixel(outputPixmap, sourcePixmap.Height - y - 1, x, ReadPixel(sourcePixmap, x, y))
69+
Next
70+
Next
71+
Case 180
72+
outputPixmap = CreatePixmap(sourcePixmap.Width, sourcePixmap.Height, sourcePixmap.Format)
73+
For Local x:Int = 0 Until sourcePixmap.Width
74+
For Local y:Int = 0 Until sourcePixmap.Height
75+
WritePixel(outputPixmap, sourcePixmap.Width - x - 1, sourcePixmap.Height - y - 1, ReadPixel(sourcePixmap, x, y))
76+
Next
77+
Next
78+
Case 270, -90
79+
outputPixmap = CreatePixmap(sourcePixmap.Height, sourcePixmap.Width, sourcePixmap.Format)
80+
For Local x:Int = 0 Until sourcePixmap.Width
81+
For Local y:Int = 0 Until sourcePixmap.Height
82+
WritePixel(outputPixmap, y, sourcePixmap.Width - x - 1, ReadPixel(sourcePixmap, x, y))
83+
Next
84+
Next
85+
Default
86+
outputPixmap = sourcePixmap
87+
EndSelect
88+
Return outputPixmap
89+
EndFunction
5690
EndType

0 commit comments

Comments
 (0)