summaryrefslogtreecommitdiff
path: root/imagefont
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-05-13 23:01:39 +0000
committerIan C <ianc@noddybox.co.uk>2005-05-13 23:01:39 +0000
commitc9259028beb11a9a838bb0d0fb0f076406986beb (patch)
treeb5c563af27dba5f88abbe359ae558b4052d4f25c /imagefont
parentfc104cc767aad70273635c79a0b99b279eb9322f (diff)
Removed module implementation to a seperate project
Diffstat (limited to 'imagefont')
-rw-r--r--imagefont/imagefont.bmx108
-rw-r--r--imagefont/test.bmx76
2 files changed, 42 insertions, 142 deletions
diff --git a/imagefont/imagefont.bmx b/imagefont/imagefont.bmx
deleted file mode 100644
index 28d4595..0000000
--- a/imagefont/imagefont.bmx
+++ /dev/null
@@ -1,108 +0,0 @@
-'Module noddybox.imagefont
-
-'ModuleInfo "Framework: Simple Bitmap Font Routines"
-'ModuleInfo "Copyright: Public Domain"
-'ModuleInfo "Author: Ian Cowburn"
-'ModuleInfo "Version: $Revision$"
-
-' $Id$
-
-Type ImageFont
-
- Const NOCHR=96
-
- Field img:TImage[NOCHR]
- Field height:Int[NOCHR]
- Field width:Int[NOCHR]
- Field is_fixed:Int
-
- Function Load:ImageFont(path:String)
- Local fnt:ImageFont
- Local str:TStream
- Local f,x,y
- Local r,g,b
-
- str=ReadStream(path)
-
- If (Not str) Then Return Null
-
- fnt=New ImageFont
-
- fnt.is_fixed=Readint(str)
-
- GetMaskColor(r,g,b)
- SetMaskColor(0,0,0)
-
- For f=0 Until NOCHR
- fnt.width[f]=Readint(str)
- fnt.height[f]=Readint(str)
-
- DebugLog("CHR " + f + " " + fnt.width[f] + "x" + fnt.height[f])
-
- fnt.img[f]=CreateImage(fnt.width[f],fnt.height[f],1,MASKEDIMAGE)'FILTEREDIMAGE|MASKEDIMAGE)
-
- Local pm:TPixmap=LockImage(fnt.img[f])
-
- For x=0 Until fnt.width[f]
- For y=0 Until fnt.height[f]
- WritePixel(pm,x,y,Readint(str))
- Next
- Next
-
- UnlockImage(fnt.img[f])
- Next
-
- SetMaskColor(r,g,b)
-
- CloseStream(str)
-
- Return fnt
- End Function
-
- Method DrawColoured(txt:String, x:Int, y:Int, red:Int, green:Int, blue:Int)
- Local f,r,g,b,c
- Local xs#,ys#
-
- GetScale(xs,ys)
-
- GetColor(r,g,b)
- SetColor(red,green,blue)
-
- For f=1 To Len(txt)
- c=Asc(Mid$(txt,f,1))-32
- DrawImage(img[c],x,y)
- x:+width[c]*xs
- Next
-
- SetColor(r,g,b)
- End Method
-
- Method Draw(txt:String, x:Int, y:Int)
- DrawColoured(txt,x,y,255,255,255)
- End Method
-
- Method CentreColoured(txt:String, y:Int, red:Int, green:Int, blue:Int)
- If is_fixed
- DrawColoured(txt,GraphicsWidth()/2-Len(txt)*width[0]/2,y,red,green,blue)
- Else
- DrawColoured(txt,GraphicsWidth()/2-TextWidth(txt)/2,y,red,green,blue)
- EndIf
- End Method
-
- Method Centre(txt:String, y:Int)
- If is_fixed
- DrawColoured(txt,GraphicsWidth()/2-Len(txt)*width[0]/2,y,255,255,255)
- Else
- DrawColoured(txt,GraphicsWidth()/2-TextWidth(txt)/2,y,255,255,255)
- EndIf
- End Method
-
- Method TextWidth:Int(txt:String)
- Local w
- For Local f=1 To Len(txt)
- w:+width[Asc(Mid$(txt,f,1))]
- Next
- Return w
- End Method
-
-End Type
diff --git a/imagefont/test.bmx b/imagefont/test.bmx
index b1da6df..0f38d29 100644
--- a/imagefont/test.bmx
+++ b/imagefont/test.bmx
@@ -1,14 +1,19 @@
' $Id$
-Import "imagefont.bmx"
+Import noddybox.bitmapfont
+
+'Import "BitmapFont.bmx"
Incbin "bmaxtest.bmi"
-Graphics 800,600,32,60
+Const SCRW=640
+Const SCRH=480
+
+Graphics SCRW,SCRH,32,60
-fnt:ImageFont=ImageFont.Load("incbin::bmaxtest.bmi")
+fnt:BitmapFont=BitmapFont.Load("incbin::bmaxtest.bmi")
-c=0
-ci=5
+c=255
+ci=-5
Type Star
Field x
@@ -16,8 +21,8 @@ Type Star
Function Create:Star()
Local s:Star=New Star
- s.x=Rand(0,800)
- s.y=Rand(0,600)
+ s.x=Rand(0,SCRW)
+ s.y=Rand(0,SCRH)
s.sp=Rand(1,3)
Return s
End Function
@@ -25,7 +30,7 @@ Type Star
Method Update()
Plot(x,y)
y:+sp
- y:Mod 600
+ y:Mod SCRH
End Method
End Type
@@ -37,7 +42,7 @@ For f=0 Until NO
st[f]=Star.Create()
Next
-While Not KeyHit(KEY_ESCAPE)
+While False ' Not KeyHit(KEY_ESCAPE)
Cls
For f=0 Until NO
@@ -46,13 +51,15 @@ While Not KeyHit(KEY_ESCAPE)
SetTransform(0,2,2)
fnt.DrawColoured("DRAWCOLOURED",0,10,c/2,c/2,c)
- fnt.Draw("DRAW",0,20)
- fnt.CentreColoured("CENTRECOLOURED",30,c/2,c/2,c)
- fnt.Centre("CENTRE",40)
-
- c:+ci
-
- If (c=0 Or c=255) ci=-ci
+ fnt.Draw("DRAW",c-120,30)
+ fnt.CentreColoured("CENTRECOLOURED",50,c/2,c/2,c)
+ fnt.Centre("CENTRE",70)
+
+ If Not KeyDown(KEY_P)
+ c:+ci
+
+ If (c=100 Or c=255) ci=-ci
+ EndIf
DrawText(MemAlloced(),0,100)
@@ -62,9 +69,9 @@ While Not KeyHit(KEY_ESCAPE)
Wend
-SetTransform(0,1,1)
-
-ch=33
+sc=10
+t$="THIS IS SOME VERY, VERY, *VERY* LARGE SCROLLING TEXT....."
+x#=0
While Not KeyHit(KEY_ESCAPE)
Cls
@@ -73,23 +80,24 @@ While Not KeyHit(KEY_ESCAPE)
st[f].Update()
Next
- a$=Chr$(ch)
-
- ch:+1
- If ch>Asc("Z") Then ch=33
-
- For x=0 To 800 Step 8
- For y=0 To 600 Step 8
- fnt.DrawColoured(a$,x,y,c,c,c)
- Next
- Next
-
- c:+ci
-
- If (c=0 Or c=255) ci=-ci
+ SetTransform(0,1,1)
+
+ DrawText("x="+x+" width="+(-fnt.TextWidth(t[0..1]))+" mem="+MemAlloced(),0,100)
+ DrawText("t="+t,0,110)
- DrawText(MemAlloced(),0,100)
+ SetTransform(0,sc,sc)
+
+ fnt.Draw(t$,x,200)
+ If Not KeyDown(KEY_P)
+ x:-sc
+
+ If x<-fnt.TextWidth(t[0..1])
+ x:+fnt.TextWidth(t[0..1])
+ t=t[1..]+t[0..1]
+ EndIf
+ EndIf
+
FlushMem
Flip