diff options
author | Ian C <ianc@noddybox.co.uk> | 2005-03-01 02:11:23 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2005-03-01 02:11:23 +0000 |
commit | fc104cc767aad70273635c79a0b99b279eb9322f (patch) | |
tree | 1af95fab3723b36e50989519463498215f6a0f5b | |
parent | 75c03c360d6a3c06e214d33a7c6ac1233e4b0303 (diff) |
Updates
-rw-r--r-- | imagefont/.cvsignore | 3 | ||||
-rw-r--r-- | imagefont/bmaxtest.bmi | bin | 0 -> 22012 bytes | |||
-rw-r--r-- | imagefont/bmaxtest.fdd | bin | 0 -> 5696 bytes | |||
-rw-r--r-- | imagefont/imagefont.bmx | 107 | ||||
-rw-r--r-- | imagefont/test.bmx | 92 |
5 files changed, 196 insertions, 6 deletions
diff --git a/imagefont/.cvsignore b/imagefont/.cvsignore new file mode 100644 index 0000000..0ac3fba --- /dev/null +++ b/imagefont/.cvsignore @@ -0,0 +1,3 @@ +.bmx +test.exe +test.debug.exe
\ No newline at end of file diff --git a/imagefont/bmaxtest.bmi b/imagefont/bmaxtest.bmi Binary files differnew file mode 100644 index 0000000..1c980a0 --- /dev/null +++ b/imagefont/bmaxtest.bmi diff --git a/imagefont/bmaxtest.fdd b/imagefont/bmaxtest.fdd Binary files differnew file mode 100644 index 0000000..7edb1e3 --- /dev/null +++ b/imagefont/bmaxtest.fdd diff --git a/imagefont/imagefont.bmx b/imagefont/imagefont.bmx index 1208cee..28d4595 100644 --- a/imagefont/imagefont.bmx +++ b/imagefont/imagefont.bmx @@ -1,13 +1,108 @@ -Module Noddybox.ImageFont +'Module noddybox.imagefont -ModuleInfo "Framework: Simple Bitmap Font Routines" -ModuleInfo "Copyright: Ian Cowburn" -ModuleInfo "Author: Ian Cowburn" -ModuleInfo "License: Ian Cowburn" -ModuleInfo "Version: $Revision$" +'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 04930e6..b1da6df 100644 --- a/imagefont/test.bmx +++ b/imagefont/test.bmx @@ -1,5 +1,97 @@ ' $Id$ Import "imagefont.bmx" +Incbin "bmaxtest.bmi" Graphics 800,600,32,60 + +fnt:ImageFont=ImageFont.Load("incbin::bmaxtest.bmi") + +c=0 +ci=5 + +Type Star + Field x + Field y,sp + + Function Create:Star() + Local s:Star=New Star + s.x=Rand(0,800) + s.y=Rand(0,600) + s.sp=Rand(1,3) + Return s + End Function + + Method Update() + Plot(x,y) + y:+sp + y:Mod 600 + End Method +End Type + +Const NO=10000 + +Local st:Star[]=New Star[NO] + +For f=0 Until NO + st[f]=Star.Create() +Next + +While Not KeyHit(KEY_ESCAPE) + Cls + + For f=0 Until NO + st[f].Update() + Next + + 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 + + DrawText(MemAlloced(),0,100) + + If KeyHit(KEY_SPACE) Then FlushMem + + Flip + +Wend + +SetTransform(0,1,1) + +ch=33 + +While Not KeyHit(KEY_ESCAPE) + Cls + + For f=0 Until NO + 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 + + DrawText(MemAlloced(),0,100) + + FlushMem + + Flip + +Wend |