MODULE testimage;
(* simple test image program *)
(* Author: Andrew Tridgell, May 1998 *)

(* import the graphics routines *)
IMPORT Graph;

FROM Graph IMPORT 
  EventSet, Event;

VAR
  Handle1, Handle2 : INTEGER;
  AEvent : EventSet;
  LastX, LastY, X, Y : INTEGER;
  Drawing : BOOLEAN; (* are we currently drawing? *)

BEGIN (* testimage *)
      
  (* start up the graphics *)
  Graph.StartGraphics(280,190,TRUE);

  (* load 2 images from disk *)
  (* Handle1 := Graph.LoadImage("bg.xpm"); *)
  Handle2 := Graph.LoadImage("bdm.xpm");

  (* display the background on screen *)
  (* Graph.DisplayImage(Handle1, 0, 0); *)
  Graph.Display();
  
  Drawing := FALSE;

  REPEAT
    (* get an event *)
    Graph.WaitForEvent(EventSet{ButtonPress,ButtonRelease,Motion});
    AEvent := Graph.LastEvent();

    (* if we have drawn then restore *)
    IF Drawing THEN
	Graph.RestoreImage(Handle2);
    END;
    
    (* start drawing when they press a button *)
    IF ButtonPress IN AEvent THEN
      Drawing := TRUE;    
    END;  

    (* stop drawing when they press a button *)
    IF ButtonRelease IN AEvent THEN
      Drawing := FALSE;    
    END;  

    (* if drawing then put the image up *)
    IF Drawing THEN
	Graph.MousePosition(X,Y);
	Graph.PlaceImage(Handle2, X, Y);
	LastX := X;
	LastY := Y;
    END;
    
    Graph.Display();
  UNTIL (FALSE);

  (* never reached *)

  (* close the graphics window *)
  Graph.EndGraphics;

END testimage.




