[q-lang-cvs] q/modules/ggi/examples font_test.q,1.1,1.2
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-20 03:17:15
|
Update of /cvsroot/q-lang/q/modules/ggi/examples In directory sc8-pr-cvs1:/tmp/cvs-serv2798/examples Modified Files: font_test.q Log Message: reworked font example Index: font_test.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/font_test.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** font_test.q 19 Dec 2003 21:37:17 -0000 1.1 --- font_test.q 20 Dec 2003 03:17:06 -0000 1.2 *************** *** 7,16 **** import ggi; ! def FONT = "/usr/X11R6/lib/X11/fonts/truetype/times.ttf", FONT_METRIC = (), ! INDEX = 0, SIZE = 50, RES = 100, RED = (0xffff,0,0), GREEN = (0,0xffff,0), BLUE = (0,0,0xffff), BLACK = (0,0,0), WHITE = (0xffff,0xffff,0xffff); def VIS = ggi_open (), _ = ggi_set_mode VIS "640x480" || ggi_set_foreground VIS WHITE || --- 7,24 ---- import ggi; ! def // name of font file; edit this as needed ! FONT = "/usr/X11R6/lib/X11/fonts/truetype/times.ttf", ! // for some font types you also have to set a font metric file here FONT_METRIC = (), ! // face index (0 will do for most purposes) ! INDEX = 0, ! // pt size and display resolution in pixels ! SIZE = 50, RES = 100, ! // some colors to play with RED = (0xffff,0,0), GREEN = (0,0xffff,0), BLUE = (0,0,0xffff), BLACK = (0,0,0), WHITE = (0xffff,0xffff,0xffff); + // set up the display + def VIS = ggi_open (), _ = ggi_set_mode VIS "640x480" || ggi_set_foreground VIS WHITE || *************** *** 19,27 **** ggi_set_char_size VIS SIZE RES; ! // set the font size size SIZE = ggi_set_char_size VIS SIZE RES; ! // set antialiasing mode antialias FLAG = ggi_set_antialias VIS FLAG; --- 27,44 ---- ggi_set_char_size VIS SIZE RES; ! // set foreground and background color ! ! fg COL = ggi_set_foreground VIS COL; ! bg COL = ggi_set_background VIS COL; ! ! // clear the display ! ! clr = ggi_clear VIS; ! ! // change the font size size SIZE = ggi_set_char_size VIS SIZE RES; ! // change the antialiasing mode antialias FLAG = ggi_set_antialias VIS FLAG; *************** *** 32,39 **** = ggi_set_transform VIS VECT MATRIX; ! // print a sample of the current font ! test P MSG = ggi_puts VIS P MSG || ! // draw bounding box ggi_draw_hline VIS (0,Y) 640 || ggi_draw_hline VIS (0,Y+H-1) 640 || --- 49,56 ---- = ggi_set_transform VIS VECT MATRIX; ! // print text in the current font ! print P MSG = ggi_puts VIS P MSG || ! // indicate bounding box ggi_draw_hline VIS (0,Y) 640 || ggi_draw_hline VIS (0,Y+H-1) 640 || *************** *** 42,51 **** where (X,Y) = P, (W,H) = ggi_get_string_size VIS MSG; ! // set foreground and background color ! fg COL = ggi_set_foreground VIS COL; ! bg COL = ggi_set_background VIS COL; ! // clear the display ! clr = ggi_clear VIS; --- 59,95 ---- where (X,Y) = P, (W,H) = ggi_get_string_size VIS MSG; ! // center text at the given point ! center (X,Y) MSG ! = ggi_puts VIS P MSG || ! ggi_draw_hline VIS (X-10,Y) 20 || ! ggi_draw_vline VIS (X,Y-10) 20 ! where (W,H) = ggi_get_string_size VIS MSG, ! P = (X - W div 2, Y - H div 2); ! // rotate text around the given point ! rotate A (X,Y) MSG ! = transform (0,0) (cos A,-sin A,sin A, cos A) || ! center (X,Y) MSG; ! ! // a little demo: rotate a text around a point until key hit ! ! def PI = 4.0*atan 1.0, P = (320,240), MSG = "Hello, world!"; ! ! demo = // make sure that async mode is set ! ggi_set_flags VIS GGI_FLAG_ASYNC || ! writes "Hit any key in the GGI window to stop\n" || ! loop 0 || ! // reset flag to original state ! ggi_set_flags VIS FLAGS || ! // reset transform to default ! transform (0,0) (1,0,0,1) ! where FLAGS = ggi_get_flags VIS; ! ! loop K = ggi_getc VIS || () if ggi_kbhit VIS; ! = clr || rotate (K*PI/18) P MSG || ggi_flush VIS || ! // 0.02 = 50 fps, change this as necessary ! sleep 0.02 || ! // advance by PI/18 (= 10 degrees) ! loop (K+1 mod 16) otherwise; |