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
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

Changes to freetype-gl/Makefile.am.

    14     14   ## flags are passed to the compiler for both C and C++, in addition to the
    15     15   ## language-specific options.
    16     16   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
    17     17   
    18     18   lib_LTLIBRARIES = libfreetype-gl.la
    19     19   libfreetype_gl_la_SOURCES = texture-atlas.c texture-font.c vector.c
    20     20   include_HEADERS = freetype-gl.h
    21         -libfreetype_gl_la_LIBADD = -lm -l@LIBGL@ -L. -lfreetype -lz -lglib-2.0 @LIBOBJS@
           21  +libfreetype_gl_la_LIBADD = -lm -l@LIBGL@ -L. -lfreetype -lz -lglib-2.0 @LIBADD@

Changes to freetype-gl/configure.ac.

     8      8   AC_CONFIG_HEADERS([config.h])
     9      9   AC_PROG_CC
    10     10   AM_PROG_AR
    11     11   LT_INIT
    12     12   
    13     13   case $CC in
    14     14        *android*)
    15         -	LIBOBJS="-llog -lglib-android-1.0"
           15  +	LIBADD="-llog -lglib-android-1.0"
    16     16   	LIBGL=GLESv2
    17     17   	;;
    18     18        *)
    19     19   	LIBGL=GL
    20     20   	;;
    21     21   esac
    22         -AC_SUBST(LIBOBJS)
           22  +AC_SUBST(LIBADD)
    23     23   AC_SUBST(LIBGL)
    24     24   
    25     25   AC_CONFIG_FILES([Makefile])
    26     26   AC_OUTPUT

Changes to gles2/ftgl-helper.fs.

    23     23   ." Textur in Atlas: " atlas texture_atlas_t-id l@ . cr
    24     24   : atlas-tex  atlas texture_atlas_t-id l@ dup to current-tex
    25     25       GL_TEXTURE_2D swap glBindTexture ;
    26     26   
    27     27   \ render font into vertex buffers
    28     28   
    29     29   2 sfloats buffer: penxy
    30         -Variable color $FFC0A000 color !
           30  +Variable color $FFC0A0FF color !
    31     31   
    32     32   : xy, { glyph -- }
    33     33       penxy sf@ penxy sfloat+ sf@ { f: xp f: yp }
    34     34       glyph texture_glyph_t-offset_x l@ s>f
    35     35       glyph texture_glyph_t-offset_y l@ s>f { f: xo f: yo }
    36     36       glyph texture_glyph_t-width  l@ s>f
    37     37       glyph texture_glyph_t-height l@ s>f { f: w f: h }    
................................................................................
    90     90   	I xc@+ swap >r xchar@xy r>
    91     91       I - +LOOP  drop ;
    92     92   
    93     93   : load-glyphs ( -- )
    94     94       font
    95     95       "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\0" >wide$ drop texture_font_load_glyphs drop ;
    96     96   
    97         -GL_FRAGMENT_SHADER shader: textFragmentShader
    98         -#precision
    99         -uniform vec3 u_LightPos;        // The position of the light in eye space.
   100         -uniform sampler2D u_Texture;    // The input texture.
   101         -uniform float u_Ambient;        // ambient lighting level
   102         - 
   103         -varying vec3 v_Position;        // Interpolated position for this fragment.
   104         -varying vec4 v_Color;           // This is the color from the vertex shader interpolated across the
   105         -                                // triangle per fragment.
   106         -varying vec3 v_Normal;          // Interpolated normal for this fragment.
   107         -varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
   108         - 
   109         -// The entry point for our fragment shader.
   110         -void main()
   111         -{
   112         -    gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
   113         -//    gl_FragColor.rgb = v_Color.rgb;
   114         -}
   115         -
   116         -' VertexShader ' textFragmentShader create-program Value textprogram
   117         -textprogram init
           97  +program init
   118     98   
   119     99   : <render ( -- )
   120         -    textprogram glUseProgram
          100  +    program glUseProgram
          101  +    1-bias set-color+
   121    102       .01e 100e 100e >ap
   122    103       atlas-tex v0 i0 ;
   123    104   
   124         -: render> ( -- )  GL_TRIANGLES draw-elements ;
          105  +: render> ( -- )  GL_TRIANGLES draw-elements
          106  +    ( Coloradd 0e fdup fdup fdup glUniform4f ) ;
   125    107   
   126    108   previous previous

