OK, any problems let me know :
Strict
Framework BRL.Basic
?win32
Import BRL.D3D7Max2D
?
Import BRL.GLMax2D
Import BRL.Retro
Import BRL.TGALoader
Import BRL.PNGLoader
'Local DX_Driver = D3D7Max2DDriver()
'Local GL_Driver:TGLMax2DDriver = GLMax2DDriver()
SetGraphicsDriver GLMax2DDriver()
Graphics 1024,768,0
'Create a FonText Type
'The function will expect to find the accompanying .ini that was created when you
'made your bitmap font in FonText. It should reside in the same folder as the bitmap
Local myFT:FonText = FonText.Create("f.png", FILTEREDIMAGE)
Local rot# = 0
Local i:Int
Local cen:Byte = False
Local scale:Float = 1.0
Local time:Int
Local text:String
Local angle:Float = 0
Local lbToggle:Byte = False
text = "Justified Text!"+Chr(13)+Chr(13)
text:+ "This text is drawn using DrawJustified(), the text is automatically wrapped at a user "
text:+ "specified pixel width. Spaces are not drawn if they're at the beginning of a line, and words are "
text:+ "wrapped properly so they don't get split!"+Chr(13)+Chr(13)
text:+ "The line break width can be optionally scaled (press RETURN to see it in action)"+Chr(13)
text:+ "Also..."+Chr(13)
text:+ "Line breaks..."+Chr(13)
text:+ "Are..."+Chr(13)
text:+ "Supported!"
SeedRnd(MilliSecs())
While Not KeyHit(KEY_ESCAPE)
Cls
If 0
For i=1 To 100
SetColor Rand(50,100),Rand(50,100),Rand(50,100)
DrawRect Rand(600),Rand(400),200,200
Next
SetColor 255,255,255
End If
SetRotation rot
SetScale scale,scale
If KeyHit(KEY_T) 'create an animated fontext routine
Local mx=MouseX()
Local my=MouseY()
Local cr#=Cos(rot+90)
Local cs#=Sin(rot+90)
afonText.Create("Wouldn't it be nice...", myFT, mx, my, 0, 2000, 4000, 2000, 2, 1,0)
afonText.Create("To be able to automate..", myFT, mx+cr*40, my+cs*40*scale, 1000, 2000, 3000, 2000, 2, 1,-1)
afonText.Create("Text fading onto the screen..", myFT, mx+cr*80, my+cs*80*scale, 2000, 2000, 2000, 2000, 2, 1,1)
afonText.Create("?", myFT, mx+cr*150, my+cs*150*scale, 4000, 2000, 2000, 2000, 0, 1,0)
afontext.Create("..Well now you can!", myFT, mx+cr*200, my+cs*200*scale, 5000, 2000, 2000, 2000, 2, 1,0)
End If
SetRotation 0
SetScale scale*.5,scale*.5
myFT.DrawJustified(text,60,60,False,2,800,lbToggle)
SetBlend ALPHABLEND
SetScale scale,scale
Local x#=MouseX()
Local y#=MouseY()
time = MilliSecs()
SetRotation 0
'SetScale 1,1
myFT.Draw("FonText Rocks!",GraphicsWidth()/2,0,True,4)
myFT.DrawVertical("Vertical Text",0,0,cen,-20)
SetScale scale,scale
SetRotation rot
'myFT.DrawVertical("Draw Vertical",0,0,cen,-25) '* working
myFT.DrawWave("Drawn with DrawWave()",x,y,angle,45,8,cen,8) '* working
myFT.DrawWiggle("Drawn with DrawWiggle()",x,y+60,angle,45,8,cen,8) '* working
myFT.DrawBouncy("Drawn with DrawBouncy()",x,y+120,angle,15,24,cen,6) '* working
myFT.DrawWobble("Drawn with DrawWobble()",x,y+180,-angle,-45,10,cen,6) '* working
myFT.DrawSineSize("Drawn with DrawSineSize()",x,y+240,-angle,-45,30,cen,6) '* working
myFT.DrawSwing("Drawn with DrawSwing()",x,y+300,-angle,5,20,cen,6) '* working
aFonText.Update()
time = MilliSecs() - time
angle:- 5
SetScale 1,1
SetRotation 0
If KeyHit(KEY_RETURN) lbToggle = Not lbToggle
If KeyDown(KEY_LEFT) scale:- .01
If KeyDown(KEY_RIGHT) scale:+ .01
If KeyHit(KEY_SPACE) cen=Not cen
If MouseDown(1) rot:- 1
If MouseDown(2) rot:+ 1
SetScale .3,.3
myFT.Draw("FonText draw time: "+time+"ms",0,728,False,2)
myFT.Draw("LMB/RMB rotate, cursor LEFT/RIGHT adjust scale, SPACE toggle center, 't' for a special FX",0,748,False,2)
'DrawText MemAlloced(),0,0
Flip
Wend
EndGraphics()
Type FonText
Field image:TImage
Field blockHeight:Int
Field char:Byte[255] 'Boolean for each ASCII character, True if the FonText includes it, False if not
Field maskColor:Int
Field packed:Int
Field pX:Float[255] 'Position X
Field pY:Float[255] 'Position Y
Field cW:Int[255] 'Width
Field sinL:Float[360] 'not used yet
Field cosL:Float[360] ' ""
Field iwM:Float 'Image width & height multipliers used in
Field ihM:Float 'functions to optimise UV calculation speed
Field u0:Float[255]
Field v0:Float[255]
Field u1:Float[255]
Field v1:Float[255]
Function Create:FonText(file:String,flags:Int = -1)
Local img:TImage = LoadImage(file,flags)
If Not img RuntimeError "Could not load Image "+file
SetImageHandle(img,0,0)
Local ini:TStream = OpenFile(Left$(file,file.length - 3)+"ini")
If Not ini RuntimeError "Could not find "+Left$(file,file.length - 3)+"ini"
Local f:FonText = New FonText
f.image = img
f.iwM = 1.0 / img.width
f.ihM = 1.0 / img.height
'Get BlockSize (height)
Local r:String
'Ignore first 3 lines
ReadLine(ini)
ReadLine(ini)
ReadLine(ini)
'Get MaskColor (needed?)
r = ReadLine(ini)
f.maskColor = Int(Right$(r,r.length-10))
'Packed Font?
r = ReadLine(ini)
f.packed = Int(Right$(r,1))
'Find [text] line
r = ReadLine(ini)
While r<>"[text]"
r = ReadLine(ini)
Wend
'Block Height
r = ReadLine(ini)
f.blockHeight = Int(Right$(r,r.length - 10))
'Count Characters
r = ReadLine(ini)
While r<>"[charset]"
r = ReadLine(ini)
Wend
'Store this location
Local location:Int = StreamPos(ini)
'do the count
Local count:Int = 0
While Not Eof(ini)
r = ReadLine(ini)
count:+ 1
Wend
'Back to the Characters...
SeekStream(ini,location)
Local i:Int,j:Int,s:String,t:String
Local cur:Byte
'Parse each characters position & width
For i = 0 Until count
r = ReadLine(ini)
cur = Asc(Left$(r,1))
f.char[cur] = True
'Position X
j = 3
s = ""
t = Mid$(r,j,1)
While t<>","
s:+ t
j:+1
t = Mid$(r,j,1)
Wend
f.pX[cur] = Float(s)
'Position Y
j:+1
s = ""
t = Mid$(r,j,1)
While t<>","
s:+ t
j:+1
t = Mid$(r,j,1)
Wend
f.pY[cur] = Float(s)
'Character Width
j:+ 1
s = ""
t = Mid$(r,j,1)
While t<>","
s:+ t
j:+1
If j>r.length Exit
t = Mid$(r,j,1)
Wend
f.cW[cur] = Int(s)
'Adjust packing if the font isn't packed (trim space either side of character)
If Not f.packed
f.pX[cur]:+ (f.blockheight - f.cW[cur]) * .5
End If
f.u0[cur] = f.pX[cur] * f.iwM
f.v0[cur] = f.pY[cur] * f.ihM
f.u1[cur] = (f.pX[cur]+f.cW[cur]) * f.iwM
f.v1[cur] = (f.pY[cur]+f.blockHeight) * f.ihM
Next
CloseStream ini
Return f
End Function
Method DrawJustified(s:String, x:Float, y:Float, centered:Byte, spacing:Float, lineBreak:Float, scaleLB:Byte)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY#
Local rot#
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
Local xDrawn:Float = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
If scaleLB Then lineBreak:* scaleX
'Center text horizontally?
Local ln:Float = 0
If centered
x:- cosR * lineBreak * .5
y:- sinR * lineBreak * .5
End If
Local newWord:Int = 0
Local wordLen:Float
Local tw:Int
Local lastLen:Int = 0
Local vSpacing = blockHeight * .8
'Draw each letter in the string...
For i = 0 Until s.length
'Check for whole word, we don't want to break them up
If lastLen <= 0 And s[i]<>32 And lineBreak>0
lastLen = 0
For newWord = i Until s.length
lastLen:+ 1
If s[newWord]=32 Or s[newWord]=13 Exit
Next
wordLen = 0
'Was there a word?
If newWord>0
For tw = i Until newWord
wordLen:+ (cW[s[tw]] + spacing)*scaleX
Next
End If
'Check the length doesn't go over the lineBreak limit
If xDrawn + wordLen > lineBreak
'goto next line
'move back to beginning
x:- cosR * xDrawn
y:- sinR * xDrawn
'move down
x:+ cosP90 * vSpacing * scaleX
y:+ sinP90 * vSpacing * scaleY
lastLen = 0
xDrawn = 0
End If
End If
'Space character?
'blockHeight/3 *seems* to be an ok value for spaces
If s[i] = 32' And xDrawn>2
x:+ cosR * blockHeight*.3 * scaleX
y:+ sinR * blockHeight*.3 * scaleY
xDrawn:+ blockHeight*.3 * scaleX
End If
'Linebreak?
If s[i] = 13
'goto next line
'move back to beginning
x:- cosR * xDrawn
y:- sinR * xDrawn
'move down
x:+ cosP90 * vSpacing * scaleX
y:+ sinP90 * vSpacing * scaleY
lastLen = 0
xDrawn = 0
End If
'If our loaded bitmap font has this character...
If char[s[i]]' And s[i]<>32
curChar = s[i]
lastLen:- 1
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, x+oX, y+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, x+oX, y+oY
End If
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ cosR * (cW[curChar]+spacing) * scaleX
y:+ sinR * (cW[curChar]+spacing) * scaleY
xDrawn:+ (cW[curChar]+spacing) * scaleX
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method Draw(s:String, x:Float, y:Float, centered:Byte = False, spacing:Float = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln = ln*scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, x+oX, y+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, x+oX, y+oY
End If
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ CosR * (cW[curChar]+spacing) * scaleX
y:+ SinR * (cW[curChar]+spacing) * scaleY
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawWave(s$, x#, y#, angle#, angleStep#, mag#, centered:Byte = False, spacing# = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln = ln*scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
Local bx#,by#,bMag#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
bMag = Sin(angle) * mag * scaleY
bx = x - cosP90 * bMag
by = y - sinP90 * bMag
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
End If
angle:+ angleStep
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ CosR * (cW[curChar]+spacing) * scaleX
y:+ SinR * (cW[curChar]+spacing) * scaleY
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawWiggle(s$, x#, y#, angle#, angleStep#, mag#, centered:Byte = False, spacing# = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln = ln*scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
Local bx#,by#,bMag#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
bMag = Sin(angle) * mag * scaleX
bx = x - cosR * bMag
by = y - sinR * bMag
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
End If
angle:+ angleStep
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ CosR * (cW[curChar]+spacing) * scaleX
y:+ SinR * (cW[curChar]+spacing) * scaleY
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawBouncy(s$, x#, y#, angle#, angleStep#, mag#, centered:Byte = False, spacing# = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln = ln*scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
Local bx#,by#,bMag#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
bMag = Abs(Sin(angle)) * mag * scaleY
bx = x - cosP90 * bMag
by = y - sinP90 * bMag
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
End If
angle:+ angleStep
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ CosR * (cW[curChar]+spacing) * scaleX
y:+ SinR * (cW[curChar]+spacing) * scaleY
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawVertical(s:String, x:Float, y:Float, centered:Byte = False, spacing:Float = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
'Look UPs
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90# = Sin(rot+90)
cosP90# = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center the Vertical text so it appears
'nicely centered
'Find widest character
Local bc:Float = 0
For i = 0 Until s.length
If cW[s[i]] > bc Then bc = cW[s[i]]
Next
'build an offset array based of widest char
Local ofs:Float[255]
For i = 0 Until s.length
ofs[s[i]] = (bc - cW[s[i]]) * .5
Next
'ln = bc*scaleX *.5
If centered
x:- cosR*(bc*.5) * scaleX
y:- sinR*(bc*.5) * scaleY
End If
Local spaceX# = cosP90 * (blockHeight+spacing) * scaleX
Local spaceY# = sinP90 * (blockHeight+spacing) * scaleY
Local bx#,by#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight/3 *seems* to be an ok value for spaces
'for Vertical text, move the position down
If s[i] = 32
x:+ spaceX
y:+ spaceY
End If
If char[s[i]] And s[i]<>32
curChar = s[i]
areaW = cW[curChar]
areaH = blockHeight
bx = x
by = y
bx:+ cosR* ofs[curChar] * scaleX
by:+ sinR* ofs[curChar] * scaleY
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, x+oX, y+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
End If
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ spaceX
y:+ spaceY
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawWobble(s$, x#, y#, angle#, angleStep#, mag#, centered:Byte = False, spacing# = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln = ln*scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
Local bx#,by#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
bx = x + Cos(angle) * mag * scaleX
by = y + Sin(angle) * mag * scaleY
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, bx+oX, by+oY
End If
angle:+ angleStep
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ CosR * (cW[curChar]+spacing) * scaleX
y:+ SinR * (cW[curChar]+spacing) * scaleY
End If
Next
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawSineSize(s$, x#, y#, angle#, angleStep#, mag#, centered:Byte = False, spacing# = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln = ln*scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
Local bx#,by#
Local sizeX#,sizeY#
mag:* .01
Local ah#,aw#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
areaW = cW[curChar]' +
areaH = blockHeight' +
aw = areaW + (Sin(angle)*cW[curChar]*mag)
ah = areaH + (Sin(angle)*blockHeight * mag)
bx=x
by=y
bx:+ cosR* (areaW - aw) * .5 * scaleX
by:+ sinR* (areaW - aw) * .5 * scaleX
bx:+ cosP90* (areaH - ah) * .5 * scaleY
by:+ sinP90* (areaH - ah) * .5 * scaleY
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = pX[curChar] * iwM
GLframe.v0 = pY[curChar] * ihM
GLframe.u1 = (pX[curChar]+areaW) * iwM
GLframe.v1 = (pY[curChar]+areaH) * ihM
GLframe.Draw 0, 0, aw, ah, bx+oX, by+oY
Else 'Same as above, but using DX variation
DXframe.setUV(pX[curChar]*iwM, pY[curChar]*ihM, (pX[curChar]+areaW)*iwM, (pY[curChar]+areaH)*ihM)
DXframe.Draw 0, 0, aw, ah, bx+oX, by+oY
End If
angle:+ angleStep
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ CosR * (cW[s[i]]+spacing) * scaleX
y:+ SinR * (cW[s[i]]+spacing) * scaleY
End If
Next
SetScale scaleX,scaleY
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
Method DrawSwing(s$, x#, y#, angle#, angleStep#, mag#, centered:Byte = False, spacing# = 0)
Local i:Int,t:String
Local scaleX#,scaleY#
Local oX#,oY# 'Current Max2D Origin
Local rot# 'Current Max2D Rotation
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curchar:Byte
Local isGL:Byte 'Boolean
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
Local frame:Int = 0
Local hX#,hY#
GetOrigin oX,oY
GetScale scaleX,scaleY
rot = GetRotation()
sinR = Sin(rot)
cosR = Cos(rot)
sinP90 = Sin(rot+90)
cosP90 = Cos(rot+90)
If TGLImageFrame(image.frame(frame))
isGL = True
GLframe = TGLImageFrame(image.frame(frame))
Else
isGL = False
DXframe = TD3D7ImageFrame(image.frame(frame))
End If
'Center text horizontally?
Local ln:Float = 0
If centered
'Get string length
For i = 0 Until s.length
If s[i] = 32
ln:+ blockHeight*.3
Else If char[s[i]]
ln:+ cW[s[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
ln:* scaleX *.5
x:- cosR*ln
y:- sinR*ln
End If
Local spaceValX# = cosR * blockHeight * .3 * scaleX
Local spaceValY# = sinR * blockHeight * .3 * scaleY
Local bx#,by#
'Draw each letter in the string...
For i = 0 Until s.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If s[i] = 32
x:+ spaceValX
y:+ spaceValY
End If
SetRotation rot+Sin(angle)*mag
'If our loaded bitmap font has this character...
If char[s[i]] And s[i]<>32
curChar = s[i]
hX = -cW[curChar]*.5
hY = 0
bx = x - cosR*hX*scaleX '- cosR * bMag
by = y - sinR*hX*scaleY'- sinR * bMag
areaW = cW[curChar]
areaH = blockHeight
'Draw this character
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = u0[curChar]
GLframe.v0 = v0[curChar]
GLframe.u1 = u1[curChar]
GLframe.v1 = v1[curChar]
GLframe.Draw hX, hY, areaW+hX, areaH, bx+oX, by+oY
Else 'Same as above, but using DX variation
DXframe.setUV(u0[curchar], v0[curChar], u1[curChar], v1[curChar])
DXframe.Draw hX, hY, areaW+hX, areaH, bx+oX, by+oY
End If
angle:+ angleStep
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
x:+ cosR * (cW[curChar]+spacing) * scaleX
y:+ sinR * (cW[curChar]+spacing) * scaleY
End If
Next
SetRotation rot
'Restore UVs
If isGL
GLframe.u0 = 0
GLframe.v0 = 0
GLframe.u1 = 1
GLframe.v1 = 1
Else
DXframe.SetUV (0,0,1,1)
End If
End Method
End Type
Type aFonText
Global list:TList
Field link:TLink
Field sX#,sY#
Field sT%
Field aT%
Field dT%
Field rT%
Field str$
Field srcX:Float[],srcY:Float[]
Field dstX:Float[],dstY:Float[]
Field vX:Float[],vY:Float[]
Field f:FonText
Field thisScaleX#,thisScaleY#
Field thisOriginX#,thisOriginY#
Field thisRotation#
Field textCenter#
Field textLength#
Method New()
If Not list Then list = CreateList()
link = ListAddLast(list,Self)
End Method
Method Destroy()
RemoveLink link
End Method
Function Create(text$, ft:FonText, pX#, pY#, start%, attack%,..
duration%, _release%, spacing#, centered:Byte,dir:Int)
Local a:aFonText = New aFonText
Local time% = MilliSecs()
a.str = text
a.f = ft
a.sX = pX
a.sY = pY
a.sT = time + start
a.aT = time + start + attack
a.dT = time + start + attack + duration
a.rT = time + start + attack + duration + _release
a.thisRotation = GetRotation()
GetOrigin a.thisOriginX,a.thisOriginY
GetScale a.thisScaleX,a.thisScaleY
Local sLen% = text.length
a.srcX = New Float[sLen]
a.srcY = New Float[sLen]
a.dstX = New Float[sLen]
a.dstY = New Float[sLen]
a.vX = New Float[sLen]
a.vY = New Float[sLen]
Local i:Int,t:String
Local sinR#,cosR#,sinP90#,cosP90#
Local areaW#,areaH#
Local curChar:Byte
sinR = Sin(a.thisRotation)
cosR = Cos(a.thisRotation)
sinP90 = Sin(a.thisRotation+90)
cosP90 = Cos(a.thisRotation+90)
'Center text horizontally?
Local ln:Float = 0
'If centered
'Get string length
For i = 0 Until text.length
If text[i] = 32
ln:+ a.f.blockHeight*.3
Else If a.f.char[text[i]]
ln:+ a.f.cW[text[i]]+spacing
End If
Next
ln:- spacing 'remove last unwanted space
a.textLength = ln
'ln = ln * a.thisScaleX *.5
ln:* .5
If centered
pX:- cosR*ln * a.thisScaleX
pY:- sinR*ln * a.thisScaleY
End If
Local spaceValX# = cosR * a.f.blockHeight * .3 * a.thisScaleX
Local spaceValY# = sinR * a.f.blockHeight * .3 * a.thisScaleY
'Calc each characters destination, and store it
For i = 0 Until text.length
'Space character?
'blockHeight*.3 *seems* to be an ok value for spaces
If text[i] = 32
pX:+ spaceValX
pY:+ spaceValY
End If
'If our loaded bitmap font has this character...
If a.f.char[text[i]] And text[i]<>32
curChar = text[i]
areaW = a.f.cW[curChar]
areaH = a.f.blockHeight
a.dstX[i] = pX+a.thisOriginX
a.dstY[i] = pY+a.thisOriginY
'Increase position of Next letter... +90 = DOWN, +180 = LEFT, -90 = UP
pX:+ CosR * (a.f.cW[curChar]+spacing) * a.thisScaleX
pY:+ SinR * (a.f.cW[curChar]+spacing) * a.thisScaleY
End If
Next
'setup src & velocity vectors
For i = 0 Until text.length
Select dir
Case 0
Local ix:Int = Int(a.str.length*.5-.5)
If ix < 0 ix = 0
a.srcX[i] = a.dstX[ix]'a.sX + cosR * a.textCenter
a.srcY[i] = a.dstY[ix]'sY + sinR * a.textCenter
Case -1
a.srcX[i] = a.dstX[0]
a.srcY[i] = a.dstY[0]
Case 1
a.srcX[i] = a.dstX[a.str.length-1]
a.srcY[i] = a.dstY[a.str.length-1]
End Select
a.vX[i] = a.srcX[i]-a.dstX[i]
a.vY[i] = a.srcY[i]-a.dstY[i]
Next
End Function
Function Update()
If Not list Then Return
Local time%
Local a:aFonText
Local oldRot#,oldScaleX#,oldScaleY#,oldOriginX#,oldOriginY#
Local oldAlpha# = GetAlpha()
Local oldBlend% = GetBlend()
oldRot = GetRotation()
GetScale oldScaleX,oldScaleY
GetOrigin oldOriginX,oldOriginY
Local i:Int
Local isGL:Byte
Local tx#,ty#,areaw#,areah#
Local curChar:Byte
Local GLframe:TGLImageFrame
Local DXframe:TD3D7ImageFrame
SetBlend ALPHABLEND
For a = EachIn aFonText.list
SetRotation a.thisRotation
SetScale a.thisScaleX,a.thisScaleY
SetOrigin a.thisOriginX,a.thisOriginY
If TGLImageFrame(a.f.image.frame(0))
isGL = True
GLframe = TGLImageFrame(a.f.image.frame(0))
Else
isGL = False
DXframe = TD3D7ImageFrame(a.f.image.frame(0))
End If
If time > a.rT
a.Destroy()
a = Null
End If
time = MilliSecs()
If a And time >= a.sT And time <= a.rT
Local elap#
Local al#
For i = 0 Until a.str.length
If time >= a.sT And time < a.aT
elap = (Float((time - a.sT)) / (a.aT-a.sT))
al = elap
elap = 1.0 - elap
elap = 1.0 - Cos(elap*90)
tx = a.dstX[i] + a.vX[i]*elap
tY = a.dstY[i] + a.vY[i]*elap'srcY[i]*elap'dstY[i] - a.srcY[i]*elap '+ a.vY[i]*elap
SetAlpha 1.0 - elap
'DrawText "Attack",0,0
Else If time >=a.aT And time <= a.dT
SetAlpha 1
'pause
tx = a.dstX[i]
ty = a.dstY[i]
'DrawText "Duration",0,0
Else If time > a.dT And time <= a.rT
tx = a.dstX[i]
ty = a.dstY[i]' + (Abs(time - a.dT) * .05)
elap = 1.0 - (Float(time - a.dT)) / (a.rT-a.dT)
SetAlpha elap
'DrawText "Release",0,0
End If
curChar = a.str[i]
areaW = a.f.cW[curChar]
areaH = a.f.blockHeight
If isGL
'Point UVs to character in FonText Bitmap..
GLframe.u0 = a.f.u0[curChar]
GLframe.v0 = a.f.v0[curChar]
GLframe.u1 = a.f.u1[curChar]
GLframe.v1 = a.f.v1[curChar]
GLframe.Draw 0, 0, areaW, areaH, tx, ty
Else 'Same as above, but using DX variation
DXframe.setUV(a.f.u0[curchar], a.f.v0[curChar], a.f.u1[curChar], a.f.v1[curChar])
DXframe.Draw 0, 0, areaW, areaH, tx, ty
End If
Next
End If
Next
SetBlend oldBlend
SetAlpha oldAlpha
SetRotation oldRot
SetScale oldScaleX,oldScaleY
SetOrigin oldOriginX,oldOriginY
End Function
End Type