[q-lang-cvs] q/modules/magick/examples magicktest.q,1.1,1.2 sprite.q,1.1,1.2
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-23 01:15:06
|
Update of /cvsroot/q-lang/q/modules/magick/examples In directory sc8-pr-cvs1:/tmp/cvs-serv23691/modules/magick/examples Modified Files: magicktest.q sprite.q Log Message: major overhaul of GGI interface; see ChangeLog for details Index: magicktest.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/magicktest.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** magicktest.q 16 Dec 2003 19:11:16 -0000 1.1 --- magicktest.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 1,10 **** import ggi, magick; ! /* show NAME INFO: show an image (designated by a valid ImageMagick source ! specification NAME and an INFO structure, see magick.q for details) in a ! GGI visual. Returns the created visual. */ ! show NAME INFO = display IMG where IMG:Image = read_image NAME INFO; /* The simple case: our image is opaque. In this case we just render it on a --- 1,16 ---- + /* $Id$ + magicktest.q: simple magick demonstration program, shows how to render an + image on a GGI visual */ + import ggi, magick; ! /* show NAME INFO: show an image in a GGI visual. Returns the created visual. ! For most purposes, NAME is just the name of an image file, and INFO is ! (). However, using appropriate NAME and INFO values, you can actually do a ! lot more than just displaying an image file, see magick.q and ! ImageMagick(1) for details. */ ! show NAME INFO = display IMG where IMG:Image = read_image NAME INFO; /* The simple case: our image is opaque. In this case we just render it on a *************** *** 16,20 **** where (W,H|_) = image_info IMG, ! VIS = ggi_open "x:-keepcursor", () = ggi_set_mode VIS (sprintf "%dx%d" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) --- 22,26 ---- where (W,H|_) = image_info IMG, ! VIS = ggi_open (sprintf "%s:-keepcursor" target), () = ggi_set_mode VIS (sprintf "%dx%d" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) *************** *** 22,28 **** if is_opaque_image IMG; ! /* The complicated case: our image has transparency. In this case we draw the ! image over a background. To these ends, we first render the image on a ! memory visual and crossblit that to the target visual on the screen. */ def BACK = magick_pixel "gray"; --- 28,33 ---- if is_opaque_image IMG; ! /* The complicated case: our image has transparency. In this case we clad the ! visual with an alpha buffer and draw the image over a background. */ def BACK = magick_pixel "gray"; *************** *** 30,52 **** display IMG ! = ggi_put_box MEM (0,0) (W,H) PIXELS || ! /* we need to also set the alpha values since these aren't transferred ! by ggi_put_box */ ! ggi_put_alpha_box MEM (0,0) (W,H) ALPHA || ! ggi_set_background VIS BACK || ggi_clear VIS || ! ggi_cross_blit MEM (0,0) (W,H) VIS (0,0) || ggi_flush VIS || ! VIS where (W,H|_) = image_info IMG, ! VIS = ggi_open "x:-keepcursor", ! () = ggi_set_mode VIS (sprintf "%dx%d.A8" (W,H)), ! () = ggi_set_alpha_flags VIS (ggi_get_alpha_flags VIS or GGI_BUF_PUTGET), ! (_,_,_,_,_,_,_,_,D,S) = ! sscanf (ggi_get_mode VIS) "%dx%d.V%dx%d.F%d.D%dx%d.[%c%d/%d]", ! MEM = ggi_open "memory", ! () = ggi_set_mode MEM (sprintf "%dx%d.[C%d/%d].A8" (W,H,D,S)), ! () = ggi_set_alpha_flags MEM (ggi_get_alpha_flags MEM or GGI_BUF_PUTGET), ! PIXELS = get_image_pixels IMG (0,0) (W,H), ! ALPHA = get_image_alpha IMG (0,0) (W,H) otherwise; --- 35,50 ---- display IMG ! = ggi_set_background VIS BACK || ggi_clear VIS || ! ggi_put_box VIS (0,0) (W,H) PIXELS || ggi_flush VIS || VIS where (W,H|_) = image_info IMG, ! VIS = ggi_open (sprintf "%s:-keepcursor" target), ! () = ggi_set_mode VIS (sprintf "%dx%d.A16" (W,H)), ! PIXELS = get_image_pixels IMG (0,0) (W,H) otherwise; + + /* Driver for display visual. */ + + target = "directx" if pos "mingw" sysinfo >= 0; + = "x" otherwise; Index: sprite.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/sprite.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sprite.q 16 Dec 2003 19:11:16 -0000 1.1 --- sprite.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 1,5 **** ! /* sprite.q: This is a tiny test program demonstrating how to move an image ! with transparency over a background image. 12-12-03 AG */ /* To use, evaluate `sprite', click left in the GGI window to show the sprite --- 1,6 ---- ! /* $Id$ ! sprite.q: This is a tiny test program demonstrating how to move an image ! with transparency over a background image. */ /* To use, evaluate `sprite', click left in the GGI window to show the sprite *************** *** 10,14 **** import ggi, magick; ! /* globals */ def --- 11,15 ---- import ggi, magick; ! /* Globals, infrastructure code. */ def *************** *** 19,24 **** GGI display visual */ (W,H|_) = image_info BACK_IMG, ! VIS = ggi_open "x:-keepcursor", _ = ggi_set_mode VIS (sprintf "%dx%d.A8" (W,H)) || ggi_set_flags VIS GGI_FLAG_ASYNC || ggi_put_box VIS (0,0) (W,H) (get_image_pixels BACK_IMG (0,0) (W,H)) || --- 20,26 ---- GGI display visual */ (W,H|_) = image_info BACK_IMG, ! VIS = ggi_open (sprintf "%s:-keepcursor" target), _ = ggi_set_mode VIS (sprintf "%dx%d.A8" (W,H)) || + /* make sure to set async mode here to reduce flickering */ ggi_set_flags VIS GGI_FLAG_ASYNC || ggi_put_box VIS (0,0) (W,H) (get_image_pixels BACK_IMG (0,0) (W,H)) || *************** *** 35,63 **** only have to store the pixels of the background image) */ _ = ggi_set_mode BACK (sprintf "%dx%d.[C%d/%d]" (W,H,D,S)), ! /* render the sprite image in another memory visual with alpha buffer, which ! will be crossblitted to the display */ ! SPRITE = ggi_open "memory", ! _ = ggi_set_mode SPRITE (sprintf "%dx%d.[C%d/%d].A8" (W,H,D,S)) || ! /* make sure GGI_BUF_PUTGET is set to enable full alpha blending */ ! ggi_set_alpha_flags SPRITE (ggi_get_alpha_flags SPRITE or GGI_BUF_PUTGET) || ! ggi_put_box SPRITE (0,0) (W,H) (get_image_pixels SPRITE_IMG (0,0) (W,H)) || ! ggi_put_alpha_box SPRITE (0,0) (W,H) ! (get_image_alpha SPRITE_IMG (0,0) (W,H)); ! /* save background pixels in the BACK visual */ save_back (X,Y) = ggi_put_box BACK (0,0) (W,H) (ggi_get_box VIS (X,Y) (W,H)); ! /* restore background from the BACK visual */ restore_back (X,Y) = ggi_put_box VIS (X,Y) (W,H) (ggi_get_box BACK (0,0) (W,H)); ! /* draw the sprite (crossblit from SPRITE visual) */ ! draw_sprite (X,Y) = ggi_cross_blit SPRITE (0,0) (W,H) VIS (X,Y); ! /* show, hide and move the sprite on the display */ show_sprite (X,Y) = save_back (X,Y) || --- 37,64 ---- only have to store the pixels of the background image) */ _ = ggi_set_mode BACK (sprintf "%dx%d.[C%d/%d]" (W,H,D,S)), ! /* get the pixels of the sprite image */ ! SPRITE = get_image_pixels SPRITE_IMG (0,0) (W,H); ! /* Driver for the display visual. We use the DirectX target on Windows, and ! assume the X11 target everywhere else. */ ! ! target = "directx" if pos "mingw" sysinfo >= 0; ! = "x" otherwise; ! ! /* Save background pixels in the BACK visual. */ save_back (X,Y) = ggi_put_box BACK (0,0) (W,H) (ggi_get_box VIS (X,Y) (W,H)); ! /* Restore background from the BACK visual. */ restore_back (X,Y) = ggi_put_box VIS (X,Y) (W,H) (ggi_get_box BACK (0,0) (W,H)); ! /* Draw the sprite. */ ! draw_sprite (X,Y) = ggi_put_box VIS (X,Y) (W,H) SPRITE; ! /* Show, hide and move the sprite on the display. */ show_sprite (X,Y) = save_back (X,Y) || *************** *** 73,81 **** ggi_flush VIS; ! /* the main function */ sprite = loop () (); ! /* the input loop; take appropriate actions on mouse events */ loop STATE POS = process STATE POS (ggi_read VIS GGI_EM_ALL); --- 74,82 ---- ggi_flush VIS; ! /* The main function. */ sprite = loop () (); ! /* The input loop; take appropriate actions on mouse events. */ loop STATE POS = process STATE POS (ggi_read VIS GGI_EM_ALL); |