Check-in [2afe3e3af7]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Test case for text widget
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2afe3e3af74db7949e1dab28559ad8fe3a4f731d
User & Date: bernd 2013-11-27 22:22:10.743
Context
2013-11-27
22:31
Freetype-gl*.fs properly linked check-in: 7cd8045508 user: bernd tags: trunk
22:22
Test case for text widget check-in: 2afe3e3af7 user: bernd tags: trunk
00:21
Uniform program for text and normal textures check-in: 2e267bcf9f user: bernd tags: trunk
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to freetype-gl/Makefile.am.
14
15
16
17
18
19
20
21

14
15
16
17
18
19
20

21







-
+
## flags are passed to the compiler for both C and C++, in addition to the
## language-specific options.
AM_CPPFLAGS = $(EXAMPLE_CFLAGS) -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include/ -I/home/bernd/proj/freetype2-android/include

lib_LTLIBRARIES = libfreetype-gl.la
libfreetype_gl_la_SOURCES = texture-atlas.c texture-font.c vector.c
include_HEADERS = freetype-gl.h
libfreetype_gl_la_LIBADD = -lm -l@LIBGL@ -L. -lfreetype -lz -lglib-2.0 @LIBOBJS@
libfreetype_gl_la_LIBADD = -lm -l@LIBGL@ -L. -lfreetype -lz -lglib-2.0 @LIBADD@
Changes to freetype-gl/configure.ac.
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22

23
24
25
26
8
9
10
11
12
13
14

15
16
17
18
19
20
21

22
23
24
25
26







-
+






-
+




AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
AM_PROG_AR
LT_INIT

case $CC in
     *android*)
	LIBOBJS="-llog -lglib-android-1.0"
	LIBADD="-llog -lglib-android-1.0"
	LIBGL=GLESv2
	;;
     *)
	LIBGL=GL
	;;
esac
AC_SUBST(LIBOBJS)
AC_SUBST(LIBADD)
AC_SUBST(LIBGL)

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
Changes to gles2/ftgl-helper.fs.
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37







-
+







." Textur in Atlas: " atlas texture_atlas_t-id l@ . cr
: atlas-tex  atlas texture_atlas_t-id l@ dup to current-tex
    GL_TEXTURE_2D swap glBindTexture ;

\ render font into vertex buffers

2 sfloats buffer: penxy
Variable color $FFC0A000 color !
Variable color $FFC0A0FF color !

: xy, { glyph -- }
    penxy sf@ penxy sfloat+ sf@ { f: xp f: yp }
    glyph texture_glyph_t-offset_x l@ s>f
    glyph texture_glyph_t-offset_y l@ s>f { f: xo f: yo }
    glyph texture_glyph_t-width  l@ s>f
    glyph texture_glyph_t-height l@ s>f { f: w f: h }    
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120


121
122
123
124


125
126
90
91
92
93
94
95
96





















97
98
99

100
101
102
103
104

105
106
107
108







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
+
+



-
+
+


	I xc@+ swap >r xchar@xy r>
    I - +LOOP  drop ;

: load-glyphs ( -- )
    font
    "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\0" >wide$ drop texture_font_load_glyphs drop ;

GL_FRAGMENT_SHADER shader: textFragmentShader
#precision
uniform vec3 u_LightPos;        // The position of the light in eye space.
uniform sampler2D u_Texture;    // The input texture.
uniform float u_Ambient;        // ambient lighting level
 
varying vec3 v_Position;        // Interpolated position for this fragment.
varying vec4 v_Color;           // This is the color from the vertex shader interpolated across the
                                // triangle per fragment.
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
 
// The entry point for our fragment shader.
void main()
{
    gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
//    gl_FragColor.rgb = v_Color.rgb;
}

' VertexShader ' textFragmentShader create-program Value textprogram
textprogram init
program init

: <render ( -- )
    textprogram glUseProgram
    program glUseProgram
    1-bias set-color+
    .01e 100e 100e >ap
    atlas-tex v0 i0 ;

