Author Topic: font kerning  (Read 3843 times)

Offline Julian

  • Mc. Print
  • *
  • Posts: 23
    • View Profile
font kerning
« on: 2012-Sep-29 »
I am building a simple gui for my project but font kerning does not work. The method "DDgui_UpdateFont(TRUE)" does not exist. At first I tried the version from the website: http://www.glbasic.com/showroom.php?site=games&game=DDgui which would not even compile. Searching for the Problem I found this updated version: http://www.glbasic.com/forum/index.php?topic=1868.msg13600#msg13600 but this too do not have this method. Where Can I find it? And is there a way to change the color scheme for the widgets?

MrTAToad

  • Guest
Re: font kerning
« Reply #1 on: 2012-Sep-29 »
To change the colour scheme, you need would need to do your own drawing routines for DDgui_draw_user, handle_user and so on.

In addition, you could also use COL_BRIGHT, COL_NORM, COL_HOVER_BRIGHT and COL_HOVER_NORM

DDgui_UpdateFont should exist (is updated with GLBasic), and consists of :

Code: (glbasic) [Select]
// ------------------------------------------ //
//! Initialize font (with kerning)
// ------------------------------------------ //
FUNCTION DDgui_UpdateFont: bWantKerning%, iPixelsSpaceBetweenLettersIfKerning%=2

ddgui_font_kerning.bHasKerning% = bWantKerning%

RETURN


// ancient code ...
LOCAL fx%, fy%

IF LEN(ddgui_font_kerning.left%[])<256
DIM ddgui_font_kerning.left%[256]
DIM ddgui_font_kerning.width%[256]
ENDIF

GETFONTSIZE fx%, fy%
IF bWantKerning

LOCAL spr_bar%, spr_char%

// create vertival bar image
LOCAL pix%[]
DIM pix%[fy]
FOREACH p% IN pix%[]; p = 0xffffffff; NEXT
spr_bar=GENSPRITE()
MEM2SPRITE(pix%[], spr_bar, 1, fy)
spr_char=GENSPRITE()

ddgui_font_kerning.bHasKerning%=TRUE
FOR i% = 0 TO 255
DRAWRECT 0,0,fx+2, fy+2, RGB(255,0,128)
PRINT CHR$(i%), 1,1
GRABSPRITE spr_char%, 1,1, fx,fy

ddgui_font_kerning.width[i%] = fx%
FOR x%=0 TO fx-1
IF SPRCOLL(spr_bar,x,0, spr_char%,0,0)
ddgui_font_kerning.left[i%] = x
BREAK
ENDIF
NEXT
FOR x%=fx-1 TO 0 STEP -1
IF SPRCOLL(spr_bar,x,0, spr_char%,0,0)
ddgui_font_kerning.width[i%] = x - ddgui_font_kerning.left[i%] + iPixelsSpaceBetweenLettersIfKerning%
BREAK
ENDIF
NEXT

// totally empty chars
IF ddgui_font_kerning.width%[i%]<=1
ddgui_font_kerning.width%[i%] = (fx%*10)/100+iPixelsSpaceBetweenLettersIfKerning%
ddgui_font_kerning.left%[i%]  = 0
ENDIF
NEXT
GRABSPRITE spr_bar , 0,0,0,0
GRABSPRITE spr_char, 0,0,0,0

// fix space character
ddgui_font_kerning.width%[ASC(" ")] = ddgui_font_kerning.width%[ASC("n")]
ddgui_font_kerning.left[ASC(" ")] = 0
ELSE
ddgui_font_kerning.bHasKerning%=FALSE
FOREACH sp% IN ddgui_font_kerning.left%[]
sp% = 0
NEXT
FOREACH sp% IN ddgui_font_kerning.width%[]
sp% = fx%
NEXT
ENDIF
ENDFUNCTION

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: font kerning
« Reply #2 on: 2012-Sep-29 »
You always find the latest version of DDgui.gbas in your GLBasic installation in \Samples\Common\DDgui.gbas
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Julian

  • Mc. Print
  • *
  • Posts: 23
    • View Profile
Re: font kerning
« Reply #3 on: 2012-Sep-30 »
Thanks you two. Using the version from my samples folder works fine.