scale font

Previous topic - Next topic

42stones

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 :)

spacefractal

Glbasic don't scaling font, you need to write your own font rutine using poly vector.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

42stones

Is there a tutorial for that?

Moru

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? :-)

MrTAToad

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

fuzzy70

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
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

fuzzy70

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
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

MrTAToad

Dont remember seeing that in the in-program helpfile!

Paul Smith

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?

Amstrad CPC 6128, ATARI STE.
Acer  SW5-173 & AMD RYZEN 7,RTX 3060TI

fuzzy70

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
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

erico

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.


fuzzy70

#11
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
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

erico

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.

fuzzy70

Getting a bit  :offtopic: here lol, the MOD failed. Will post future findings after update check on the other post.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

spacefractal

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).
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/