: render> ( -- )  GL_TRIANGLES draw-elements ;
: render> ( -- )  GL_TRIANGLES draw-elements
    ( Coloradd 0e fdup fdup fdup glUniform4f ) ;

previous previous
Changes to gles2/ftgl-sample.fs.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







\ freetype GL example

require gl-helper.fs
[IFUNDEF] android window-init [THEN]
[IFUNDEF] android helper-init [THEN]

require ftgl-helper.fs

\ Demo Toplevel

also freetype-gl
also opengl
Changes to gles2/gl-helper.fs.
263
264
265
266
267
268
269

270
271
272
273
274
275
276
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277







+







}

GL_FRAGMENT_SHADER shader: FragmentShader
#precision
uniform vec3 u_LightPos;        // The position of the light in eye space.
uniform sampler2D u_Texture;    // The input texture.
uniform float u_Ambient;        // ambient lighting level
uniform vec4 u_Coloradd;        // color bias for texture
 
varying vec3 v_Position;        // Interpolated position for this fragment.
varying vec4 v_Color;           // This is the color from the vertex shader interpolated across the
                                // triangle per fragment.
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
 
289
290
291
292
293
294
295
296
297



298
299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
290
291
292
293
294
295
296


297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338







-
-
+
+
+













+

















+







 
    // Add attenuation.
    diffuse = diffuse * (1.0 / (1.0 + (0.10 * distance)));
 
    // Add ambient lighting
    diffuse = (diffuse * ( 1.0 - u_Ambient )) + u_Ambient;
 
    // Multiply the color by the diffuse illumination level and texture value to get final output color.
    gl_FragColor = vec4(diffuse, diffuse, diffuse, 1.0) * v_Color * texture2D(u_Texture, v_TexCoordinate);
// Multiply the color by the diffuse illumination level and texture value to get final output color.
    vec4 texture = texture2D(u_Texture, v_TexCoordinate) + u_Coloradd;
    gl_FragColor = vec4(diffuse, diffuse, diffuse, 1.0) * v_Color * texture;
    // vec4 pixel = (v_Color * texture2D(u_Texture, v_TexCoordinate));
    // gl_FragColor = vec4(pixel.rgb, pixel.a);
    // gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
    // gl_FragColor = (v_Color * diffuse);
    // gl_FragColor = v_Color;
}


0 Value MVPMatrix
0 Value MVMatrix
0 Value LightPos
0 Value Texture
0 Value ambient
0 Value Coloradd
0 Value program

: create-program { vs-xt fs-xt -- program }
    glCreateProgram dup >r IF
	r@ vs-xt execute glAttachShader
	r@ fs-xt execute glAttachShader
	vs-xt r@ >bindattrib
	r@ glLinkProgram THEN
    r> ;

[IFDEF] GL_TEXTURE_EXTERNAL_OES
GL_FRAGMENT_SHADER shader: oesShader
#extension GL_OES_EGL_image_external : require
#precision
uniform vec3 u_LightPos;        // The position of the light in eye space.
uniform samplerExternalOES u_Texture;
uniform float u_Ambient;        // ambient lighting level
uniform vec4 u_Colorad;         // color bias for texture
 
