2009-01-21 20:34:42 -05:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-01-30 04:36:39 -05:00
|
|
|
USING: kernel arrays sequences math math.order opengl opengl.gl
|
2009-02-07 19:05:11 -05:00
|
|
|
strings fonts colors accessors ;
|
2009-01-21 20:34:42 -05:00
|
|
|
IN: ui.text
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
SYMBOL: font-renderer
|
|
|
|
|
2009-02-10 03:45:43 -05:00
|
|
|
HOOK: init-text-rendering font-renderer ( world -- )
|
|
|
|
|
2009-01-27 00:11:45 -05:00
|
|
|
HOOK: finish-text-rendering font-renderer ( world -- )
|
|
|
|
|
|
|
|
M: object finish-text-rendering drop ;
|
|
|
|
|
2009-01-30 04:36:39 -05:00
|
|
|
HOOK: string-dim font-renderer ( font string -- dim )
|
2009-01-21 20:34:42 -05:00
|
|
|
|
2009-01-30 04:36:39 -05:00
|
|
|
HOOK: string-width font-renderer ( font string -- w )
|
2009-01-21 20:34:42 -05:00
|
|
|
|
2009-01-30 04:36:39 -05:00
|
|
|
HOOK: string-height font-renderer ( font string -- h )
|
2009-01-21 20:34:42 -05:00
|
|
|
|
|
|
|
M: object string-dim [ string-width ] [ string-height ] 2bi 2array ;
|
|
|
|
|
|
|
|
M: object string-width string-dim first ;
|
|
|
|
|
|
|
|
M: object string-height string-dim second ;
|
|
|
|
|
|
|
|
HOOK: draw-string font-renderer ( font string loc -- )
|
|
|
|
|
|
|
|
HOOK: free-fonts font-renderer ( world -- )
|
|
|
|
|
|
|
|
: combine-text-dim ( dim1 dim2 -- dim3 )
|
|
|
|
[ [ first ] bi@ max ]
|
|
|
|
[ [ second ] bi@ + ]
|
|
|
|
2bi 2array ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
HOOK: x>offset font-renderer ( x font string -- n )
|
|
|
|
|
|
|
|
HOOK: offset>x font-renderer ( n font string -- x )
|
|
|
|
|
|
|
|
GENERIC: text-dim ( font text -- dim )
|
|
|
|
|
2009-01-30 04:36:39 -05:00
|
|
|
M: string text-dim string-dim ;
|
2009-01-21 20:34:42 -05:00
|
|
|
|
2009-02-09 01:22:41 -05:00
|
|
|
M: array text-dim
|
2009-01-30 04:36:39 -05:00
|
|
|
[ { 0 0 } ] 2dip [ string-dim combine-text-dim ] with each ;
|
2009-01-21 20:34:42 -05:00
|
|
|
|
|
|
|
: text-width ( font text -- w ) text-dim first ;
|
|
|
|
|
|
|
|
: text-height ( font text -- h ) text-dim second ;
|
|
|
|
|
2009-02-02 00:58:05 -05:00
|
|
|
HOOK: line-metrics font-renderer ( font string -- metrics )
|
2009-02-01 21:32:49 -05:00
|
|
|
|
2009-01-21 20:34:42 -05:00
|
|
|
GENERIC# draw-text 1 ( font text loc -- )
|
|
|
|
|
|
|
|
M: string draw-text draw-string ;
|
|
|
|
|
2009-02-07 19:05:11 -05:00
|
|
|
M: selection draw-text draw-string ;
|
|
|
|
|
2009-02-09 01:22:41 -05:00
|
|
|
M: array draw-text
|
2009-01-21 20:34:42 -05:00
|
|
|
[
|
|
|
|
[
|
|
|
|
2dup { 0 0 } draw-string
|
2009-01-30 04:36:39 -05:00
|
|
|
0.0 swap string-height 0.0 glTranslated
|
2009-01-21 20:34:42 -05:00
|
|
|
] with each
|
|
|
|
] with-translation ;
|