GLBasic forum

Main forum => GLBasic - en => Topic started by: 42stones on 2014-Aug-08

Title: scale font
Post by: 42stones on 2014-Aug-08
Hello everybody,

I tried to display my highscore relative to the screen size of my game by using the optional scalfactor after the font id in SETFONT, but then I get the error "gbas\game.gbas"(93) error : wrong number of aguments : "SETFONT" called with 2 args. Required: 1 to 1.

I wrote it like this: SETFONT 1,2

Does this scale factor command even exist or was it my fault?

It would make me very happy if you can help me :)
Title: Re: scale font
Post by: spacefractal on 2014-Aug-08
Glbasic don't scaling font, you need to write your own font rutine using poly vector.
Title: Re: scale font
Post by: 42stones on 2014-Aug-08
Is there a tutorial for that?
Title: Re: scale font
Post by: Moru on 2014-Aug-08
Yes, there are a number of them in the 2D-snippets forum.

In the latest online help there is a scale parameter to the SETFONT command so mabe there will be something like that in the next version of GLBasic? :-)
Title: Re: scale font
Post by: MrTAToad on 2014-Aug-08
This is my proportional font routine :

Code (glbasic) Select
// --------------------------------- //
// Project: TestProFont
// Start: Friday, February 07, 2014
// IDE Version: 12.001


TYPE tChar
character%
x%
y%
width%
height%
ENDTYPE

TYPE TProFont
id%
chars[] AS tChar
charSpacing%
lineSpacing%
xScale
yScale
italic%

colour%[]
shadow%[]
shadowActive%
shadowSpacing%

sChar%;endChar%;numLoaded%
bWidthIndex%
bHeightIndex%

FUNCTION Initialise%:
DIM self.colour%[4]
DIM self.shadow%[4]

self.Clear()

self.SetColour(RGB(255,255,255),RGB(255,255,255),RGB(255,255,255),RGB(255,255,255))
self.SetShadow(RGB(127,127,127),RGB(127,127,127),RGB(127,127,127),RGB(127,127,127))

self.SetCharSpacing(2)
self.SetLineSpacing(2)
self.SetXScale(1)
self.SetYScale(1)
self.SetItalic(0)
self.UseShadow(FALSE)
self.SetShadowSpacing(4)

RETURN TRUE
ENDFUNCTION

FUNCTION SetCharSpacing%:s%
self.charSpacing%=s%
ENDFUNCTION

FUNCTION GetCharSpacing%:
RETURN self.charSpacing%
ENDFUNCTION

FUNCTION SetLineSpacing%:l%
self.lineSpacing%=l%
ENDFUNCTION

FUNCTION GetLineSpacing%:
RETURN self.lineSpacing%
ENDFUNCTION

FUNCTION SetXScale%:s
self.xScale=s
ENDFUNCTION

FUNCTION GetXScale:
RETURN self.xScale
ENDFUNCTION

FUNCTION SetYScale%:s
self.yScale=s
ENDFUNCTION

FUNCTION GetYScale:
RETURN self.yScale
ENDFUNCTION

FUNCTION UseShadow%:s%
self.shadowActive%=s%
ENDFUNCTION

FUNCTION IsShadow%:
RETURN self.shadowActive%
ENDFUNCTION

FUNCTION SetShadowSpacing%:d%
self.shadowSpacing%=d%
ENDFUNCTION

FUNCTION GetShadowSpacing%:
RETURN self.shadowSpacing%
ENDFUNCTION

FUNCTION SetShadow%:tl%,tr%,bl%,br%
self.shadow%[0]=tl%
self.shadow%[2]=bl%
self.shadow%[1]=tr%
self.shadow%[3]=br%
ENDFUNCTION

FUNCTION SetColour%:tl%,tr%,bl%,br%
self.colour%[0]=tl%
self.colour%[2]=bl%
self.colour%[1]=tr%
self.colour%[3]=br%
ENDFUNCTION

FUNCTION GetTLColour%:offset%
IF offset%<>0
RETURN self.shadow%[0]
ELSE
RETURN self.colour%[0]
ENDIF
ENDFUNCTION

FUNCTION GetBLColour%:offset%
IF offset%<>0
RETURN self.shadow%[2]
ELSE
RETURN self.colour%[2]
ENDIF
ENDFUNCTION