Changes to gles2/ftgl-sample.fs.

     1      1   \ freetype GL example
     2      2   
     3      3   require gl-helper.fs
     4         -[IFUNDEF] android window-init [THEN]
            4  +[IFUNDEF] android helper-init [THEN]
     5      5   
     6      6   require ftgl-helper.fs
     7      7   
     8      8   \ Demo Toplevel
     9      9   
    10     10   also freetype-gl
    11     11   also opengl

Changes to gles2/gl-helper.fs.

   263    263   }
   264    264   
   265    265   GL_FRAGMENT_SHADER shader: FragmentShader
   266    266   #precision
   267    267   uniform vec3 u_LightPos;        // The position of the light in eye space.
   268    268   uniform sampler2D u_Texture;    // The input texture.
   269    269   uniform float u_Ambient;        // ambient lighting level
          270  +uniform vec4 u_Coloradd;        // color bias for texture
   270    271    
   271    272   varying vec3 v_Position;        // Interpolated position for this fragment.
   272    273   varying vec4 v_Color;           // This is the color from the vertex shader interpolated across the
   273    274                                   // triangle per fragment.
   274    275   varying vec3 v_Normal;          // Interpolated normal for this fragment.
   275    276   varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
   276    277    
................................................................................
   289    290    
   290    291       // Add attenuation.
   291    292       diffuse = diffuse * (1.0 / (1.0 + (0.10 * distance)));
   292    293    
   293    294       // Add ambient lighting
   294    295       diffuse = (diffuse * ( 1.0 - u_Ambient )) + u_Ambient;
   295    296    
   296         -    // Multiply the color by the diffuse illumination level and texture value to get final output color.
   297         -    gl_FragColor = vec4(diffuse, diffuse, diffuse, 1.0) * v_Color * texture2D(u_Texture, v_TexCoordinate);
          297  +// Multiply the color by the diffuse illumination level and texture value to get final output color.
          298  +    vec4 texture = texture2D(u_Texture, v_TexCoordinate) + u_Coloradd;
          299  +    gl_FragColor = vec4(diffuse, diffuse, diffuse, 1.0) * v_Color * texture;
   298    300       // vec4 pixel = (v_Color * texture2D(u_Texture, v_TexCoordinate));
   299    301       // gl_FragColor = vec4(pixel.rgb, pixel.a);
   300    302       // gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
   301    303       // gl_FragColor = (v_Color * diffuse);
   302    304       // gl_FragColor = v_Color;
   303    305   }
   304    306   
   305    307   
   306    308   0 Value MVPMatrix
   307    309   0 Value MVMatrix
   308    310   0 Value LightPos
   309    311   0 Value Texture
   310    312   0 Value ambient
          313  +0 Value Coloradd
   311    314   0 Value program
   312    315   
   313    316   : create-program { vs-xt fs-xt -- program }
   314    317       glCreateProgram dup >r IF
   315    318   	r@ vs-xt execute glAttachShader
   316    319   	r@ fs-xt execute glAttachShader
   317    320   	vs-xt r@ >bindattrib
