1996-09-27 06:29:02 -04:00
|
|
|
|
;;;;
|
1998-04-10 06:59:06 -04:00
|
|
|
|
;;;; I m a g e . s t k l o s -- The Tk4.0 image mechanism
|
1996-09-27 06:29:02 -04:00
|
|
|
|
;;;;
|
1998-04-10 06:59:06 -04:00
|
|
|
|
;;;; Copyright <20> 1993-1998 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
|
1996-09-27 06:29:02 -04:00
|
|
|
|
;;;;
|
|
|
|
|
;;;; 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: 26-Jul-1995 11:23
|
1998-04-10 06:59:06 -04:00
|
|
|
|
;;;; Last file update: 21-Mar-1998 22:38
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
(require "Basics")
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(require "image") ; The one with a lower "i"
|
|
|
|
|
|
|
|
|
|
(select-module STklos+Tk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Images can be seen in two ways in STklos, depending of what you
|
|
|
|
|
;;;; want to do with them. If you want just to load an image in a
|
|
|
|
|
;;;; button or a label without modifying its parameters (gamma
|
|
|
|
|
;;;; correction, palette, ..) you can use the class <Image>. This
|
|
|
|
|
;;;; class uses the make-image helper function which knows about the
|
|
|
|
|
;;;; *image-path* variable. To create such an image can be done with
|
|
|
|
|
;;;; (make <Image> "teapot.ppm")
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; On the other hand, if you want to deal with images options you
|
|
|
|
|
;;;; have to take the appropriate class depending of the type of image
|
|
|
|
|
;;;; you want to manipulate. The available classes for that are
|
|
|
|
|
;;;; <Bitmap-image>, <Photo-image>, <Pixmap-Image>, ...
|
|
|
|
|
;;;; Here is how the hierarchy is organized
|
|
|
|
|
;;;; <Tk-image> common ancestor
|
|
|
|
|
;;;; <Image> simple to use images (format independant)
|
|
|
|
|
;;;; <Tk-Basic-image> Basic class for "complex" image manipulation
|
|
|
|
|
;;;; <Bitmap-image> Bitmaps and all its options
|
|
|
|
|
;;;; <Photo-image> GIF and PPM and all their options
|
|
|
|
|
;;;; .....
|
|
|
|
|
|
|
|
|
|
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; <Tk-image> class definition
|
|
|
|
|
;;;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-class <Tk-Image> ()
|
|
|
|
|
((Id :getter Id)
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(image-type :getter image-type
|
|
|
|
|
:allocation :virtual
|
|
|
|
|
:slot-ref (lambda(o) (image 'type (Id o)))
|
|
|
|
|
:slot-set! (lambda(o v) (Tk:slot-is-read-only o 'image-type)))
|
|
|
|
|
(width :getter width
|
|
|
|
|
:allocation :virtual
|
|
|
|
|
:slot-ref (lambda(o) (image 'width (Id o)))
|
|
|
|
|
:slot-set! (lambda(o v) (Tk:slot-is-read-only o 'width)))
|
|
|
|
|
(height :getter height
|
|
|
|
|
:allocation :virtual
|
|
|
|
|
:slot-ref (lambda(o) (image 'height (Id o)))
|
|
|
|
|
:slot-set! (lambda(o v) (Tk:slot-is-read-only o 'height))))
|
|
|
|
|
:metaclass <Tk-metaclass>)
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Write-object
|
|
|
|
|
;;;
|
|
|
|
|
(define-method Tk-write-object((self <Tk-Image>) port)
|
|
|
|
|
(display (widget-name (slot-ref self 'id)) port))
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; <Image> class definition
|
|
|
|
|
;;;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-class <Image> (<Tk-Image>)
|
|
|
|
|
((file :initform #f :init-keyword :file)))
|
|
|
|
|
|
|
|
|
|
(define-method initialize ((self <Image>) initargs)
|
|
|
|
|
(next-method)
|
|
|
|
|
(let ((file (slot-ref self 'file)))
|
|
|
|
|
(unless file
|
|
|
|
|
(error "<Image> initialization requires a file name"))
|
|
|
|
|
(let ((Id (make-image file)))
|
|
|
|
|
(if Id
|
|
|
|
|
(slot-set! self 'Id Id)
|
|
|
|
|
(error "Cannot create image with file ~S" file)))))
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Destroy
|
|
|
|
|
;;;
|
|
|
|
|
(define-method destroy ((self <Image>))
|
|
|
|
|
(delete-image (slo-ref self 'Id)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; <Tk-Basic-image> class definition
|
|
|
|
|
;;;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-class <Tk-Basic-Image> (<Tk-image>)
|
|
|
|
|
((file :accessor file
|
1996-09-27 06:29:02 -04:00
|
|
|
|
:init-keyword :file
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(data :accessor image-data
|
|
|
|
|
:init-keyword :data
|
1998-04-10 06:59:06 -04:00
|
|
|
|
:allocation :tk-virtual)))
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(define-method initialize ((self <Tk-Basic-Image>) initargs)
|
1996-09-27 06:29:02 -04:00
|
|
|
|
(let ((tk-options (get-keyword :tk-options initargs '())))
|
|
|
|
|
(slot-set! self 'id (initialize-image self tk-options))
|
|
|
|
|
(next-method)))
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Destroy
|
|
|
|
|
;;;
|
|
|
|
|
(define-method destroy ((self <Tk-image>))
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(image 'delete self))
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; <Bitmap-image> class definition
|
|
|
|
|
;;;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(define-class <Bitmap-image> (<Tk-Basic-Image>)
|
1996-09-27 06:29:02 -04:00
|
|
|
|
((background :accessor background
|
|
|
|
|
:init-keyword :background
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(foreground :accessor foreground
|
|
|
|
|
:init-keyword :foreground
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(mask-data :accessor mask-data
|
|
|
|
|
:init-keyword :mask-data
|
|
|
|
|
:tk-name maskdata
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(mask-file :accessor mask-file
|
|
|
|
|
:init-keyword :mask-file
|
|
|
|
|
:tk-name maskfile
|
|
|
|
|
:allocation :tk-virtual)))
|
|
|
|
|
|
|
|
|
|
(define-method initialize-image((self <Bitmap-image>) args)
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(apply image 'create 'bitmap (gensym "Img ") args))
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; <Photo-image> class definition
|
|
|
|
|
;;;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(define-class <Photo-image> (<Tk-Basic-Image>)
|
|
|
|
|
((channel :accessor channel
|
|
|
|
|
:init-keyword :channel
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(image-format :accessor image-format
|
|
|
|
|
:init-keyword :image-format
|
|
|
|
|
:tk-name format
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(gamma :accessor gamma
|
|
|
|
|
:init-keyword :gamma
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(height :accessor height
|
|
|
|
|
:init-keyword :height
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(palette :accessor palette
|
|
|
|
|
:init-keyword :palette
|
|
|
|
|
:allocation :tk-virtual)
|
|
|
|
|
(width :accessor width
|
|
|
|
|
:init-keyword :width
|
|
|
|
|
:allocation :tk-virtual)))
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
(define-method initialize-image((self <Photo-image>) args)
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(apply image 'create 'photo (gensym "Img ") args))
|
|
|
|
|
|
|
|
|
|
;;; [FIXME] functions for photo images should be written here. But is is
|
|
|
|
|
;;; really necessary
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; <Pixmap-image> class definition
|
|
|
|
|
;;;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
(define-class <Pixmap-image> (<Tk-Basic-Image>)
|
|
|
|
|
())
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
|
1998-04-10 06:59:06 -04:00
|
|
|
|
(define-method initialize-image((self <Pixmap-image>) args)
|
|
|
|
|
(require "pixmap")
|
|
|
|
|
(apply image 'create 'pixmap (gensym "Img ") args))
|
1996-09-27 06:29:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide "Image")
|