FUNCTION GetTRColour%:offset%
IF offset%<>0
RETURN self.shadow%[1]
ELSE
RETURN self.colour%[1]
ENDIF
ENDFUNCTION

FUNCTION GetBRColour%:offset%
IF offset%<>0
RETURN self.shadow%[3]
ELSE
RETURN self.colour%[3]
ENDIF
ENDFUNCTION

FUNCTION SetItalic%:i%
self.italic%=i%
ENDFUNCTION

FUNCTION GetItalic%:
RETURN self.italic%
ENDFUNCTION

FUNCTION Clear%:
LOCAL loop%

DIM self.chars[0]

self.id%=-1
self.numLoaded%=-1
self.bWidthIndex%=-1
self.bHeightIndex%=-1
ENDFUNCTION

FUNCTION Load%:controlFile$,graphicPath$=""
LOCAL handle%,loop%,count%,index%,gFile$,error%
LOCAL line$
LOCAL sep$[]
LOCAL chr AS tChar

IF DOESFILEEXIST(controlFile$)
handle%=GENFILE()
IF handle%<0
RETURN FALSE
ELSE
IF OPENFILE(handle%,controlFile$,1)
WHILE ENDOFFILE(handle%)=FALSE
READLINE handle%,line$
IF line$<>"" AND LEFT$(line$,1)<>";"
DIM sep$[0]
count%=SPLITSTR(line$,sep$[],",")
DEBUG "Line : "+line$+"\n"
KEYWAIT
error%=FALSE
IF count%>0
SELECT INTEGER(sep$[0])
CASE 1 // Graphic filename

IF count%>=2
gFile$=graphicPath$+"/"+sep$[1]
DEBUG "gFile$:"+gFile$+"\n"
IF DOESFILEEXIST(gFile$)
self.id%=GENFILE()
IF self.id%<0
error%=TRUE
ELSE
LOADSPRITE gFile$,self.id%
GETSPRITESIZE self.id%,self.bWidthIndex%,self.bHeightIndex%
IF self.bWidthIndex%<=0 OR self.bHeightIndex%<=0
error%=TRUE
ENDIF
ENDIF
ENDIF
ELSE
error%=TRUE
ENDIF



CASE 2 // Starting, ending (and number of characters)
IF count%>=4
self.sChar%=INTEGER(sep$[1])
self.endChar%=INTEGER(sep$[2])
self.numLoaded%=INTEGER(sep$[3])
ELSE
error%=TRUE
ENDIF

CASE 3 // Actual characters
IF self.numLoaded%>0 AND count%>=6
chr.character%=INTEGER(sep$[1])
IF chr.character%>=0 AND chr.character%<=65535
chr.x%=INTEGER(sep$[2])
chr.y%=INTEGER(sep$[3])
chr.width%=INTEGER(sep$[4])
chr.height%=INTEGER(sep$[5])
DIMPUSH self.chars[],chr
ELSE
error%=TRUE
ENDIF
ENDIF
ENDSELECT

IF error%
CLOSEFILE handle%
RETURN FALSE
ENDIF

ENDIF
ENDIF
WEND

CLOSEFILE handle%
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDIF
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION

FUNCTION DrawChar%:one%,x%,y%,BYREF height%
LOCAL sizeX,sizeY

DEC one%,self.sChar%
IF one%<0 OR one%>=BOUNDS(self.chars[],0) THEN RETURN 0

height%=0

sizeX=self.chars[one%].width%*GetXScale()
sizeY=MAX(0.0,self.chars[one%].height%*GetYScale())
IF sizeX<=0.0 OR sizeY<=0.0 THEN RETURN 0

IF self.IsShadow()
self._draw%(x%,y%,GetItalic(),GetXScale(),GetYScale(),self.chars[one%].x%,self.chars[one%].y%,self.chars[one%].width%,self.chars[one%].height%,self.GetShadowSpacing())
ENDIF

self._draw%(x%,y%,GetItalic(),GetXScale(),GetYScale(),self.chars[one%].x%,self.chars[one%].y%,self.chars[one%].width%,self.chars[one%].height%)

height%=INTEGER(sizeY)

RETURN INTEGER(sizeX+self.GetCharSpacing())
ENDFUNCTION

