Draw bitmap text at an angle?

Started by wombats, August 08, 2018, 13:37:14

Previous topic - Next topic

wombats

I want to be able to draw my bitmap font at the angle set by SetRotation(), like DrawText().

Does anyone know how I can do that?

Type Character
Field id:Int
Field x:Int
Field y:Int
Field w:Int
Field h:Int
Function Create:Character(char:String, x:Int, y:Int, w:Int, h:Int)
Local c:Character = New Character
c.id = Asc(char)
c.x = x
c.y = y
c.w = w
c.h = h
Return c
EndFunction
EndType

Global font:TImage = LoadImage("font.png", 0)

Global Chars:TList = New TList

Local A:Character = New Character.Create("a", 0, 0, 14, 31)
Chars.AddLast(A)

Local B:Character = New Character.Create("c", 18, 0, 15, 31)
Chars.AddLast(B)

Local C:Character = New Character.Create("c", 36, 0, 11, 31)
Chars.AddLast(C)

Local Space:Character = New Character.Create(" ", 48, 0, 11, 31)
Chars.AddLast(Space)

Function DrawBitmapText(t:String, x:Int, y:Int)
Local x1:Int = x
For Local i:Int = 1 To t.length
For Local char:Character = EachIn Chars
If char.id = Asc(Mid(t, i, 1))
DrawSubImageRect(font, x1, y, char.w, char.h, char.x, char.y, char.w, char.h)
x1:+char.w
EndIf
Next
Next
EndFunction

Graphics 640, 480

Repeat

SetClsColor(255, 255, 255)

Cls

SetRotation(45)

SetColor(255, 255, 255)
DrawBitmapText("abcabc", 50, 50)

SetColor(0, 0, 0)
DrawText("abcabc", 300, 50)

Flip

Until KeyHit(KEY_ESCAPE) Or AppTerminate()

col

#1
Like this?
If you are using virtual resolutions then you'll need to factor those 'scalings' into the equation too.


Function DrawBitmapText(t:String, x:Int, y:Int)
Local r:Float = GetRotation()
Local sx:Float, sy:Float
GetScale(sx, sy)

For Local i:Int = 1 To t.length
For Local char:Character = EachIn Chars
If char.id = Asc(Mid(t, i, 1))
DrawSubImageRect(font, x, y, char.w, char.h, char.x, char.y, char.w, char.h)
x :+ Cos(r) * char.w * sx
y :+ Sin(r) * char.w * sy
EndIf
Next
Next
EndFunction
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

wombats