Author Topic: Center / Align / Scroll text with proportional fonts  (Read 3415 times)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
I have been reworking PeeJays Bitmap Font routines for using more than one font, colors and scrolling messages. The source code can be downloaded from my homepage together with examples of how to use it.

A short example how to use the library:
Code: GLBasic [Select]
// First we add two fonts and put the font-id into variables
// We need to tell it the size of the grafic, the desired space
// between characters and what sprite-number to start
// importing at but only the first time. The routine expects the
// grafic to be 16x16 characters, if not you need to specify the size
big = AddFont("smallfont.png",  336, 368, 2, 1000)
small = AddFont("smallfont2.png", 160, 224, 1)

// Main color and alpha-mode of the text (r, g, b, font, alpha)
TextColor(128,255,128, big, 0)
TextColor(128,255,128, small, 0.7)

DrawText("This text is kerned.",0,50,TRUE)
DrawText("This text is not kerned.",0,80,FALSE)

WrapText("Sometimes we just want to be able to type long strings and not have to worry about when to stop - this is where word wrap comes in.",0,50,640,TRUE,2,big)

CentreText("This text is centralised on the screen",320,50,TRUE,2,big)

TextColor(0,0,255)
RightText("This text is right justified and blue",640,50,TRUE,2,big)

JustifyText("And finally, we have the ability to call a function to allow us to fully justify text. This allows for text to be displayed filling the entire area, and evenly spaced.",0,50,640,2,small)

 

You can change the color of each corner of all characters and those will blend smothly.

Code: GLBasic [Select]
TextColorCorner("d", 0, 128, 0)         // change the lower two corners (Default font 0 if we don't specify)
TextColorCorner("u", 255, 255, 255)     // change the upper two corners (Default font 0 if we don't specify)
 
Use these codes to choose corner:
"ul", "dl", "dr", "ur" (UpLeft, DownRight and so on)
"u" for up, "d" for down and "l" and "r" for sides

Update 2008-08-20: Finally figured a workaround for the blending feature of POLYVECTOR so now we can use Multisampling which enables italic styles too. Bold has always worked though.

So this gives us one more command: FontStyle(fnr, bold, italic)
Bold is how many pixels to add to the thickness and italic is how many pixels to scew the font to the left (negative) or right (positive)

For examples of everything, run the exefile :-)

[attachment deleted by admin]
« Last Edit: 2015-Apr-05 by Moru »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Fixed some bugs and new functions