................................................................................
   321    324   [IFDEF] GL_TEXTURE_EXTERNAL_OES
   322    325   GL_FRAGMENT_SHADER shader: oesShader
   323    326   #extension GL_OES_EGL_image_external : require
   324    327   #precision
   325    328   uniform vec3 u_LightPos;        // The position of the light in eye space.
   326    329   uniform samplerExternalOES u_Texture;
   327    330   uniform float u_Ambient;        // ambient lighting level
          331  +uniform vec4 u_Colorad;         // color bias for texture
   328    332    
   329    333   varying vec3 v_Position;        // Interpolated position for this fragment.
   330    334   varying vec4 v_Color;           // This is the color from the vertex shader interpolated across the
   331    335                                   // triangle per fragment.
   332    336   varying vec3 v_Normal;          // Interpolated normal for this fragment.
   333    337   varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.
   334    338   void main() {
................................................................................
   354    358   
   355    359   : clear ( -- )
   356    360       GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT or glClear ;
   357    361   
   358    362   : sf,  ( float -- )  here 1 sfloats allot sf! ;
   359    363   : sf!+ ( float addr -- addr' )  dup sf! sfloat+ ;
   360    364   
          365  +Create z-bias
          366  +0e sf, 0e sf, 0e sf, 0e sf,
          367  +Create 1-bias
          368  +1e sf, 1e sf, 1e sf, 0e sf,
          369  +
   361    370   Create unit-matrix
   362    371   1.0e sf, 0.0e sf, 0.0e sf, 0.0e sf,
   363    372   0.0e sf, 1.0e sf, 0.0e sf, 0.0e sf,
   364    373   0.0e sf, 0.0e sf, 1.0e sf, 0.0e sf,
   365    374   0.0e sf, 0.0e sf, 0.0e sf, 1.0e sf,
   366    375   
   367    376   unit-matrix 12 sfloats + Constant x-pos
................................................................................
   381    390   	I 4 sfloats bounds DO
   382    391   	    I sf@ f.
   383    392   	1 sfloats +LOOP cr
   384    393       4 sfloats +LOOP ;
   385    394   
   386    395   : set-matrix ( addr handle -- ) swap >r
   387    396       1 false r> glUniformMatrix4fv ;
          397  +
          398  +: set-color+ ( addr -- )  Coloradd 1 rot glUniform4fv ;
   388    399   
   389    400   : >ortho { f: near f: far f: left f: right f: top f: bottom -- }
   390    401       ap-matrix
   391    402       near f2* right left f- f/ sf!+ 0e sf!+ 0e sf!+ 0e sf!+
   392    403       0e sf!+ near f2* top bottom f- f/ sf!+ 0e sf!+ 0e sf!+
   393    404       right left f+ right left f- f/ sf!+
   394    405       top bottom f+ top bottom f- f/ sf!+
................................................................................
   486    497       GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
   487    498       program glUseProgram
   488    499       program "u_MVPMatrix\0" drop glGetUniformLocation to MVPMatrix
   489    500       program "u_MVMatrix\0" drop glGetUniformLocation to MVMatrix
   490    501       program "u_LightPos\0" drop glGetUniformLocation to LightPos
   491    502       program "u_Texture\0" drop glGetUniformLocation to Texture
   492    503       program "u_Ambient\0" drop glGetUniformLocation to Ambient
          504  +    program "u_Coloradd\0" drop glGetUniformLocation to Coloradd
   493    505       GL_UNPACK_ALIGNMENT 1 glPixelStorei
   494    506       GL_TEXTURE0 glActiveTexture
   495    507       none-tex no-texture
   496    508       Texture 0 glUniform1i
   497    509       Ambient 1 ambient% glUniform1fv
   498    510       LightPos 0.0e 0.0e -0.3e glUniform3f
          511  +    z-bias set-color+
   499    512       .01e 100e dpy-w @ dpy-h @ min s>f f2/ 100 fm* >ap ;
   500    513   
   501    514   : 2d-vertex ( index addr -- ) >r
   502    515       dup 2 GL_FLOAT  0 0 r> glVertexAttribPointer
   503    516       glEnableVertexAttribArray ;
   504    517   
   505    518   : 3d-vertex ( index addr -- ) >r

Added gles2/widgets-test.fs.

            1  +\ simple tests for widgets code
            2  +
            3  +require widgets.fs
            4  +
            5  +also minos
            6  +
            7  +frame new value f1
            8  +frame new value f2
            9  +frame new value f3
           10  +frame new value f4
           11  +frame new value f5
           12  +frame new value f6
           13  +text new value f7
           14  +text new value f8
           15  +f1 >o rdrop
           16  +0 x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
           17  +32 border ! $FFFFFFFF frame-color !
           18  +button2
           19  +
           20  +f2 >o rdrop
           21  +dpy-w @ 2/ x ! 0 y ! dpy-w @ 2/ w ! dpy-h @ 19 20 */ d !
           22  +32 border ! $FF7FFFFF frame-color !
           23  +button3
           24  +
           25  +f3 >o rdrop
           26  +0 x ! dpy-h @ 2/ y ! dpy-w @ 2/ w ! dpy-h @ 2/ 2/ d !
           27  +16 border ! $FFFF7FFF frame-color !
           28  +button1
           29  +
           30  +f4 >o rdrop
           31  +0 x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
           32  +32 border ! $FF7F7FFF frame-color !
           33  +button1
           34  +
           35  +f5 >o rdrop
           36  +dpy-w @ 4 / x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
           37  +8 border ! $7FFF7FFF frame-color !
           38  +button1
           39  +
           40  +f6 >o rdrop
           41  +dpy-w @ 4 / x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
           42  +16 border ! $7FFFFFFF frame-color !
           43  +button2
           44  +
           45  +also freetype-gl
           46  +48e FConstant fontsize#
           47  +atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
           48  +[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
           49  +[THEN]
           50  +fontsize# texture_font_new Value font1
           51  +
           52  +atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
           53  +[ELSE] "/usr/share/fonts/truetype/gkai00mp.ttf\0" drop
           54  +[THEN]
           55  +fontsize# texture_font_new Value font2
           56  +previous
           57  +
           58  +f7 >o rdrop
           59  +8 x ! dpy-h @ 4 / y ! "Dös isch a Tägscht!" text-string $!
           60  +$884400FF text-color !  font1 text-font !
           61  +
           62  +f8 >o rdrop
           63  +8 x ! dpy-h @ 5 8 */ y ! "这是一个文本:在德语说" text-string $!
           64  +$004488FF text-color !  font2 text-font !
           65  +
           66  +<draw0 draw0>
           67  +<draw1
           68  +f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
           69  +f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
           70  +draw1>
           71  +<draw2
           72  +f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
           73  +f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
           74  +draw2>
           75  +sync

Added gles2/widgets.fs.

            1  +\ MINOS2 widget basis
            2  +
            3  +\ A MINOS2 widget is composed of drawable elements, boxes and actors.
            4  +\ to make things easier, neither drawable elements nor boxes need an actor.
            5  +
            6  +require gl-helper.fs
            7  +require ftgl-helper.fs
            8  +require mini-oof2.fs
            9  +
           10  +get-current
           11  +also [IFDEF] android android [THEN]
           12  +also opengl
           13  +
           14  +helper-init
           15  +
           16  +vocabulary minos  also minos definitions
           17  +
           18  +0 Value layer \ drawing layer
           19  +
           20  +object class
           21  +    field: caller-w
           22  +    method clicked
           23  +    method keyed
           24  +    method inside?
           25  +    method focus
           26  +    method defocus
           27  +    method show
           28  +    method hide
           29  +    method get
           30  +    method set
           31  +    method show-you
           32  +end-class actor
           33  +
           34  +object class
           35  +    field: next-w
           36  +    field: parent-w
           37  +    field: x
           38  +    field: y
           39  +    field: w
           40  +    field: h \ above baseline
           41  +    field: d \ below baseline
           42  +    method draw ( -- )
           43  +    method hglue
           44  +    method vglue
           45  +    method hglue@ \ cached variant
           46  +    method vglue@ \ cached variant
           47  +    method xywh
           48  +    method xywhd
           49  +    method !size \ set your own size
           50  +end-class widget
           51  +
           52  +:noname x @ y @ h @ - w @ h @ d @ + ; widget to xywh
           53  +:noname x @ y @ w @ h @ d @ ; widget to xywhd
           54  +' noop widget to !size
           55  +
           56  +widget class
           57  +    field: child-w
           58  +    field: act
           59  +    method resized
           60  +    method map
           61  +end-class box
           62  +
           63  +tex: style-tex \ 8 x 8 subimages, each sized 128x128
           64  +style-tex 1024 dup rgba-newtex
           65  +
           66  +\ tile widget
           67  +
           68  +widget class
           69  +    field: frame#
           70  +    field: frame-color
           71  +end-class tile
           72  +
           73  +8 Value style-w#
           74  +8 Value style-h#
           75  +
           76  +: #>st ( x y frame -- ) \ using frame#
           77  +    style-w# /mod
           78  +    s>f f+ style-w# fm/ fswap
           79  +    s>f f+ style-h# fm/ fswap >st ;
           80  +
           81  +: draw-rectangle { f: x1 f: y1 f: x2 f: y2 -- }
           82  +    i? >v
           83  +    x1 y2 >xy frame-color @ rgba>c n> 0e 1e frame# @ #>st v+
           84  +    x2 y2 >xy frame-color @ rgba>c n> 1e 1e frame# @ #>st v+
           85  +    x2 y1 >xy frame-color @ rgba>c n> 1e 0e frame# @ #>st v+
           86  +    x1 y1 >xy frame-color @ rgba>c n> 0e 0e frame# @ #>st v+
           87  +    v> dup i, dup 1+ i, dup 2 + i, dup i, dup 2 + i, 3 + i, ;
           88  +: tile-draw ( -- ) layer 1 <> ?EXIT
           89  +    xywh { x y w h }
           90  +    x s>f y s>f x w + s>f y h + s>f
           91  +    draw-rectangle GL_TRIANGLES draw-elements ;
           92  +
           93  +' tile-draw tile is draw
           94  +
           95  +\ frame widget
           96  +
           97  +tile class
           98  +    field: border
           99  +end-class frame
          100  +
          101  +Create button-st  0e sf, 0.25e sf, 0.75e sf, 1e sf,
          102  +DOES>  swap sfloats + sf@ ;
          103  +: button-border ( n -- gray )  dup 2/ xor ;
          104  +: >border ( x b i w -- r ) >r
          105  +    button-border >r
          106  +    r@ 1 and 0= IF drop 0       THEN
          107  +    r> 2 and    IF negate r@ +  THEN  + s>f  rdrop ;
          108  +
          109  +: frame-draw ( -- ) layer 1 <> ?EXIT
          110  +    frame# @ frame-color @ border @ xywh { f c b x y w h }
          111  +    i>off >v
          112  +    4 0 DO
          113  +	4 0 DO
          114  +	    x b I w >border  y b J h >border >xy
          115  +	    c rgba>c  n>
          116  +	    I button-st J button-st f #>st v+
          117  +	LOOP
          118  +    LOOP
          119  +    v>
          120  +    9 0  DO
          121  +	4 quad  1 I 3 mod 2 = - i-off +!
          122  +    LOOP
          123  +; ' frame-draw frame to draw
          124  +
          125  +\ text widget
          126  +
          127  +widget class
          128  +    field: text-string
          129  +    field: text-font
          130  +    field: text-color
          131  +end-class text
          132  +
          133  +: text-draw ( -- ) layer 2 <> ?EXIT
          134  +    x @ s>f penxy sf!  y @ s>f penxy sfloat+ sf!
          135  +    text-font @ to font  text-color @ color !
          136  +    text-string $@ render-string ;
          137  +: text-!size ( -- )
          138  +    text-string $@ layout-string
          139  +    f>s d ! f>s h ! f>s w ! ;
          140  +' text-draw text to draw
          141  +' text-!size text to !size
          142  +
          143  +\ draw wrapper
          144  +
          145  +: <draw0 ( -- )  0 to layer
          146  +    -1e 1e >apxy
          147  +    .01e 100e 100e >ap
          148  +    0.01e 0.02e 0.15e 1.0e glClearColor
          149  +    Ambient 1 ambient% glUniform1fv ;
          150  +: draw0> ( -- ) clear v0 i0 ;
          151  +
          152  +: <draw1 ( -- )  1 to layer
          153  +    z-bias set-color+
          154  +    program glUseProgram  style-tex ;
          155  +: draw1> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;
          156  +
          157  +: <draw2 ( -- )  2 to layer
          158  +    1-bias set-color+
          159  +    program glUseProgram  atlas-tex ;
          160  +: draw2> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;
          161  +
          162  +Variable style-i#
          163  +
          164  +: load-style ( addr u -- n )  style-tex
          165  +    style-i# @ 8 /mod 128 * >r 128 * r> 2swap load-subtex 2drop
          166  +    style-i# @ 1 style-i# +! ;
          167  +: style: load-style Create , DOES> @ frame# ! ;
          168  +
          169  +"button.png" style: button1
          170  +"button2.png" style: button2
          171  +"button3.png" style: button3
          172  +
          173  +previous previous previous set-current

Changes to widgets-test.fs.

     1      1   \ simple tests for widgets code
     2      2   
     3      3   require widgets.fs
     4      4   
     5      5   also minos
     6      6   
     7         -<draw
     8      7   frame new value f1
     9      8   frame new value f2
    10      9   frame new value f3
    11     10   frame new value f4
    12     11   frame new value f5
    13     12   frame new value f6
           13  +text new value f7
           14  +text new value f8
    14     15   f1 >o rdrop
    15     16   0 x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
    16     17   32 border ! $FFFFFFFF frame-color !
    17     18   button2
    18         -draw
           19  +
    19     20   f2 >o rdrop
    20     21   dpy-w @ 2/ x ! 0 y ! dpy-w @ 2/ w ! dpy-h @ 19 20 */ d !
    21     22   32 border ! $FF7FFFFF frame-color !
    22     23   button3
    23         -draw
           24  +
    24     25   f3 >o rdrop
    25     26   0 x ! dpy-h @ 2/ y ! dpy-w @ 2/ w ! dpy-h @ 2/ 2/ d !
    26     27   16 border ! $FFFF7FFF frame-color !
    27     28   button1
    28         -draw
           29  +
    29     30   f4 >o rdrop
    30     31   0 x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
    31     32   32 border ! $FF7F7FFF frame-color !
    32     33   button1
    33         -draw
           34  +
    34     35   f5 >o rdrop
    35     36   dpy-w @ 4 / x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
    36     37   8 border ! $7FFF7FFF frame-color !
    37     38   button1
    38         -draw
           39  +
    39     40   f6 >o rdrop
    40     41   dpy-w @ 4 / x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
    41     42   16 border ! $7FFFFFFF frame-color !
    42     43   button2
    43         -draw draw>
           44  +
           45  +also freetype-gl
           46  +48e FConstant fontsize#
           47  +atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
           48  +[ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 
           49  +[THEN]
           50  +fontsize# texture_font_new Value font1
    44     51   
           52  +atlas [IFDEF] android  "/system/fonts/DroidSansFallback.ttf\0" drop
           53  +[ELSE] "/usr/share/fonts/truetype/gkai00mp.ttf\0" drop
           54  +[THEN]
           55  +fontsize# texture_font_new Value font2
    45     56   previous
           57  +
           58  +f7 >o rdrop
           59  +8 x ! dpy-h @ 4 / y ! "Dös isch a Tägscht!" text-string $!
           60  +$884400FF text-color !  font1 text-font !
           61  +
           62  +f8 >o rdrop
           63  +8 x ! dpy-h @ 5 8 */ y ! "这是一个文本:在德语说" text-string $!
           64  +$004488FF text-color !  font2 text-font !
           65  +
           66  +<draw0 draw0>
           67  +<draw1
           68  +f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
           69  +f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
           70  +draw1>
           71  +<draw2
           72  +f1 >o draw o> f7 >o draw o> f2 >o draw o> f3 >o draw o>
           73  +f8 >o draw o> f4 >o draw o> f5 >o draw o> f6 >o draw o>
           74  +draw2>
           75  +sync

Changes to widgets.fs.

    11     11   also [IFDEF] android android [THEN]
    12     12   also opengl
    13     13   
    14     14   helper-init
    15     15   
    16     16   vocabulary minos  also minos definitions
    17     17   
           18  +0 Value layer \ drawing layer
           19  +
    18     20   object class
    19     21       field: caller-w
    20     22       method clicked
    21     23       method keyed
    22     24       method inside?
    23     25       method focus
    24     26       method defocus
................................................................................
    33     35       field: next-w
    34     36       field: parent-w
    35     37       field: x
    36     38       field: y
    37     39       field: w
    38     40       field: h \ above baseline
    39     41       field: d \ below baseline
    40         -    method draw
           42  +    method draw ( -- )
    41     43       method hglue
    42     44       method vglue
    43     45       method hglue@ \ cached variant
    44     46       method vglue@ \ cached variant
    45     47       method xywh
    46     48       method xywhd
           49  +    method !size \ set your own size
    47     50   end-class widget
    48     51   
    49     52   :noname x @ y @ h @ - w @ h @ d @ + ; widget to xywh
    50     53   :noname x @ y @ w @ h @ d @ ; widget to xywhd
           54  +' noop widget to !size
    51     55   
    52     56   widget class
    53     57       field: child-w
    54     58       field: act
    55     59       method resized
    56     60       method map
    57     61   end-class box
    58     62   
    59     63   tex: style-tex \ 8 x 8 subimages, each sized 128x128
    60     64   style-tex 1024 dup rgba-newtex
           65  +
           66  +\ tile widget
    61     67   
    62     68   widget class
    63     69       field: frame#
    64     70       field: frame-color
    65     71   end-class tile
    66     72   
    67     73   8 Value style-w#
................................................................................
    75     81   : draw-rectangle { f: x1 f: y1 f: x2 f: y2 -- }
    76     82       i? >v
    77     83       x1 y2 >xy frame-color @ rgba>c n> 0e 1e frame# @ #>st v+
    78     84       x2 y2 >xy frame-color @ rgba>c n> 1e 1e frame# @ #>st v+
    79     85       x2 y1 >xy frame-color @ rgba>c n> 1e 0e frame# @ #>st v+
    80     86       x1 y1 >xy frame-color @ rgba>c n> 0e 0e frame# @ #>st v+
    81     87       v> dup i, dup 1+ i, dup 2 + i, dup i, dup 2 + i, 3 + i, ;
    82         -: tile-draw ( -- )
           88  +: tile-draw ( -- ) layer 1 <> ?EXIT
    83     89       xywh { x y w h }
    84     90       x s>f y s>f x w + s>f y h + s>f
    85     91       draw-rectangle GL_TRIANGLES draw-elements ;
    86     92   
    87     93   ' tile-draw tile is draw
           94  +
           95  +\ frame widget
    88     96   
    89     97   tile class
    90     98       field: border
    91     99   end-class frame
    92    100   
    93    101   Create button-st  0e sf, 0.25e sf, 0.75e sf, 1e sf,
    94    102   DOES>  swap sfloats + sf@ ;
    95    103   : button-border ( n -- gray )  dup 2/ xor ;
    96    104   : >border ( x b i w -- r ) >r
    97    105       button-border >r
    98    106       r@ 1 and 0= IF drop 0       THEN
    99    107       r> 2 and    IF negate r@ +  THEN  + s>f  rdrop ;
   100    108   
   101         -: frame-draw ( -- )
          109  +: frame-draw ( -- ) layer 1 <> ?EXIT
   102    110       frame# @ frame-color @ border @ xywh { f c b x y w h }
   103    111       i>off >v
   104    112       4 0 DO
   105    113   	4 0 DO
   106    114   	    x b I w >border  y b J h >border >xy
   107    115   	    c rgba>c  n>
   108    116   	    I button-st J button-st f #>st v+
................................................................................
   110    118       LOOP
   111    119       v>
   112    120       9 0  DO
   113    121   	4 quad  1 I 3 mod 2 = - i-off +!
   114    122       LOOP
   115    123   ; ' frame-draw frame to draw
   116    124   
   117         -: <draw ( -- )  v0 i0
   118         -    program glUseProgram  style-tex
          125  +\ text widget
          126  +
          127  +widget class
          128  +    field: text-string
          129  +    field: text-font
          130  +    field: text-color
          131  +end-class text
          132  +
          133  +: text-draw ( -- ) layer 2 <> ?EXIT
          134  +    x @ s>f penxy sf!  y @ s>f penxy sfloat+ sf!
          135  +    text-font @ to font  text-color @ color !
          136  +    text-string $@ render-string ;
          137  +: text-!size ( -- )
          138  +    text-string $@ layout-string
          139  +    f>s d ! f>s h ! f>s w ! ;
          140  +' text-draw text to draw
          141  +' text-!size text to !size
          142  +
          143  +\ draw wrapper
          144  +
          145  +: <draw0 ( -- )  0 to layer
   119    146       -1e 1e >apxy
   120    147       .01e 100e 100e >ap
   121         -    0.6e 0.4e 0.2e 1.0e glClearColor clear
          148  +    0.01e 0.02e 0.15e 1.0e glClearColor
   122    149       Ambient 1 ambient% glUniform1fv ;
   123         -: draw> ( -- )  GL_TRIANGLES draw-elements sync v0 i0 ;
          150  +: draw0> ( -- ) clear v0 i0 ;
          151  +
          152  +: <draw1 ( -- )  1 to layer
          153  +    z-bias set-color+
          154  +    program glUseProgram  style-tex ;
          155  +: draw1> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;
          156  +
          157  +: <draw2 ( -- )  2 to layer
          158  +    1-bias set-color+
          159  +    program glUseProgram  atlas-tex ;
          160  +: draw2> ( -- )  GL_TRIANGLES draw-elements v0 i0 ;
   124    161   
   125    162   Variable style-i#
   126    163   
   127    164   : load-style ( addr u -- n )  style-tex
   128    165       style-i# @ 8 /mod 128 * >r 128 * r> 2swap load-subtex 2drop
   129    166       style-i# @ 1 style-i# +! ;
   130    167   : style: load-style Create , DOES> @ frame# ! ;
   131    168   
   132    169   "button.png" style: button1
   133    170   "button2.png" style: button2
   134    171   "button3.png" style: button3
   135    172   
   136    173   previous previous previous set-current