FUNCTION _draw%:x%,y%,italic%,xScale,yScale,tx%,ty%,width%,height%,offset%=0
POLYVECTOR  x%+((italic%+offset%)*xScale),  y%+(offset%*yScale),  tx%,  ty%, self.GetTLColour(offset%)
POLYVECTOR  x%+(offset%*xScale), y%+((height%+offset%)*yScale), tx%, ty%+height%, self.GetBLColour(offset%)
POLYVECTOR x%+((width%+offset%+italic%)*xScale), y%+(offset%*yScale), tx%+width%, ty, self.GetTRColour(offset%)
POLYVECTOR x%+((width%+offset%)*xScale), y%+((height%+offset%)*yScale), tx%+width%, ty%+height%, self.GetBRColour(offset%)
POLYNEWSTRIP
ENDFUNCTION

FUNCTION DrawText%:text$,x%,y%
LOCAL loop%,add%,nline%,one%,height%

nline%=0
STARTPOLY self.id%,2
FOR loop%=0 TO LEN(text$)-1
one%=ASC(MID$(text$,loop%,1))
INC x%,DrawChar(one%,x%,y%,height%)
nline%=MAX(nline%,height%)
NEXT
ENDPOLY

RETURN nline%+GetLineSpacing()
ENDFUNCTION

FUNCTION DrawMultiLine%:text$,x%,y%
LOCAL split$[]
LOCAL loop$

DIM split$[0]
SPLITSTR(text$,split$[],",")
FOREACH loop$ IN split$[]
INC y%,DrawText(loop$,x%,y%)
NEXT

ENDFUNCTION

ENDTYPE

GLOBAL  proFont AS TProFont
GLOBAL scale=1.0

proFont.Initialise()

SETTRANSPARENCY RGB(0,0,0)
ALPHAMODE -1.0
DEBUG "Result : "+proFont.Load("Media/moo.txt","Media")

SETLOOPSUB "main"

SUB main:
SMOOTHSHADING FALSE
proFont.UseShadow(TRUE)
proFont.SetColour(RGB(127,127,255),RGB(127,127,255),RGB(255,255,255),RGB(255,255,255))
proFont.SetXScale(1)
proFont.SetYScale(1)
proFont.DrawMultiLine("This is a set,of multiple lines,rendered IN one go",0,0)

// proFont.UseShadow(FALSE)
// proFont.SetColour(RGB(127,127,255),RGB(127,127,255),RGB(127,255,0),RGB(127,255,0))
// proFont.SetXScale(scale)
// proFont.SetYScale(scale)

// proFont.DrawText("Testing",100,100)
SHOWSCREEN

INC scale,0.01
ENDSUB


