]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/text/text.factor
Add foreground and background color slots to font tuple
[factor.git] / basis / ui / text / text.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel arrays sequences math math.order opengl opengl.gl
4 strings fonts colors ;
5 IN: ui.text
6
7 <PRIVATE
8
9 SYMBOL: font-renderer
10
11 HOOK: finish-text-rendering font-renderer ( world -- )
12
13 M: object finish-text-rendering drop ;
14
15 HOOK: string-dim font-renderer ( font string -- dim )
16
17 HOOK: string-width font-renderer ( font string -- w )
18
19 HOOK: string-height font-renderer ( font string -- h )
20
21 M: object string-dim [ string-width ] [ string-height ] 2bi 2array ;
22
23 M: object string-width string-dim first ;
24
25 M: object string-height string-dim second ;
26
27 HOOK: draw-string font-renderer ( font string loc -- )
28
29 HOOK: free-fonts font-renderer ( world -- )
30
31 : combine-text-dim ( dim1 dim2 -- dim3 )
32     [ [ first ] bi@ max ]
33     [ [ second ] bi@ + ]
34     2bi 2array ;
35
36 PRIVATE>
37
38 HOOK: x>offset font-renderer ( x font string -- n )
39
40 HOOK: offset>x font-renderer ( n font string -- x )
41
42 GENERIC: text-dim ( font text -- dim )
43
44 M: string text-dim string-dim ;
45
46 M: sequence text-dim
47     [ { 0 0 } ] 2dip [ string-dim combine-text-dim ] with each ;
48
49 : text-width ( font text -- w ) text-dim first ;
50
51 : text-height ( font text -- h ) text-dim second ;
52
53 GENERIC# draw-text 1 ( font text loc -- )
54
55 M: string draw-text draw-string ;
56
57 M: sequence draw-text
58     [
59         [
60             2dup { 0 0 } draw-string
61             0.0 swap string-height 0.0 glTranslated
62         ] with each
63     ] with-translation ;