stk/Demos/stklos-demo2.stklos

62 lines
2.3 KiB
Plaintext
Executable File

#!/usr/local/bin/stk -f
;;;;
;;;; s t k l o s - d e m o 2 . s t k -- A demo which use some STklos classes
;;;;
;;;; Copyright © 1993-1999 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;;
;;;; Permission to use, copy, and/or distribute this software and its
;;;; documentation for any purpose and without fee is hereby granted, provided
;;;; that both the above copyright notice and this permission notice appear in
;;;; all copies and derived works. Fees for distribution or use of this
;;;; software or derived works may only be charged with express written
;;;; permission of the copyright holder.
;;;; This software is provided ``as is'' without express or implied warranty.
;;;;
;;;; Author: Erick Gallesio [eg@unice.fr]
;;;; Creation date: 24-Aug-1993 19:55
;;;; Last file update: 2-Feb-1999 08:45
(require "Tk-classes")
;;;; Make canvas
(define f (make <Frame>))
(define l (make <Label> :parent f :text "A simple demo written in STklos"))
(define c (make <Canvas> :parent f :relief "groove" :height 400 :width 700))
(define m (make <Label> :parent f :font '(Courier -12) :justify 'left
:text "This demo file illustrates the use of bind-for-dragging with various parameters:
- Left button to drag any kind of object.
- Left button with Shift key pressed to drag an object and executes user hooks
- Right button to move red objects only."))
(define q (make <Button> :text "Quit" :command (lambda () (exit 0))))
(pack l c m q :in f :expand #t :fill 'both)
(pack f)
;;;; Make items
(define r1 (make <rectangle> :coords '(0 0 50 50)
:parent c
:fill "red"
:tags "red"))
(define r2 (make <rectangle> :coords '(100 100 150 150)
:parent c
:fill "blue"))
(define t (make <Text-Item> :coords '(80 80)
:parent c
:fill "red"
:tags "red"
:text "Hello world!"))
;; Button 1 for dragging objects
(bind-for-dragging c)
;; Button 1 for dragging objects (with user hooks)
(bind-for-dragging c :tag 'all
:modifier "Shift"
:start (lambda (w x y) (format #t "Start to drag ~S\n" w))
:motion (lambda (w x y) (format #t "Move ~A ~A\n" x y))
:stop (lambda (w x y) (format #t "Stop with ~S\n" w)))
;; Button 3 for dragging red objects (i.e. r1 and t)
(bind-for-dragging c :tag "red" :button 3)