------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 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>  <--------------

-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>

class DEMO1 is
   -- Strange and meaningless demo. Shows two lines on a canvas.
   -- Clicking or entering causes the event information to be
   -- printed in the other window
   
   include GUI_UTIL;
   
   init is
      c ::= #TK_CANVAS;
      -- Below are examples of creating items with more complex configurations
      -- --different colors, tags for callbacks etc.

      -- Example of setting line attributes before drawing the line
      line_config ::=  #TK_LINE_CFG;
      line_config.arrow(false,true).fill("blue");
      tag1 ::= #TK_CANVAS_TAG; -- Creating a tag for future reference
      tag2 ::= #TK_CANVAS_TAG; -- Creating  tag2, for future reference
      c.draw_line(0.0,0.0,100.0,100.0,|tag1|,line_config); -- supply tag array
      c.draw_line(0.0,100.0,100.0,0.0,|tag1|,line_config); -- another line

      TK::update;
      text_tag ::= #TK_CANVAS_TAG;
      c.draw_text("Test",200.0,200.0,|text_tag|,void);

      -- Draw some points
      rconfig ::= #TK_RECT_CFG;
      rconfig.fill_color := "green";
      rtag ::= #TK_CANVAS_TAG;
      draw_point(c,15.0,15.0,|rtag|,rconfig);
      draw_point(c,100.0,100.0,|rtag|,rconfig);
      
      tw ::= #TK_TEXT;
      -- An example of binding a callback. 
      tw+"This is a pretty silly demo\n";
      tw+"Either enter or click on a line and something will be printed\n";
      -- Bind the print something function to a button click on all items
      -- with a tag of "tag1" i.e. both lines
      c.bind_event(TK_BUTTON_EVENT::B1,tag1,bind(print_something(tw,_)));

      -- Bind the do_something function to all enter events on items with
      -- the tag tag1, i.e. both lines
      c.bind_event(TK_EVENT::Widget_enter,tag1,bind(do_something(tw,_)));
   end;
   
   draw_point(c: TK_CANVAS,x,y: FLT,tag:ARRAY{TK_CANVAS_TAG},config:TK_RECT_CFG) is
      c.draw_rect(x,y,x+1.0,y+1.0,tag,config);
   end;
   
   print_something(w: TK_TEXT,b: TK_EVENT_INFO) is
      -- The first argument is the action id. 
      #ERR+"Reached here!";
      #ERR+b.str;
      w+"Button press action:"+b.str+"\n";
   end;
   
   do_something(w: TK_TEXT,b: TK_EVENT_INFO) is
      -- The first argument is the action id. 
      #OUT+"enter action: Going to do something!=n";
      #OUT+b.str+"\n";
      w+"Enter action:"+b.str+"\n";
      #OUT+"dunno what, though.\n";
   end;

end; 
-------------------------------------------------------------------

