summaryrefslogtreecommitdiff
path: root/bitmapfont.mod
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-05-13 23:02:16 +0000
committerIan C <ianc@noddybox.co.uk>2005-05-13 23:02:16 +0000
commit2e2bc7939e2986814667e40ffe814e394c46beaf (patch)
tree057c25f5855e71df116c696a5a795f7453f0b313 /bitmapfont.mod
parentb17db91bd18d0e0a9a15cc041276dbf2d20f394d (diff)
Initial modulised version of BitmapFont
Diffstat (limited to 'bitmapfont.mod')
-rw-r--r--bitmapfont.mod/.cvsignore3
-rw-r--r--bitmapfont.mod/bitmapfont.bmx115
2 files changed, 118 insertions, 0 deletions
diff --git a/bitmapfont.mod/.cvsignore b/bitmapfont.mod/.cvsignore
new file mode 100644
index 0000000..00f8c35
--- /dev/null
+++ b/bitmapfont.mod/.cvsignore
@@ -0,0 +1,3 @@
+.bmx
+bitmapfont.debug.win32.i
+bitmapfont.release.win32.i \ No newline at end of file
diff --git a/bitmapfont.mod/bitmapfont.bmx b/bitmapfont.mod/bitmapfont.bmx
new file mode 100644
index 0000000..86c29f8
--- /dev/null
+++ b/bitmapfont.mod/bitmapfont.bmx
@@ -0,0 +1,115 @@
+Module noddybox.bitmapfont
+
+ModuleInfo "Framework: Simple Bitmap Font Routines"
+ModuleInfo "Copyright: Public Domain"
+ModuleInfo "Author: Ian Cowburn"
+ModuleInfo "Version: $Revision$"
+
+' $Id$
+
+Import brl.Max2D
+Import brl.Basic
+
+Strict
+
+Type BitmapFont
+
+ Const NOCHR=96
+
+ Field img:TImage[NOCHR]
+ Field height:Int[NOCHR]
+ Field width:Int[NOCHR]
+ Field is_fixed:Int
+
+ Function Load:BitmapFont(path:String)
+ Local fnt:BitmapFont
+ Local str:TStream
+ Local f,x,y
+ Local r,g,b
+
+ str=ReadStream(path)
+
+ If (Not str) Then Return Null
+
+ fnt=New BitmapFont
+
+ 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)
+
+ 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=0 Until Len(txt)
+ c=txt[f]-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
+ Local xs#,ys#
+
+ GetScale(xs,ys)
+
+ For Local f=0 Until Len(txt)
+ w:+width[txt[f]-32]*xs
+ Next
+ Return w
+ End Method
+
+End Type