varying vec3 v_Position;        // Interpolated position for this fragment.
varying vec4 v_Color;           // This is the color from the vertex shader interpolated across the
                                // triangle per fragment.
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
void main() {
354
355
356
357
358
359
360





361
362
363
364
365
366
367
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376







+
+
+
+
+








: clear ( -- )
    GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT or glClear ;

: sf,  ( float -- )  here 1 sfloats allot sf! ;
: sf!+ ( float addr -- addr' )  dup sf! sfloat+ ;

Create z-bias
0e sf, 0e sf, 0e sf, 0e sf,
Create 1-bias
1e sf, 1e sf, 1e sf, 0e sf,

Create unit-matrix
1.0e sf, 0.0e sf, 0.0e sf, 0.0e sf,
0.0e sf, 1.0e sf, 0.0e sf, 0.0e sf,
0.0e sf, 0.0e sf, 1.0e sf, 0.0e sf,
0.0e sf, 0.0e sf, 0.0e sf, 1.0e sf,

unit-matrix 12 sfloats + Constant x-pos
381
382
383
384
385
386
387


388
389
390
391
392
393
394
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405







+
+







	I 4 sfloats bounds DO
	    I sf@ f.
	1 sfloats +LOOP cr
    4 sfloats +LOOP ;

: set-matrix ( addr handle -- ) swap >r
    1 false r> glUniformMatrix4fv ;

: set-color+ ( addr -- )  Coloradd 1 rot glUniform4fv ;

: >ortho { f: near f: far f: left f: right f: top f: bottom -- }
    ap-matrix
    near f2* right left f- f/ sf!+ 0e sf!+ 0e sf!+ 0e sf!+
    0e sf!+ near f2* top bottom f- f/ sf!+ 0e sf!+ 0e sf!+
    right left f+ right left f- f/ sf!+
    top bottom f+ top bottom f- f/ sf!+
486
487
488
489
490
491
492

493
494
495
496
497
498

499
500
501
502
503
504
505
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518







+






+







    GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
    program glUseProgram
    program "u_MVPMatrix\0" drop glGetUniformLocation to MVPMatrix
    program "u_MVMatrix\0" drop glGetUniformLocation to MVMatrix
    program "u_LightPos\0" drop glGetUniformLocation to LightPos
    program "u_Texture\0" drop glGetUniformLocation to Texture
    program "u_Ambient\0" drop glGetUniformLocation to Ambient
    program "u_Coloradd\0" drop glGetUniformLocation to Coloradd
    GL_UNPACK_ALIGNMENT 1 glPixelStorei
    GL_TEXTURE0 glActiveTexture
    none-tex no-texture
    Texture 0 glUniform1i
    Ambient 1 ambient% glUniform1fv
    LightPos 0.0e 0.0e -0.3e glUniform3f
    z-bias set-color+
    .01e 100e dpy-w @ dpy-h @ min s>f f2/ 100 fm* >ap ;

: 2d-vertex ( index addr -- ) >r
    dup 2 GL_FLOAT  0 0 r> glVertexAttribPointer
    glEnableVertexAttribArray ;

: 3d-vertex ( index addr -- ) >r
Added gles2/widgets-test.fs.











































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ simple tests for widgets code

require widgets.fs

also minos

frame new value f1
frame new value f2
frame new value f3
frame new value f4
frame new value f5
frame new value f6
text new value f7
text new value f8
f1 >o rdrop
0 x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
32 border ! $FFFFFFFF frame-color !
button2

f2 >o rdrop
dpy-w @ 2/ x ! 0 y ! dpy-w @ 2/ w ! dpy-h @ 19 20 */ d !
32 border ! $FF7FFFFF frame-color !
button3

f3 >o rdrop
0 x ! dpy-h @ 2/ y ! dpy-w @ 2/ w ! dpy-h @ 2/ 2/ d !
16 border ! $FFFF7FFF frame-color !
button1

f4 >o rdrop
0 x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
32 border ! $FF7F7FFF frame-color !
button1

f5 >o rdrop
dpy-w @ 4 / x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
8 border ! $7FFF7FFF frame-color !
button1

f6 >o rdrop
dpy-w @ 4 / x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
16 border ! $7FFFFFFF frame-color !
button2

also freetype-gl
48e FConstant fontsize#
atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
[THEN]
fontsize# texture_font_new Value font1

atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/gkai00mp.ttf\0" drop
[THEN]
fontsize# texture_font_new Value font2
previous

f7 >o rdrop
8 x ! dpy-h @ 4 / y ! "Dös isch a Tägscht!" text-string $!
$884400FF text-color !  font1 text-font !

f8 >o rdrop
8 x ! dpy-h @ 5 8 */ y ! "这是一个文本:在德语说" text-string $!
$004488FF text-color !  font2 text-font !

<draw0 draw0>
<draw1
f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
draw1>
<draw2
f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
draw2>
sync
Added gles2/widgets.fs.













































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ MINOS2 widget basis

\ A MINOS2 widget is composed of drawable elements, boxes and actors.
\ to make things easier, neither drawable elements nor boxes need an actor.

require gl-helper.fs
require ftgl-helper.fs
require mini-oof2.fs

get-current
also [IFDEF] android android [THEN]
also opengl

helper-init

vocabulary minos  also minos definitions

0 Value layer \ drawing layer

object class
    field: caller-w
    method clicked
    method keyed
    method inside?
    method focus
    method defocus
    method show
    method hide
    method get
    method set
    method show-you
end-class actor

object class
    field: next-w
    field: parent-w
    field: x
    field: y
    field: w
    field: h \ above baseline
    field: d \ below baseline
    method draw ( -- )
    method hglue
    method vglue
    method hglue@ \ cached variant
    method vglue@ \ cached variant
    method xywh
    method xywhd
    method !size \ set your own size
end-class widget

:noname x @ y @ h @ - w @ h @ d @ + ; widget to xywh
:noname x @ y @ w @ h @ d @ ; widget to xywhd
' noop widget to !size

widget class
    field: child-w
    field: act
    method resized
    method map
end-class box

tex: style-tex \ 8 x 8 subimages, each sized 128x128
style-tex 1024 dup rgba-newtex

\ tile widget

widget class
    field: frame#
    field: frame-color
end-class tile

8 Value style-w#
8 Value style-h#

: #>st ( x y frame -- ) \ using frame#
    style-w# /mod
    s>f f+ style-w# fm/ fswap
    s>f f+ style-h# fm/ fswap >st ;

: draw-rectangle { f: x1 f: y1 f: x2 f: y2 -- }
    i? >v
    x1 y2 >xy frame-color @ rgba>c n> 0e 1e frame# @ #>st v+
    x2 y2 >xy frame-color @ rgba>c n> 1e 1e frame# @ #>st v+
    x2 y1 >xy frame-color @ rgba>c n> 1e 0e frame# @ #>st v+
    x1 y1 >xy frame-color @ rgba>c n> 0e 0e frame# @ #>st v+
    v> dup i, dup 1+ i, dup 2 + i, dup i, dup 2 + i, 3 + i, ;
: tile-draw ( -- ) layer 1 <> ?EXIT
    xywh { x y w h }
    x s>f y s>f x w + s>f y h + s>f
    draw-rectangle GL_TRIANGLES draw-elements ;

' tile-draw tile is draw

\ frame widget

tile class
    field: border
end-class frame

Create button-st  0e sf, 0.25e sf, 0.75e sf, 1e sf,
DOES>  swap sfloats + sf@ ;
: button-border ( n -- gray )  dup 2/ xor ;
: >border ( x b i w -- r ) >r
    button-border >r
    r@ 1 and 0= IF drop 0       THEN
    r> 2 and    IF negate r@ +  THEN  + s>f  rdrop ;

: frame-draw ( -- ) layer 1 <> ?EXIT
    frame# @ frame-color @ border @ xywh { f c b x y w h }
    i>off >v
    4 0 DO
	4 0 DO
	    x b I w >border  y b J h >border >xy
	    c rgba>c  n>
	    I button-st J button-st f #>st v+
	LOOP
    LOOP
    v>
    9 0  DO
	4 quad  1 I 3 mod 2 = - i-off +!
    LOOP
; ' frame-draw frame to draw

\ text widget

widget class
    field: text-string
    field: text-font
    field: text-color
end-class text

: text-draw ( -- ) layer 2 <> ?EXIT
    x @ s>f penxy sf!  y @ s>f penxy sfloat+ sf!
    text-font @ to font  text-color @ color !
    text-string $@ render-string ;
: text-!size ( -- )
    text-string $@ layout-string
    f>s d ! f>s h ! f>s w ! ;
' text-draw text to draw
' text-!size text to !size

\ draw wrapper

: <draw0 ( -- )  0 to layer
    -1e 1e >apxy
    .01e 100e 100e >ap
    0.01e 0.02e 0.15e 1.0e glClearColor
    Ambient 1 ambient% glUniform1fv ;
: draw0> ( -- ) clear v0 i0 ;

: <draw1 ( -- )  1 to layer
    z-bias set-color+
    program glUseProgram  style-tex ;
: draw1> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;

: <draw2 ( -- )  2 to layer
    1-bias set-color+
    program glUseProgram  atlas-tex ;
: draw2> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;

Variable style-i#

: load-style ( addr u -- n )  style-tex
    style-i# @ 8 /mod 128 * >r 128 * r> 2swap load-subtex 2drop
    style-i# @ 1 style-i# +! ;
: style: load-style Create , DOES> @ frame# ! ;

"button.png" style: button1
"button2.png" style: button2
"button3.png" style: button3

previous previous previous set-current
Changes to widgets-test.fs.
1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18

19
20
21
22
23

24
25
26
27
28

29
30
31
32
33

34
35
36
37
38

39
40
41
42
43







44




45



















1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23

24
25
26
27
28

29
30
31
32
33

34
35
36
37
38

39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75






-






+
+




-
+




-
+




-
+




-
+




-
+




-
+
+
+
+
+
+
+

+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ simple tests for widgets code

require widgets.fs

also minos

<draw
frame new value f1
frame new value f2
frame new value f3
frame new value f4
frame new value f5
frame new value f6
text new value f7
text new value f8
f1 >o rdrop
0 x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
32 border ! $FFFFFFFF frame-color !
button2
draw

f2 >o rdrop
dpy-w @ 2/ x ! 0 y ! dpy-w @ 2/ w ! dpy-h @ 19 20 */ d !
32 border ! $FF7FFFFF frame-color !
button3
draw

f3 >o rdrop
0 x ! dpy-h @ 2/ y ! dpy-w @ 2/ w ! dpy-h @ 2/ 2/ d !
16 border ! $FFFF7FFF frame-color !
button1
draw

f4 >o rdrop
0 x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
32 border ! $FF7F7FFF frame-color !
button1
draw

f5 >o rdrop
dpy-w @ 4 / x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
8 border ! $7FFF7FFF frame-color !
button1
draw

f6 >o rdrop
dpy-w @ 4 / x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
16 border ! $7FFFFFFF frame-color !
button2
draw draw>

also freetype-gl
48e FConstant fontsize#
atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
[THEN]
fontsize# texture_font_new Value font1

atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
[ELSE] "/usr/share/fonts/truetype/gkai00mp.ttf\0" drop
[THEN]
fontsize# texture_font_new Value font2
previous

f7 >o rdrop
8 x ! dpy-h @ 4 / y ! "Dös isch a Tägscht!" text-string $!
$884400FF text-color !  font1 text-font !

f8 >o rdrop
8 x ! dpy-h @ 5 8 */ y ! "这是一个文本:在德语说" text-string $!
$004488FF text-color !  font2 text-font !

<draw0 draw0>
<draw1
f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
draw1>
<draw2
f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
draw2>
sync
Changes to widgets.fs.
11
12
13
14
15
16
17


18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26







+
+







also [IFDEF] android android [THEN]
also opengl

helper-init

vocabulary minos  also minos definitions

0 Value layer \ drawing layer

object class
    field: caller-w
    method clicked
    method keyed
    method inside?
    method focus
    method defocus
33
34
35
36
37
38
39
40

41
42
43
44
45
46

47
48
49
50

51
52
53
54
55
56
57
58
59
60


61
62
63
64
65
66
67
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73







-
+






+




+










+
+







    field: next-w
    field: parent-w
    field: x
    field: y
    field: w
    field: h \ above baseline
    field: d \ below baseline
    method draw
    method draw ( -- )
    method hglue
    method vglue
    method hglue@ \ cached variant
    method vglue@ \ cached variant
    method xywh
    method xywhd
    method !size \ set your own size
end-class widget

:noname x @ y @ h @ - w @ h @ d @ + ; widget to xywh
:noname x @ y @ w @ h @ d @ ; widget to xywhd
' noop widget to !size

widget class
    field: child-w
    field: act
    method resized
    method map
end-class box

tex: style-tex \ 8 x 8 subimages, each sized 128x128
style-tex 1024 dup rgba-newtex

\ tile widget

widget class
    field: frame#
    field: frame-color
end-class tile

8 Value style-w#
75
76
77
78
79
80
81
82

83
84
85
86
87


88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116








117
118













119
120
121

122





123






124
125
126
127
128
129
130
131
132
133
134
135
136
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173







-
+





+
+













-
+















+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+

+
+
+
+
+
-
+
+
+
+
+
+













: draw-rectangle { f: x1 f: y1 f: x2 f: y2 -- }
    i? >v
    x1 y2 >xy frame-color @ rgba>c n> 0e 1e frame# @ #>st v+
    x2 y2 >xy frame-color @ rgba>c n> 1e 1e frame# @ #>st v+
    x2 y1 >xy frame-color @ rgba>c n> 1e 0e frame# @ #>st v+
    x1 y1 >xy frame-color @ rgba>c n> 0e 0e frame# @ #>st v+
    v> dup i, dup 1+ i, dup 2 + i, dup i, dup 2 + i, 3 + i, ;
: tile-draw ( -- )
: tile-draw ( -- ) layer 1 <> ?EXIT
    xywh { x y w h }
    x s>f y s>f x w + s>f y h + s>f
    draw-rectangle GL_TRIANGLES draw-elements ;

' tile-draw tile is draw

\ frame widget

tile class
    field: border
end-class frame

Create button-st  0e sf, 0.25e sf, 0.75e sf, 1e sf,
DOES>  swap sfloats + sf@ ;
: button-border ( n -- gray )  dup 2/ xor ;
: >border ( x b i w -- r ) >r
    button-border >r
    r@ 1 and 0= IF drop 0       THEN
    r> 2 and    IF negate r@ +  THEN  + s>f  rdrop ;

: frame-draw ( -- )
: frame-draw ( -- ) layer 1 <> ?EXIT
    frame# @ frame-color @ border @ xywh { f c b x y w h }
    i>off >v
    4 0 DO
	4 0 DO
	    x b I w >border  y b J h >border >xy
	    c rgba>c  n>
	    I button-st J button-st f #>st v+
	LOOP
    LOOP
    v>
    9 0  DO
	4 quad  1 I 3 mod 2 = - i-off +!
    LOOP
; ' frame-draw frame to draw

\ text widget

widget class
    field: text-string
    field: text-font
    field: text-color
end-class text

: <draw ( -- )  v0 i0
    program glUseProgram  style-tex
: text-draw ( -- ) layer 2 <> ?EXIT
    x @ s>f penxy sf!  y @ s>f penxy sfloat+ sf!
    text-font @ to font  text-color @ color !
    text-string $@ render-string ;
: text-!size ( -- )
    text-string $@ layout-string
    f>s d ! f>s h ! f>s w ! ;
' text-draw text to draw
' text-!size text to !size

\ draw wrapper

: <draw0 ( -- )  0 to layer
    -1e 1e >apxy
    .01e 100e 100e >ap
    0.6e 0.4e 0.2e 1.0e glClearColor clear
    0.01e 0.02e 0.15e 1.0e glClearColor
    Ambient 1 ambient% glUniform1fv ;
: draw0> ( -- ) clear v0 i0 ;

: <draw1 ( -- )  1 to layer
    z-bias set-color+
    program glUseProgram  style-tex ;
: draw> ( -- )  GL_TRIANGLES draw-elements sync v0 i0 ;
: draw1> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;

: <draw2 ( -- )  2 to layer
    1-bias set-color+
    program glUseProgram  atlas-tex ;
: draw2> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;

Variable style-i#

: load-style ( addr u -- n )  style-tex
    style-i# @ 8 /mod 128 * >r 128 * r> 2swap load-subtex 2drop
    style-i# @ 1 style-i# +! ;
: style: load-style Create , DOES> @ frame# ! ;

"button.png" style: button1
"button2.png" style: button2
"button3.png" style: button3

previous previous previous set-current