You would need to use my modified font creation program here (http://www.triority.uk/visualstudio.html) to create the bitmap font and a file with all the required coordinates
Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-08
Quote from: spacefractal on 2014-Aug-08
Glbasic don't scaling font, you need to write your own font rutine using poly vector.
SETFONT 1,2 does indeed work & you can scale fonts with it. However you must be running GLB 12.243 which I believe is only downloadable from the main GLB page at the time of writing this.

Lee
Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-08
Testing code used
Code (glbasic) Select
LOCAL scale#=1,fsx#,fsy#,ypos%,loop#

SETCURRENTDIR("Media") // go to media files
LOADFONT "Testfont.png", 1
GETFONTSIZE fsx,fsy

FOR loop = 1 TO 3

SETFONT 1,scale
PRINT "Testing scale *"+scale#,0,ypos

INC scale#,0.5
INC ypos,scale*fsy

NEXT

SHOWSCREEN

KEYWAIT


Output & screenshot attached

Lee
Title: Re: scale font
Post by: MrTAToad on 2014-Aug-08
Dont remember seeing that in the in-program helpfile!
Title: Re: scale font
Post by: Paul Smith on 2014-Aug-08
What I'm running v12.096, didnt even know a new version was out.just downloading the GLBasic from the main page, hope its the latest version.

I use createscreen and stretchsprite for my Text, MrTAToad  code looks a bit to much and I dont like using code i dont fully understand.

Maybe its time for Gernot to let someone update the Website and let people know about updates/new commands. In a couple of days I found the mod/xm/it player in android and now a font size.what next?

Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-08
Quote from: MrTAToad on 2014-Aug-08
Dont remember seeing that in the in-program helpfile!
It's not, it shows on the status bar at the bottom of the screen & the online help. I only discovered it from the update log.

Quote from: Paul Smith on 2014-Aug-08
In a couple of days I found the mod/xm/it player in android and now a font size.what next?
There are no guarantees that them file formats will work on all Android devices (or all platforms). It's mostly down to what Audio/Video codecs are installed on a device and/or platform & in the case of Android the manufacturer decides what to include with the  WAV/MP3/OGG or whatever Google lists as default standard.

Lee
Title: Re: scale font
Post by: erico on 2014-Aug-08
What? let´s not spoil the fun of hunt and share new features! :P

Fuzzy, are you sure about the mod/xm/it on all androids?
I read in another thread that it is done by something inside GLBasic.
I also did a test project with an apk here:
http://www.glbasic.com/forum/index.php?topic=9933.15

Maybe if people give that a spin we can check how it fares on the many androids.

Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-08
Both files from your link played on my main phone (Xperia Z), however only one played on my old backup phone (a HTC Wildfire) which is Cyanogen modded. I will look into the HTC as only reason it's modded was to update the Android version to the minimum GLB requires & a more stable version may be available as was done a very long time ago.

I think there was a post ages ago about .MOD etc issues but can't recall if it was Android related or not.

I like to keep older gear around purely for testing purposes & for general toying around since they are well out of warranty  :D

Lee
Title: Re: scale font
Post by: erico on 2014-Aug-08
Which file didn´t play on the older android?
Here I´m in hopes that the .it runs everywhere.

I wonder if the likes of ouyah or gamestick supports that too.
Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-08
Getting a bit  :offtopic: here lol, the MOD failed. Will post future findings after update check on the other post.

Lee
Title: Re: scale font
Post by: spacefractal on 2014-Aug-08
mod/xm/it player is just included a software player for Android, which uses the SLDMixer. So its software mixer based, and not hardware based. So its property only works on Android, but would been nice to see players on other Systems as well.

But if you uses Soundpool/MediaPlayer from Android Extras, then its property not work, which is more based on the codec installed on the device, but its decode a much faster throught....

Also im was not aware there is now a scaling for the font, but that property due im created my little own long time ago and hence newer used it. But that is a nice thing addidation really for the font. Now we just missing color them now without slowdown (on iOS, color POLYVECTOR slow down like hell).
Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-08
Font scaling only appeared in the latest GLB v12.243, an update that most people are unaware of & one if I remember is not picked up by the update tool in GLB 12.096.

Lee
Title: Re: scale font
Post by: MrTAToad on 2014-Aug-09
Yes, 12.096 doesn't detect it for some reason.  Looks like Gernot hasn't officially released it
Title: Re: scale font
Post by: fuzzy70 on 2014-Aug-09
Quote from: MrTAToad on 2014-Aug-09
Yes, 12.096 doesn't detect it for some reason.  Looks like Gernot hasn't officially released it
Seems odd why the online help is updated for that command & latest version is what is downloaded from the main site. Basically anyone new to GLB will have a version newer than others already using GLB.

Lee
Title: Re: scale font
Post by: spacefractal on 2014-Aug-09
Im just got the txt format https://71squared.com/en/glyphdesigner using, which was a pretty simply format to support and dosent require very much work. Its seen its a excellent commercial software to create those bitmap font. Howover its Mac only. But only have tried the example project file to been tested with throught.
Title: Re: scale font
Post by: Paul Smith on 2014-Aug-10
The Android Loading screen now has bigger animated squares since I installed GLBasic 12.243, more likely due to the font scale.

Still would be nice to change the Text or Icons as Spicypixel requested in topic http://www.glbasic.com/forum/index.php?topic=9602.0
Title: Re: scale font
Post by: spacefractal on 2014-Aug-10
That loading screen is completly skipped in android extras, which is why you need those assest check thing or use the Z alternative of the loading commands.

In next version I'm will property add a option to strings.xml, if you don't want to skip that screen...
Title: Re: scale font
Post by: Paul Smith on 2014-Aug-10
not installed Android extras yet, not even read what the functions do.
Title: Re: scale font
Post by: spacefractal on 2014-Aug-10
you dont need all features AE supports. The most basic is its would fix the screen orientation, and its will rotate automatic to the other side, if you turns the device, and the annoying loading screen would been skipped. Rest is not required for using AE.

Im do later next week purchase the font editor, which seens very good bitmap font software, despite its a Mac only software. Im will property release the source in the code snippets later. But its cool glbasic now support scaling. Howover im would want to see it to support real TrueType support.