demo1.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- demo.sa,v 1.1 1995/11/15 03:34:51 gomes Exp
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.


class DEMO1

class DEMO1 is 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_CTAG; -- Creating a tag for future reference tag2 ::= #TK_CTAG; -- 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_CTAG; c.draw_text("Test",200.0,200.0,|text_tag|,void); -- Draw some points rconfig ::= #TK_RECT_CFG; rconfig.fill_color := "green"; rtag ::= #TK_CTAG; 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_item(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_item(TK_EVENT::Widget_enter,tag1,bind(do_something(tw,_))); end; draw_point(c: TK_CANVAS,x,y: FLT,tag:ARRAY{TK_CTAG},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_CANVAS_CB) 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_CANVAS_CB) 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;