------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 199x by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- Demo of the raster widget

class DEMO_RASTER is
   -- The raster widget provides a much faster, lower level way of
   -- drawing to the screen. It is not as sophisticated as the canvas
   -- widget, but since it avoids silly tcl string conversions, it can
   -- be orders of magnitude faster and is close to the speed of 
   -- raw X lib calls
    
   include GUI_UTIL;
    
   attr x0, y0: FLTD;
    
   init is
      raster ::= #TK_RASTER(root_window, "test_raster", 
			    TK_RASTER_CFG::std, TK_PACK::top);
      raster.bind_action(TK_BUTTON_EVENT::Press+2,
			 bind(make_demo(raster, _)));
      raster.bind_action(TK_BUTTON_EVENT::Press+1,
			 bind(save_coords(_)));
      -- raster.bind(EVENT::Motion.Mouse_1, bind(draw(raster, _)));
      raster.bind_action(TK_BUTTON_EVENT::Release+1, bind(draw(raster, _)));
   end;
    
   save_coords(cb_info: TK_RASTER_CB) is
      #ERR+"Save coordinates\n";
      x0 := cb_info.x;
      y0 := cb_info.y;
      #OUT+"Start of square:"+x0+","+y0+"\n";
   end;
    
   draw(raster: TK_RASTER, cb_info: TK_RASTER_CB) is
      raster.draw_rectangle(x0, y0, cb_info.x, cb_info.y);
      raster.display;
   end;
    
   make_demo(raster: TK_RASTER, dummy_info: TK_RASTER_CB) is
      #ERR+"Make demo\n";
      fg_blue ::= raster.create_env.foreground("blue");
      fg_green ::= raster.create_env.foreground("green");
	
      fg_blue.activate;
      loop i ::= 100.times!; 
	 loop j ::= 100.times!;
	    raster.draw_point(i.fltd, j.fltd);
	 end;
      end;
	
      loop n ::= 10.times!;
	 if n.is_even then raster.set_env(fg_blue);
	 else raster.set_env(fg_green) end;
	 loop i ::= 100.times!; 
	    loop j ::= 100.times!;
	       raster.draw_point((n+i+10).fltd, (n+j+10).fltd);
	    end;
	 end;
      end;
	
      raster.display;
   end; -- make_demo
    
end; 
