BASIC

Author Topic: _PRINT A clean scalable print type  (Read 2513 times)

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
_PRINT A clean scalable print type
« on: 2013-Jan-08 »
This little project was inspired when I discovered that the print does not zoom very well. This solution uses a large font file, and allows you to zoom it smaller for different sizes.

The left alignment needs a little work, but I'll leave that to the experts to play with. Note that this does not use the built in PRINT command, but duplicates what it does.

Code: GLBasic [Select]
TYPE _PRINTX
        chr []
        fontID
        base
        border = 2   //font border if used
        fw = 64 + self.border    //font width
        fh = 72 + self.border    //font height
        count = 15

        FUNCTION Init: font$
                LOCAL i, j, c=-1, x,y
                self.fontID = RND(1000)+1000
                self.base = RND(10000)+2000
                LOADSPRITE font$, self.fontID
                FOR j = 0 TO 15  //change this to 31 to include high ascii values
                        FOR i = 0 TO 15
                                c = c + 1
                                x = i * self.fw
                                y = j * self.fh
                                CLEARSCREEN
                                DRAWSPRITE self.fontID, -x,-y
                                GRABSPRITE self.base + c, 0,0, self.fw, self.fh  
                                DIMPUSH self.chr[], self.base + c
                        NEXT
                NEXT
                CLEARSCREEN
        ENDFUNCTION


        FUNCTION _print: text$, x, y, scale#
                LOCAL i,c, s$
                FOR i = 0 TO LEN(text$)-1
                        s$ = MID$(text$,i,1)
                        c = ASC(s$)
                        ZOOMSPRITE self.chr[c], x + (i * self.fw *scale#), y, scale#, scale#
                NEXT
        ENDFUNCTION

ENDTYPE



LOCAL font1 AS _PRINTX   //define your own font object

font1.Init("arial72.png")  //initialize the font here

font1._print ("AbCdEfG 123", 0, 0, 0.2)  
font1._print ("Hello world", 0, 20, 0.2)
font1._print ("!@#$%^&*()_+", 0, 40, 0.3)
font1._print ("Is it a bird, is it a plane? No it's Super-GLBasic", 0 ,60, 0.18)
font1._print ("Eat your food to grow", 0, 80, 0.4)
font1._print ("even bigger", 0, 110, 0.6)
font1._print ("and bigger", 0, 140, 0.8)
font1._print ("Yum !", 30, 200, 1.5)
font1._print ("...oooOOOoooooo...", 20, 300, 0.5)

SHOWSCREEN
MOUSEWAIT
 

[attachment deleted by admin]
« Last Edit: 2013-Jan-08 by backspace »
I came, I saw, I coded.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3357
  • Integrated Brain
    • View Profile
Re: _PRINT A clean scalable print type
« Reply #1 on: 2013-Jan-08 »
Thanks very interesting... and usefully...

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: _PRINT A clean scalable print type
« Reply #2 on: 2013-Jan-08 »
Nice work, but a few thoughts:
-normally i like to have everything inside a type, but here it makes things to long, the print command should ge a function outside of the type.
-without kerning its not to useful.

Btw. do you know Moru's scalable font systems? He did a great work with them, years ago. Too bad his website is down and i dont have a copy of it.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1772
    • View Profile
    • Homepage
Re: _PRINT A clean scalable print type
« Reply #3 on: 2013-Jan-08 »
Aw I totally forgot about putting that page up again.

It's not all my work though, just modified Peejays code to use colours, faster rendering on tiny computers and auto-kerning.
Original can be found here for the kerning code, centering and justifying text and so on:
http://www.glbasic.com/forum/index.php?topic=1521.0

Haven't used it for anything useful yet though, really a sin.
The attached file should be the last update I did to it about three years ago.

[attachment deleted by admin]

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: _PRINT A clean scalable print type
« Reply #4 on: 2013-Jan-09 »
There is a large difference in the project when a novice like myself attempts something, against when someone with a lot of experience does it. But I'll get there one day. 
Thank you for the link, The code gives me something to aspire to.  :nw:
I came, I saw, I coded.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: _PRINT A clean scalable print type
« Reply #5 on: 2013-Jan-09 »
Nice work!
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1631
  • Particle Hawk
    • View Profile
Re: _PRINT A clean scalable print type
« Reply #6 on: 2013-Jan-09 »
Nice font objects  :good:
One note, as it were, you have a possibility(although not likely), you might end up with an ID collision.
You can use the GENSPRITE command to eliminate such an event.

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)