id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
33,488
device-pc.lsp
rwoldford_Quail/source/window-basics/monitor/device-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; device-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; R.W. Oldford 1992 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*color-available* color-available-p))) ;;; ;;; *color-available* is a Mac Common Lisp variable that is T if ;;; the Mac has color and NIL otherwise. ;;; In window-basics, this information is stored as function. ;;; For the PC we are assuming that color is available (defvar *color-available* T) (defun color-available-p () "Returns T if colour (or gray-scale) ~ is available on the present monitor, NIL otherwise." T)
1,203
Common Lisp
.l
27
41.777778
105
0.545299
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
4c92e05d6fa464ee86565538418371e6881b37a82219a7b6736d70efc9b2eb2c
33,488
[ -1 ]
33,489
screen.lsp
rwoldford_Quail/source/window-basics/monitor/screen.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; screen.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; R.W. Oldford 1989-1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-screen-region screen-height screen-width screen-x screen-y))) ;;;----------------------------------------------------------------------- ;;; grabbing the screen and screen coordinates (defun screen-region () (make-region 0 0 (screen-width) (screen-height))) (defun canvas-screen-region (canvas) "Returns the (active) screen location occupied by canvas as a region." (let* ((left (screen-x canvas)) (bottom (screen-y canvas)) (region (canvas-region canvas))) (make-region left bottom (region-width region) (region-height region)))) (defun screen-to-canvas (canvas location) "Converts location from screen to canvas coords ~ location may be a region or position ~ returns a region or position as appropriate." (let* ((dx (screen-x canvas)) (dy (screen-y canvas))) (if (region-p location) (make-region (- (region-left location) dx) (- (region-bottom location) dy) (region-width location) (region-height location)) ;;else (make-position (- (position-x location) dx) (- (position-y location) dy) )))) (defun canvas-to-screen (canvas location) "Converts location from canvas to screen coords ~ location may be a region or position. ~ Returns a region or position as appropriate." (let* ((dx (screen-x canvas)) (dy (screen-y canvas))) (if (region-p location) (make-region (+ (region-left location) dx) (+ (region-bottom location) dy) (region-width location) (region-height location)) ;;else (make-position (+ (position-x location) dx) (+ (position-y location) dy) ))) )
2,643
Common Lisp
.l
62
36.16129
87
0.53114
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
532b8ab482e7e9782daae08e2b9499af0c096d526af6d052fa2b583d4f4f5e5e
33,489
[ -1 ]
33,491
screen-pc.lsp
rwoldford_Quail/source/window-basics/monitor/screen-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; screen-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1993 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(screen-width screen-height screen-x screen-y))) #| (defun screen-height () "Returns the height of the screen in pixels." (declare (special *default-display*)) (xlib::screen-height (xlib::display-default-screen *default-display*))) |# ;;; The closest approximations seen to be as follows ;;; gwb feb 26, 1996 - check with rwo (defun screen-height () "Returns the height of the special variable *screen* in pixels. ~ the optional t is required to get result in pixels. ~ the functions used can be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::page-height (cg::screen cg::*system*) t)) )) #| (defun screen-height () "Returns the height of the special variable *screen* in pixels. ~ the optional t is required to get result in pixels. ~ the functions used can be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (graft-height (find-graft)) ) (defun screen-width () "Returns the width of the screen in pixels." (declare (special *default-display*)) (xlib::screen-width (xlib::display-default-screen *default-display*))) (defun screen-width () "Returns the width of the special variable *screen* in pixels. ~ The optional t is required to get the result in pixels. ~ the functions used ca be applied to any stream." (declare (special (cg::screen cg::*system*))) ;(graft-width (find-graft))) |# (defun screen-width () "Returns the width of the special variable *screen* in pixels. ~ The optional t is required to get the result in pixels. ~ the functions used ca be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::page-width (cg::screen cg::*system*) t)) )) (defun screen-to-host-y (y) (- (screen-height) y)) (defun host-to-screen-y (y) (- (screen-height) y)) #| (defun screen-x (canvas) (xlib::drawable-x (host-window canvas))) ;;(xwindow-of canvas))) |# ;; Poach from -mcl() (defun screen-x (canvas) "The x-coordinate of the bottom left of the EXTERIOR ~ of canvas as a fixnum." (cg::box-left (cg::exterior canvas))) #| (defun screen-y (canvas) (host-to-screen-y (xlib::drawable-y (host-window canvas)))) ;;(xwindow-of canvas)))) |# ;; Poach from -mcl (defun screen-y (canvas) "The y-coordinate of the bottom left of the EXTERIOR ~ of canvas as a fixnum." (host-to-screen-y (cg::box-bottom (cg::exterior canvas))))
3,344
Common Lisp
.l
86
35.930233
112
0.631011
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5b78afe37e8e7ebe1ebd0d076103f665dab05130233a983c4467d808368f0a6e
33,491
[ -1 ]
33,492
screen-sblx.lsp
rwoldford_Quail/source/window-basics/monitor/screen-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; screen-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1993 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(screen-width screen-height screen-x screen-y))) #| (defun screen-height () "Returns the height of the screen in pixels." (declare (special *default-display*)) (xlib::screen-height (xlib::display-default-screen *default-display*))) ;;; The closest approximations seen to be as follows ;;; gwb feb 26, 1996 - check with rwo (defun screen-height () "Returns the height of the special variable *screen* in pixels. ~ the optional t is required to get result in pixels. ~ the functions used can be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::page-height (cg::screen cg::*system*) t)) )) |# (defun screen-height () "Returns the height of the special variable *screen* in pixels. ~ the optional t is required to get result in pixels. ~ the functions used can be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (graft-height (find-graft)) ) #| (defun screen-width () "Returns the width of the screen in pixels." (declare (special *default-display*)) (xlib::screen-width (xlib::display-default-screen *default-display*))) (defun screen-width () "Returns the width of the special variable *screen* in pixels. ~ The optional t is required to get the result in pixels. ~ the functions used can be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::page-width (cg::screen cg::*system*) t)) )) |# (defun screen-width () "Returns the width of the special variable *screen* in pixels. ~ The optional t is required to get the result in pixels. ~ the functions used can be applied to any stream." ;(declare (special (cg::screen cg::*system*))) (graft-width (find-graft))) (defun screen-to-host-y (y) (- (screen-height) y)) (defun host-to-screen-y (y) (- (screen-height) y)) (defun exterior-frame-rect (canvas) "Returns the exterior rectangle of canvas ~ in screen coordinates x L -> R, y T -> B." (transform-region (sheet-delta-transformation (frame-top-level-sheet canvas) (graft canvas)) (sheet-region (frame-top-level-sheet canvas)))) (defun screen-x (canvas) "The x-coordinate of the bottom left of the EXTERIOR ~ of canvas as a fixnum." (rectangle-min-x (exterior-frame-rect canvas))) (defun screen-y (canvas) "The y-coordinate of the bottom left of the EXTERIOR ~ of the canvas as a fixnum." (host-to-screen-y (rectangle-max-y (exterior-frame-rect canvas)))) #| (defun screen-x (canvas) "The x-coordinate of the bottom left of the EXTERIOR ~ of canvas as a fixnum." (cg::box-left (cg::exterior canvas))) ;; Poach from -mcl (defun screen-y (canvas) "The y-coordinate of the bottom left of the EXTERIOR ~ of canvas as a fixnum." (host-to-screen-y (cg::box-bottom (cg::exterior canvas)))) |#
3,764
Common Lisp
.l
92
37.521739
112
0.640492
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
09f341207b2b11fdb7f44223a0c597bc9ceadb647dfbb298b6de65934ddc0b7d
33,492
[ -1 ]
33,493
device.lsp
rwoldford_Quail/source/window-basics/monitor/device.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; device.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*device-types* *current-device-type* set-device-type device-type color-device-p gray-scale-device-p black&white-device-p))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Device types ;;; ;;; Useful for setting up default kinds of canvas. ;;; User can always make a canvas that is not applicable to the ;;; current (device-type). ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar *device-types* '(:black&white :color :gray-scale) "Allowable device types. Minimally, one of :black&white :color or :gray-scale. ~ Device type is used by window-basics to determine the ~ default kind of canvas. ~ Default type is :black&white.") (defvar *current-device-type* :black&white "The current device type. ~ Device type is used by window-basics to determine the ~ default kind of canvas. ~ Default type is :black&white. ~ Set with set-device-type, access with device-type.") (defun set-device-type (&optional (type :black&white)) "Sets the current device type to be the value of type. ~ Device type is used by window-basics to determine the ~ default kind of canvas. ~ Default type is :black&white." (declare (special *current-device-type* *device-types*)) (if (member type *device-types*) (setf *current-device-type* (or (case type ;; Allow different spelling (:colour :color) ;; Allow different spelling (:grey-scale :gray-scale) ) type)) (quail-error "Illegal device type: ~s." type))) (defun device-type () "Returns the current device type." (declare (special *current-device-type*)) *current-device-type*) (defun color-device-p () "Determine if :color is the current device type." (eq :color (device-type))) (defun gray-scale-device-p () "Determine if :gray-scale is the current device type." (eq :gray-scale (device-type))) (defun black&white-device-p () "Determine if :black&white is the current device type." (eq :black&white (device-type))) (eval-when (:load-toplevel :execute) (if (color-available-p) (set-device-type :color) (set-device-type :black&white)))
3,136
Common Lisp
.l
78
35.423077
119
0.556766
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
70a8f4849cb0d6de28b471d1a360a63ce66a66c2f092302be72ad90f7626c2ad
33,493
[ -1 ]
33,494
canvas-redisplay-sblx.lsp
rwoldford_Quail/source/window-basics/redisplay/canvas-redisplay-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-redisplay-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996 ;;; R.W. Oldford 1989-1992 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defmethod resize-sheet ((self canvas-redisplay-mixin) width height) (let ((result)) (cond ((eql (frame-state self) :shrunk) (setf result (call-next-method)) ) (T (setf result (call-next-method)) (unless (eq (frame-state self) :shrunk) (when (redisplay-p self) (redisplay self))))) result)) ;(what-goes-here-? :force T)) #| (defmethod cg::resize-window ((self canvas-redisplay-mixin) position) (let (result ) (cond ((eq :icon (cg::state self)) (setf result (call-next-method)) ) (T (setf result (call-next-method)) (unless (eq :icon (cg::state self)) (when (redisplay-p self) (redisplay self) )))) result)) |#
1,577
Common Lisp
.l
43
32.093023
85
0.499348
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e69fb6b1ae7f8f96487ba89aa35de378a9248f6394b5da14dd474f0e85b413ca
33,494
[ -1 ]
33,495
canvas-redisplay-pc.lsp
rwoldford_Quail/source/window-basics/redisplay/canvas-redisplay-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-redisplay-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996 ;;; R.W. Oldford 1989-1992 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defmethod cg::resize-window ((self canvas-redisplay-mixin) position) (declare (ignorable position)) ; 28JUL2023 (let (result ) (cond ((eq :icon (cg::state self)) (setf result (call-next-method)) ) (T (setf result (call-next-method)) (unless (eq :icon (cg::state self)) (when (redisplay-p self) (redisplay self) )))) result))
1,262
Common Lisp
.l
30
36.9
86
0.46748
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
2736b2c861967ef3a4af5006444c3e0dc6adb19c92695e5cd0de8884ee7957d1
33,495
[ -1 ]
33,496
canvas-ops-pc.lsp
rwoldford_Quail/source/window-basics/redisplay/canvas-ops-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-ops-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996 ;;; R.W. Oldford 1996 ;;; ;;;---------------------------------------------------------------------------------- ;;; Changed defsetf on canvas-title to use ;;; cg::set-stream-title (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(;;size-changed-p canvas-visible-p at-top-p close-canvas hide-canvas show-canvas canvas-width canvas-height canvas-title canvas-set-title which-canvas move-canvas shape-canvas canvas-to-top canvas-at-top canvases ))) #| (defun size-changed-p (display) ; cbh ;; for a particular kind of display, redefine this (declare (ignore display)) T) |# (defun at-top-p (canvas) "Test whether the canvas is the top-most in the display." (declare (special *quail-menubar-window*)) (let ((fw (first (canvases));(cg::front-window (cg::screen cg::*system*)) 08JUN2021 )) (and (canvas-p canvas) (not (member ;(cg::window-state canvas) 19oct05 (cg::state canvas) ;19oct05 (list :shrunk :icon))) (or (eq canvas fw) (and (eq *quail-menubar-window* fw) (eq canvas (cg::next-window *quail-menubar-window*)))))) ) (defun canvas-visible-p (canvas) "Test whether the canvas is visible in the display." (eql (cg::state canvas) :normal)) (defun close-canvas (canvas) "Close the canvas if it's open." (cg::close canvas)) (defun hide-canvas (canvas) "Hides the canvas from display." (cg::shrink-window canvas T)) (defun show-canvas (canvas) "Displays the canvas." (cg::select-window canvas) ) (defun canvas-width (canvas) "Returns the display width of the canvas (in pixels)." (- (cg::visible-box-width canvas) (cg::vertical-scrollbar-thickness))) ;;05may06 (defun canvas-height (canvas) "Returns the display height of the canvas (in pixels)." (- (cg::visible-box-height canvas) (cg::horizontal-scrollbar-thickness))) ;;05may06 ;;;============================================================ ;;; Canvas properties ;;;============================================================ (defun canvas-to-top (window) "Brings the canvas to the front of all other windows." (cg::select-window window)) (defun canvas-at-top () "Returns the canvas at the front of all other canvases." (first (canvases))) (defun canvases () "Returns a list of all existing canvases." (loop for w in (cg::windows (cg::screen cg::*system*)) when (wb::canvas-p w) ; when (typep w 'canvas) ;; Changed Nov 19+ 1997 collect w)) (defun which-canvas (screen-position) "Returns the canvas at the screen-position, if it exists." ;;loop over all windows, find the frontmost one containing position ;; return it if it is a canvas (find-if #'(lambda (w) (inside-p (canvas-screen-region w) screen-position)) (canvases))) (defun canvas-title (canvas) (cg::title canvas)) ;;; Changed 18 Feb 1998 from (cg::set-stream-title to (setf (cg::stream-title (defsetf canvas-title (canvas) (new-value) `(let ((my-new-value ,new-value)) (setf (cg::title ,canvas) my-new-value) ) ) (defun canvas-set-title (c title) "Sets the canvas title to be the value of the second argument ~ title must be a string." (setf (cg::title c) title)) (defun move-canvas (canvas x &optional y) "Reposition the canvas to the position (x y) in screen coordinates. ~ If only one argument is given then it is assumed to be a position." (cond ((integerp y) (cg::move-window canvas (cg::make-position x (screen-to-host-y y)))) (T (cg::move-window canvas (cg::make-position (position-x x) (screen-to-host-y (position-y x))))))) (defun shape-canvas (canvas width &optional height) "Resize a canvas to have width and height as given. If the optional ~ argument height is not supplied, then it is assumed that the first argument ~ is either a position specifying the width and height as its x and y coordinates, ~ or a region whose width and height specify the corresponding attributes of the canvas." (cond (height (cg::resize-window canvas (cg::make-position width height)) ) ((position-p width) (cg::resize-window canvas width)) ((region-p width) (cg::resize-window canvas (cg::make-position (region-width width) (region-height width)))) (T (cg::resize-window canvas (cg::make-position (min width (window-max-width)) (min width (window-max-height)))))))
5,449
Common Lisp
.l
128
36.046875
87
0.583444
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
84742a345d7c7955b89cea1d3f5f8d4b48de4c54785d9daa17725f1ea2cadf73
33,496
[ -1 ]
33,499
canvas-redisplay.lsp
rwoldford_Quail/source/window-basics/redisplay/canvas-redisplay.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; canvas-redisplay.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1989-1992 ;;; H.A. Chipman 1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-redisplay-mixin set-redisplay-fn set-redisplay-test redisplay redisplay-p redisplay-fn-of redisplay-p-of display-of canvas-display))) ;;; Give canvas a hook to the thing it's displaying. This is ;;; necessary to get the Mac windows to refresh themselves ;;; properly. ;;; ;;; NOTE: the redisplay function needs to be defined for any particular ;;; application. Here, we just have a useless dummy definition. (defun default-redisplay-fn (canvas) (declare (ignore canvas))) (defun default-redisplay-p (canvas) "This dummy function returns NIL. ~ It is here in case some canvas types wish to have ~ redisplay tests peculiar to the individual canvas." (declare (ignore canvas)) NIL) (defclass canvas-redisplay-mixin () ((display :initarg :display :initform nil :accessor display-of :documentation "The data structure to be displayed in ~ this canvas.") (redisplay-fn :initarg :redisplay-fn :initform #'default-redisplay-fn :accessor redisplay-fn-of :documentation "A function applied to the canvas ~ when redisplay-p yields true when ~ applied to the canvas.") (redisplay-p :initarg :redisplay-p :initform #'default-redisplay-p :accessor redisplay-p-of :documentation "A test function applied to the canvas ~ which yields true when ~ the canvas contents should be redisplayed.") ) (:documentation "Mixin to canvas so that it will redraw it's display") ) (defun redisplay (canvas) "Redisplays the canvas by applying the canvas's redisplay-fn ~ to the canvas." (funcall (redisplay-fn-of canvas) canvas)) (defun redisplay-p (canvas ) "Yields true when ~ the canvas contents should be redisplayed." (or (and (canvas-visible-p canvas) (not (at-top-p canvas))) (and (at-top-p canvas) (just-selected-p canvas)) (funcall (redisplay-p-of canvas) canvas)) ) (defun set-redisplay-fn (canvas new-fn) "Sets the redisplay function of the canvas to new-fn." (setf (redisplay-fn-of canvas) new-fn)) (defun set-redisplay-test (canvas new-fn) "Sets the redisplay test function of the canvas to new-fn." (setf (redisplay-p-of canvas) new-fn)) ;;; An additional fun to grab the display ... rwo (defun canvas-display (canvas) (display-of canvas)) (defun just-selected-p (canvas) (declare (special *just-selected*)) (eq canvas *just-selected*)) (defvar *just-selected* NIL)
3,629
Common Lisp
.l
87
34.505747
125
0.583191
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7dc4c6400f2e4c52d22f28b0660106cf548de0d366dc0a7ccf1f70b3de6f90a6
33,499
[ -1 ]
33,502
canvas-ops-sblx.lsp
rwoldford_Quail/source/window-basics/redisplay/canvas-ops-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-ops-sblx.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996 ;;; R.W. Oldford 1996 ;;; ;;;---------------------------------------------------------------------------------- ;;; Changed defsetf on canvas-title to use ;;; cg::set-stream-title (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(;;size-changed-p canvas-visible-p at-top-p close-canvas hide-canvas show-canvas canvas-width canvas-height canvas-title canvas-set-title which-canvas move-canvas shape-canvas canvas-to-top canvas-at-top canvases ))) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*current-canvas* *quail-canvases* revise-ccqc update-ccqc))) (defvar *current-canvas* NIL) (defvar *quail-canvases* '()) (defun update-ccqc (canvas) "set *current-canvas* to be canvas, remove the canvas entry from *q-c,*~ (cons (cons canvas (frame-state canvas)) *q-c*" (setf *current-canvas* canvas) (setf *quail-canvases* (cons (cons canvas :ENABLED) ;(frame-state canvas)) (remove-if #'(lambda (x) (eql (car x) canvas)) *quail-canvases*))) ) (defun revise-ccqc (canvas) "set *current-canvas* to be the first :ENABLED car on *quail-canvases*~ minus the entry for canvas itself [NIL if find-if fails - OK]~ if there is a *current-canvas*, set *quail-canvases* to be (update-ccqc *current-canvas*)~ otherwise exit" (setf *current-canvas* (car (find-if #'(lambda (x) (eql (cdr x) :ENABLED)) (remove-if #'(lambda (y) (eql (car y) canvas)) *quail-canvases*)))) (if *current-canvas* (update-ccqc *current-canvas*) NIL) ) #| now in color/bw-canvas-sblx.lsp (define-presentation-action do-change-canvas (blank-area nil quail-color-canvas :gesture :select) (object) (with-application-frame (frame) (update-ccqc frame) )) |# #| the next 9 methods need the canvas specialiser which is not available until canvas/canvas.lsp has run which is AFTER this file They have been moved to a new file canvas canvas/color-canvas-ops-sblx.lsp on 28AUG2021. This file will appear AFTER color-canvas-sblx.lsp in the canvas module of wb's .asd file (defmethod enable-frame :after ((self canvas)) "The :before method will have set the frame-state of self to :DISABLED~ so now this part of the call to enable-frame will pop it back up. Then update-ccqc." ;(format t "~%:after on enable-frame called.") (update-ccqc self) ) (defmethod enable-frame :before ((self canvas)) "If self is not :ENABLED, disable-it so that the :after method can pop it back up." ;(format t "~%:before on enable-frame called.") (unless (eql (frame-state self) :ENABLED) (disable-frame self)) ) (defmethod destroy-frame :after ((self canvas)) "First reset the state of canvas on *quail-canvases* to be :DISOWNED - then revise-ccqc" (setf (cdr (find-if #'(lambda (x) (eql (car x) self)) *quail-canvases*)) :DISOWNED) (revise-ccqc self)) (defmethod raise-frame :after ((self canvas)) (cond ((eql self *current-canvas*) NIL) ((not (eql :ENABLED (frame-state self))) NIL) (T (update-ccqc self)) )) (defmethod shrink-frame :after ((self canvas)) "First reset the state of canvas on *quail-canvases* to be :SHRUNK - then revise-ccqc" (setf (cdr (find-if #'(lambda (x) (eql (car x) self)) *quail-canvases*)) :SHRUNK) (revise-ccqc self)) (defmethod move-sheet ((self canvas) (x fixnum) (y fixnum)) ) (defmethod move-sheet ((self canvas) (x fixnum) (y fixnum)) (move-sheet (frame-top-level-sheet self) x y) (update-ccqc self)) (defmethod resize-sheet ((self canvas) (x fixnum) (y fixnum)) ;(format t "~%Entering do-nothing primary on resize-sheet") ) (defmethod resize-sheet ((self canvas) (w fixnum) (h fixnum)) (resize-sheet (frame-top-level-sheet self) w h) (update-ccqc self)) |# #| (defun size-changed-p (display) ; cbh ;; for a particular kind of display, redefine this (declare (ignore display)) T) |# ;;; see canvases below (defun at-top-p (canvas) "Test whether the canvas is the top-most in the display." (and (canvas-p canvas) (eql canvas (caar *quail-canvases*)) ) ) ; destroy-frame (defun close-canvas (canvas) "Close the canvas if it's open." (clim::destroy-frame canvas)) ;; need to setf state to be :shrunk NOPE just shrink-frame (defun hide-canvas (canvas) "Hides the canvas from display." (clim::shrink-frame canvas)) ;; raise-frame brings it to the top of the list but does not actually show it (defun show-canvas (canvas) "Displays the canvas." (clim::enable-frame canvas) ) #| ; defined already in monitor/screen-sblx.lsp 09MAR2022 gwb ;; the outside of canvas (defun exterior-frame-rect (canvas) "Returns the exterior rectangle of canvas ~ in screen coordinates x L -> R, y T -> B." (transform-region (sheet-delta-transformation (frame-top-level-sheet canvas) (graft canvas)) (sheet-region (frame-top-level-sheet canvas)))) |# (defun canvas-width (canvas) "Returns the display width of the canvas (in pixels)." (clim::rectangle-width (exterior-frame-rect canvas))) ;(- (cg::visible-box-width canvas) (cg::vertical-scrollbar-thickness))) ;;05may06 (defun canvas-height (canvas) "Returns the display height of the canvas (in pixels)." (clim::rectangle-height (exterior-frame-rect canvas))) ;(- (cg::visible-box-height canvas) (cg::horizontal-scrollbar-thickness))) ;;05may06 ;;;============================================================ ;;; Canvas properties ;;;============================================================ ;;; assuming to the front means to the top of some list ;;; raise-frame should do (defun canvas-to-top (canvas) "Brings the canvas to the front of all other windows." (clim::raise-frame canvas)) ;;; the value of *application-frame* shoud do - can't use this, only available inside a frame (defun canvas-at-top () "Returns the canvas at the front of all other canvases." (first (canvases))) ;;; don't yet know how to get this ;;; Aha! see clim-spec under frammanager ;;; (frame-manager-frames (frame-manager *quail-menubar-window*)) ;;; returns a list of frames ;;; (eql (car *this*) *application-frame*) ;;; returns T (defun canvases () "Returns a list of all existing canvases."*quail-canvases*) (defun which-canvas (screen-position) "Returns the canvas at the screen-position, if it exists." ;;loop over all windows, find the frontmost one containing position ;; return it if it is a canvas (find-if #'(lambda (w) (clim::region-contains-position-p (clim::sheet-region (clim::frame-top-level-sheet w)) (h-draw::point-x screen-position) (h-draw::point-y screen-position))) (canvases))) (defun canvas-title (canvas) (clim::frame-pretty-name canvas)) ;;; Changed 18 Feb 1998 from (cg::set-stream-title to (setf (cg::stream-title (defsetf canvas-title (canvas) (new-value) `(let ((my-new-value ,new-value)) (setf (clim::frame-pretty-name ,canvas) my-new-value) ) ) (defun canvas-set-title (c title) "Sets the canvas title to be the value of the second argument ~ title must be a string." (setf (clim::frame-pretty-name c) title)) (defun move-canvas (canvas x &optional y) "Reposition the canvas to the position (x y) in screen coordinates. ~ If only one argument is given then it is assumed to be a position." (let ((ftls (frame-top-level-sheet canvas))) (cond ((integerp y) (move-sheet ftls x y) ) (T (move-sheet ftls (h-draw::point-x x) (h-draw::point-y x)) )) )) (defun shape-canvas (canvas width &optional height) "Resize a canvas to have width and height as given. If the optional ~ argument height is not supplied, then it is assumed that the first argument ~ is either a position specifying the width and height as its x and y coordinates, ~ or a region whose width and height specify the corresponding attributes of the canvas." (let ((ftls (frame-top-level-sheet canvas))) (cond (height (clim::resize-sheet ftls width height) ) ((position-p width) (clim::resize-sheet ftls (h-draw::point-x width) (h-draw::point-y width))) ((region-p width) (clim::resize-sheet ftls (region-width width) (region-height width))) (T nil) ))) ;=================================================== ; canvas-visible-p things ; mcclim does not seem to have facilities for accessing the z-order of its frames ; and all its region-X functions are with region coords rather than screen coords ; hence much of what follows ; gwb august 2021 ;=================================================== (defun canvas-in-screen-coords (canvas &optional (v-kludge 30)) "Returns the clim bounding rectangle of the exterior of canvas ~ in *screen* units. ~ mcclim does not know about the 'title-bar' and so the bounding rectangle ~ returned has v-min too big by its height .. hence v-kludge." (declare (optimize (speed 3))) (let ((basic-region (transform-region (clim::sheet-delta-transformation (clim::frame-top-level-sheet canvas) (graft (clim::frame-top-level-sheet canvas))) (sheet-region (clim::frame-top-level-sheet canvas))))) (list (clim::bounding-rectangle-min-x basic-region) (clim::bounding-rectangle-max-x basic-region) (- (clim::bounding-rectangle-min-y basic-region) v-kludge) (clim::bounding-rectangle-max-y basic-region)))) (defun screen-point-on-canvas (canvas h v) "Determines whether the screen point pt h v is in or on the boundary of canvas" (declare (fixnum h v) (optimize (speed 3))) (let* ((canvas-exterior (canvas-in-screen-coords canvas )) (h-min (first canvas-exterior)) (h-max (second canvas-exterior)) (v-min (third canvas-exterior)) (v-max (fourth canvas-exterior))) (if (and (>= h h-min) (<= h h-max) (>= v v-min) (<= v v-max)) T nil) ) ) (defun range-covered-p (list-of-canvases h-min h-max v-min v-max) (declare (optimize (speed 3))) (let ((h-range (make-list-from-ends h-min h-max)) (v-range (make-list-from-ends v-min v-max))) (if (every #'(lambda (v) (every #'(lambda (h) (some #'(lambda (c) (screen-point-on-canvas c h v)) list-of-canvases)) h-range)) v-range) T NIL ) )) (defun revise-canvas-list (canvas list-of-cons-canvas-and-state) "Returns a new list of just the canvas components which are (1) not [the arg] ~ nor (2) have cdr not equal to :ENABLED" (let ((new-list '())) (setf new-list (mapcar #'(lambda (y) (car y)) (remove-if #'(lambda (x) (or (eql (car x) canvas) (not (eql (cdr x) :ENABLED)))) list-of-cons-canvas-and-state))) new-list)) ;;; ;;; I need to make an integer list including from l-min l0max (defun make-list-from-ends (l-min l-max) "Returns an integer list including from l-max to l-min" (declare (fixnum l-min l-max) (optimize (speed 3))) (let ((result '())) (do ((i l-min (1+ i))) ((> i l-max)) (setf result (cons i result))) result )) (defun canvas-visible-p (canvas) "Determines whether some part of canvas is not covered by any other canvas" (cond ((eql canvas *current-canvas*) T) ((not (eql (frame-state canvas) :ENABLED)) NIL) (T (let* ((screen-canvas (canvas-in-screen-coords canvas)) (ch-min (first screen-canvas)) (ch-max (second screen-canvas)) (cv-min (third screen-canvas)) (cv-max (fourth screen-canvas)) (updated-canvas-list (revise-canvas-list canvas *quail-canvases*))) (not (range-covered-p updated-canvas-list ch-min ch-max cv-min cv-max)))))) ;;;
12,487
Common Lisp
.l
287
38.961672
99
0.642487
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
752afd66739968e61bc2665200bbaa3e09b3d85c686ed03a8e7883815a7ce00d
33,502
[ -1 ]
33,505
clip-sblx.lsp
rwoldford_Quail/source/window-basics/canvas-regions/clip-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; clip-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) 1988-1992 Statistical Computing Laboratory, University of Waterloo ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; G.W. Benentt 1996 ;;;---------------------------------------------------------------------------------- (in-package :window-basics) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(clipping-region-of))) (defun clipping-region-of (canvas) "Returns the content region of the canvas which I take to ~ means the interior of its window in (Q) coords." (let* ((its-pane (get-frame-pane canvas 'host-pane)) (its-rectangle (pane-viewport-region its-pane)) (clip-left (bounding-rectangle-min-x its-rectangle)) (clip-bottom (host-to-screen-y (bounding-rectangle-max-y its-rectangle))) (clip-width (bounding-rectangle-width its-rectangle)) (clip-height (bounding-rectangle-height its-rectangle))) (make-region clip-left clip-bottom clip-width clip-height) )) #| (defun clipping-region-of (canvas) "Returns the content region of the canvas which I take to ~ mean the interior of its window in (Q)screen coords." (let ((clip-left (cg::box-left ;(cg::window-interior canvas) 28oct05 (cg::interior canvas) ;28oct05 )) (clip-bottom (host-to-screen-y (cg::box-bottom ;(cg::window-interior canvas) 28oct05 (cg::interior canvas) ;28oct05 ))) (clip-width ;(cg::window-interior-width canvas) 28oct05 (cg::width (cg::interior canvas)) ;28oct05 ) (clip-height ;(cg::window-interior-height canvas) 28oct05 (cg::height (cg::interior canvas)) ;28oct05 )) (make-region clip-left clip-bottom clip-width clip-height) ) ) |#
2,165
Common Lisp
.l
46
38.130435
86
0.51983
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b598f4aa0c87c7aa17feffbf426c25d22fcab4c2977548eb51427a7040491d3d
33,505
[ -1 ]
33,506
canvas-regions-sblx.lsp
rwoldford_Quail/source/window-basics/canvas-regions/canvas-regions-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-regions-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; G.W. Bennett 1996 ;;;---------------------------------------------------------------------------------- (in-package :window-basics) (defun display-rect (window) "Returns the rectangle in which the display is drawn inside the window (canvas) in ~ local coordinates" (pane-viewport-region (get-frame-pane window 'host-pane))) (defun display-rect-right (display-rect) (bounding-rectangle-max-x display-rect)) (defun display-rect-bottom (display-rect) (bounding-rectangle-max-y display-rect)) #| (defun display-rect (window) "Returns the rectangle in which the display is drawn inside the window in ~ local coordinates." (when (wptr window) (let ((rgn (%get-ptr (rref (wptr window) :window.contRgn)))) (make-record :rect :top 0 :left 0 :bottom (- (%get-signed-word rgn 6) (%get-signed-word rgn 2) 15) :right (- (%get-signed-word rgn 8) (%get-signed-word rgn 4) 15))))) (defun display-rect-right (display-rect) (rref display-rect rect.right)) (defun display-rect-bottom (display-rect) (rref display-rect rect.bottom)) |#
1,789
Common Lisp
.l
40
40.675
86
0.55906
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
22d4a18ab1d89fab0db8b6869e3aa176e1d0f0ccc76d62dfc066d2ecdbf3f88b
33,506
[ -1 ]
33,507
instrumented-drag-pc.lsp
rwoldford_Quail/source/window-basics/canvas-regions/instrumented-drag-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; instrumented-drag-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(drag-region-on-canvas drag-region-on-screen select-rectangle select-canvas-rect select-screen-rect prompt-for-canvas sweep-for-canvas reshape-canvas-rect))) (defun calc-region (canvas &optional region left bottom width height) "Returns left bottom, width height as multiple values ~ if region is provided, its left bottom etc are used ~ if left or bottom are not provided, the mouse position is used instead." (when region (setq left (region-left region)) (setq bottom (region-bottom region)) (setq height (region-height region)) (setq width (region-width region))) (setq left (or left (if canvas (mouse-x canvas) (screen-mouse-x)))) (setq bottom (or bottom (- (if canvas (mouse-y canvas) (screen-mouse-y)) height))) (values left bottom width height)) (defun drag-region-on-canvas (canvas &key region (limit-region (canvas-region canvas)) left bottom (width 50) (height 50) (axis :both)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively. ~ Returns a region." ;; bounds for top ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; top -> draw-pt (declare (special :boole-xor cg::invert)) (sleep 10) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ Wrap all this in a with-device-context ;;+ to see whether this will allow sweeping rather than freezing ;;+ 08 Dec 2014 gwb (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((old-mouse NIL) (new-mouse NIL) (top (canvas-to-host-y canvas (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (canvas-to-host-y canvas (region-top limit-region))) (limit-bottom (canvas-to-host-y canvas (region-bottom limit-region))) (limit-right (region-right limit-region)) (draw-pt (screen-to-host-y (+ bottom height))) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower limit-left) (setf left-upper (max limit-left (- limit-right width))) ;; bounds Right ;;(setf right-upper limit-right) ;;(setf right-lower (min limit-right (+ limit-left width))) ;; bound draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position draw-pt (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let (position (cg::cursor-position canvas)) (list (cg::position-x position) (cg::position-y position))) ) ) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) (with-focused-canvas canvas (with-pen-values canvas NIL 1 :boole-xor ;; draw the rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) )) (make-region left (host-to-canvas-y canvas (+ draw-pt height)) width height) )) )) ) (defun drag-region-on-screen (canvas &key region left bottom (width 50) (height 50) (axis :both) (limit-region NIL)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively, :none => no motion. ~ Returns a region." ;; bounds for draw-pt ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; draw-pt -> draw-pt (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((old-mouse NIL) (new-mouse NIL) (draw-pt (screen-to-host-y (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; wrap all this in the correct painting operation (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower (+ limit-left width)) (setf left-upper (max limit-right (+ limit-left width))) ;; bounds draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position Top (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) ;; draw the rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ) ;; Since we are drawing from bottom-right there is no need to add ;; height to draw-pt (make-region left (host-to-screen-y draw-pt ) width height) )) ) (defun select-rectangle (&key canvas (width 10) (height 10) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ If no canvas is supplied the action is taken on the screen in ~ screen coordinates. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas or screen. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ (or screen) coordinates." (if canvas (select-canvas-rect canvas width height limit-region) (select-screen-rect width height limit-region))) (defun select-canvas-rect (canvas &optional (width 0) (height 0) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." (declare (special *gray-shade* :boole-xor cg::invert)) (loop until (mouse-down-p )) (format t "~%Data from select-canvas-rect:") ;06FEB2015 ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((anchor-point NIL) (original-mouse-position NIL) ;07FEB2015 (final-mouse-position NIL) ;07FEB2015 (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable (cg::frame-child canvas)) ) (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) (format t "~%host-mouse-position is ~s " (host-mouse-position)) ;06FEB2015 (setq limit-region (or limit-region (canvas-region canvas))) (format t "~%limit-region is ~s " limit-region) ;06FEB2015 (setf old-mouse (host-mouse-position)) (setf anchor-point (list (max (- (first old-mouse) width) (region-left limit-region)) (max (- (second old-mouse) height) (canvas-to-host-y canvas (region-top limit-region))) )) (format t "~%anchor-point is ~s " anchor-point) ;06FEB2015 (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (setf original-mouse-position (host-mouse-position)) ;07FEB2015 (format t "~%original-mouse-position is ~s " original-mouse-position) (with-focused-canvas canvas (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 ; (with-pen-values canvas *gray-shade* 1 :boole-xor ;; draw the rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) (loop (unless (mouse-down-p ) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; update to get new one (cond ((> (first new-mouse) (first anchor-point)) (setf left (first anchor-point)) (setf width (- (first new-mouse) left))) (T (setf left (first new-mouse)) (setf width (- (first anchor-point) left)))) (cond ((> (second new-mouse) (second anchor-point)) (setf top (second anchor-point)) (setf height (- (second new-mouse) top))) (T (setf top (second new-mouse)) (setf height (- (second anchor-point) top)))) ;; draw it (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; slow down ;;(sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) (setf final-mouse-position (host-mouse-position)) ;07FEB2015 (format t "~% final-mouse-position is ~s " final-mouse-position) ;; Finally erase it. (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) );;end (with-pen-values );; end (with-focused-canvas (format t "~% Values to be returned: ") ;06FEB2015 (format t "~%left is ~d " left) ;06FEB2015 (format t "~%top is ~d " (min (second anchor-point) (second original-mouse-position) (second final-mouse-position))) ;07FEB2015 ;(format t "~% (- (canvas-to-host-y canvas top) height) is ~d " (- (canvas-to-host-y canvas top) height)) ;06FEB2015 (format t "~%width is ~d " width) ;06FEB2015 (format t "~%height is ~d " height) ;06FEB2015 (format t "~%host-mouse-position is now ~s " (host-mouse-position)) ;06FEB2015 (values (min (first anchor-point) (first original-mouse-position) (first final-mouse-position)) ; 07FEB22015left (min (second anchor-point) (second original-mouse-position) (second final-mouse-position)) ; 07FEB2015(- (canvas-to-host-y canvas top) height) ;;(+ top height) (cond ((and ( > (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (first final-mouse-position) (min (first anchor-point) (first original-mouse-position))) ) ((and (< (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (max (first anchor-point) (first original-mouse-position)) (first final-mouse-position))) ((and (< (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (- (max (first anchor-point) (first original-mouse-position)) (first final-mouse-position))) ((and (> (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (- (first final-mouse-position) (min (first anchor-point) (first original-mouse-position)) ) ) T);; end width (cond ((and ( > (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (second final-mouse-position) (min (second anchor-point) (second original-mouse-position))) ) ((and (< (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (second final-mouse-position) (min (second anchor-point) (second original-mouse-position))) ) ((and (< (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (- (max (second anchor-point) (second original-mouse-position)) (second final-mouse-position))) ((and (> (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (- (max (second anchor-point) (second original-mouse-position)) (second final-mouse-position)) ) T);; end height ;width height ;07FEB2015 ) );; end (flet ((host-mouse-position );; end (let* ((anchor-point ) ;; end wrapper );; end (defun select-canvas-rect (defun select-screen-rect ( &optional (width 50) (height 50) limit-region) "Mouse-selects a rectangle on the screen by selecting a location on the~ screen with the mouse and ~ sweeping out the region to be selected. The rectangle selected is confined to limit-region ~ which defaults to the boundary of the screen. ~ Returns the region information as ~ multiple values (left bottom width height) in ~ screen coordinates." (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((root-window (cg::screen cg::*system*)) (anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable root-window) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) ) (flet ((host-mouse-position () (let ((pos (cg::with-device-context (hdc root-window) (cg::cursor-position drawable)))) (list (cg::position-x pos) (cg::position-y pos)))) (check-bound (old-list new-list) "Assumes old-left is current drawing left ~ old-draw is current drawing bottom ~ new-list comes from host-mouse-position ~ so its car is new-left, cdr is new-bottom.~ Checks for switches." (let ((old-left (first old-list)) (old-top (second old-list)) (new-left (first new-list)) (new-top (second new-list))) (cond ((and (>= new-left old-left) (>= new-top old-top)) (setf left old-left) (setf top old-top) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (>= new-left old-left) (< new-top old-top)) (setf left old-left) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) ((and (< new-left old-left) (>= new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top old-top) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (< new-left old-left) (< new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) )) (list left top width height) ) ) (setq limit-region (or limit-region (screen-region))) (loop until (mouse-down-p)) (setf old-mouse (host-mouse-position)) (setf anchor-point (copy-tree old-mouse)) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height))) (loop (unless (mouse-down-p) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; update to get new one (check-bound anchor-point old-mouse ) ;; draw it (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) );; end (loop ;; Finally erase it. (cg::with-device-context (hdc roo-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) );; end (cg::with-paint-operation (values left (- (screen-to-host-y top) height) width height) );; end (flet ((host-mouse-position );; end let* ((root-window );; end with-device-context ) (defun sweep-for-canvas (&rest args) "Sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (multiple-value-bind (left bottom width height) (select-rectangle) (apply #'make-canvas :left left :bottom bottom :width width :height height args))) (defun prompt-for-canvas (&rest args) "Prompts user to sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (declare (special *box-cursor*)) (quail-print "Sweep out a region for the canvas with the mouse.") (with-cursor *box-cursor* (apply #'sweep-for-canvas args))) (defun reshape-canvas-rect (canvas rect &key (draw? t) limit-region (corner-width 10)) "Reshapes a rectangle on the canvas using the mouse ~ to relocate the corner of rectangle closest to the mouse. ~ The selected corner should be within corner-width ~ (horizontally and vertically) of the mouse location.~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let ((d corner-width) mouse-x mouse-y vl vb vr vt fix-x fix-y move-x move-y) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (if draw? (draw-rect&corners canvas rect :corner-width d)) (loop until (mouse-down-p)) (setq mouse-x (mouse-x canvas) mouse-y (mouse-y canvas)) (if draw? (erase-rect&corners canvas rect :corner-width d)) (if (< mouse-x (truncate (+ vl vr) 2)) (setq move-x vl fix-x vr) (setq move-x vr fix-x vl)) (if (< mouse-y (truncate (+ vb vt) 2)) (setq move-y vb fix-y vt) (setq move-y vt fix-y vb)) (if (and (< (abs (- mouse-x move-x)) d) (< (abs (- mouse-y move-y)) d)) (select-rectangle :canvas canvas :limit-region limit-region :width (- mouse-x fix-x) :height (- fix-y mouse-y )))) ) ;; end with-device-context )
37,511
Common Lisp
.l
770
32.045455
138
0.484892
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6e85d90fee9fe9e210f48194fa71a9332bad6a69f3ac9fa01875f8bb69539335
33,507
[ -1 ]
33,508
drag-pc.lsp
rwoldford_Quail/source/window-basics/canvas-regions/drag-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; instrumented-drag-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(drag-region-on-canvas drag-region-on-screen select-rectangle select-canvas-rect select-screen-rect prompt-for-canvas sweep-for-canvas reshape-canvas-rect))) (defun calc-region (canvas &optional region left bottom width height) "Returns left bottom, width height as multiple values ~ if region is provided, its left bottom etc are used ~ if left or bottom are not provided, the mouse position is used instead." (when region (setq left (region-left region)) (setq bottom (region-bottom region)) (setq height (region-height region)) (setq width (region-width region))) (setq left (or left (if canvas (mouse-x canvas) (screen-mouse-x)))) (setq bottom (or bottom (- (if canvas (mouse-y canvas) (screen-mouse-y)) height))) (values left bottom width height)) (defun drag-region-on-canvas (canvas &key region (limit-region (canvas-region canvas)) left bottom (width 50) (height 50) (axis :both)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively. ~ Returns a region." ;; bounds for top ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; top -> draw-pt (declare (special :boole-xor cg::invert)) (sleep 10) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ Wrap all this in a with-device-context ;;+ to see whether this will allow sweeping rather than freezing ;;+ 08 Dec 2014 gwb (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((old-mouse NIL) (new-mouse NIL) ;(top (canvas-to-host-y canvas ; (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (canvas-to-host-y canvas (region-top limit-region))) (limit-bottom (canvas-to-host-y canvas (region-bottom limit-region))) (limit-right (region-right limit-region)) (draw-pt (screen-to-host-y (+ bottom height))) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower limit-left) (setf left-upper (max limit-left (- limit-right width))) ;; bounds Right ;;(setf right-upper limit-right) ;;(setf right-lower (min limit-right (+ limit-left width))) ;; bound draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position draw-pt (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let ((position (cg::cursor-position canvas))) (list (cg::position-x position) (cg::position-y position))) ) ) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) (with-focused-canvas canvas (with-pen-values canvas NIL 1 :boole-xor ;; draw the rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) )) (make-region left (host-to-canvas-y canvas (+ draw-pt height)) width height) )) )) ) (defun drag-region-on-screen (canvas &key region left bottom (width 50) (height 50) (axis :both) (limit-region NIL)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively, :none => no motion. ~ Returns a region." ;; bounds for draw-pt ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; draw-pt -> draw-pt (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((old-mouse NIL) (new-mouse NIL) (draw-pt (screen-to-host-y (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; wrap all this in the correct painting operation (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower (+ limit-left width)) (setf left-upper (max limit-right (+ limit-left width))) ;; bounds draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position Top (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) ;; draw the rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ) ;; Since we are drawing from bottom-right there is no need to add ;; height to draw-pt (make-region left (host-to-screen-y draw-pt ) width height) )) ) (defun select-rectangle (&key canvas (width 10) (height 10) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ If no canvas is supplied the action is taken on the screen in ~ screen coordinates. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas or screen. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ (or screen) coordinates." (if canvas (select-canvas-rect canvas width height limit-region) (select-screen-rect width height limit-region))) (defun select-canvas-rect (canvas &optional (width 0) (height 0) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." (declare (special *gray-shade* :boole-xor cg::invert)) (loop until (mouse-down-p )) ;(format t "~%Data from select-canvas-rect:") ;06FEB2015 ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((anchor-point NIL) ;(original-mouse-position NIL) ;07FEB2015 ;(final-mouse-position NIL) ;07FEB2015 ;(original-anchor-point NIL) ;07FEB2015 (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable (cg::frame-child canvas)) ) (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) ;(format t "~%host-mouse-position is ~s " (host-mouse-position)) ;06FEB2015 (setq limit-region (or limit-region (canvas-region canvas))) ;(format t "~%limit-region is ~s " limit-region) ;06FEB2015 (setf old-mouse (host-mouse-position)) (setf anchor-point (list (max (- (first old-mouse) width) (region-left limit-region)) (max (- (second old-mouse) height) (canvas-to-host-y canvas (region-top limit-region))) )) ;(setf original-anchor-point anchor-point) ;07FEB2015 ;(format t "~%anchor-point is ~s " anchor-point) ;06FEB2015 (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) ;(setf original-mouse-position (host-mouse-position)) ;07FEB2015 ;(format t "~%original-mouse-position is ~s " original-mouse-position) (with-focused-canvas canvas (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 ; (with-pen-values canvas *gray-shade* 1 :boole-xor ;; draw the rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) (loop (unless (mouse-down-p ) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; update to get new one (cond ((> (first new-mouse) (first anchor-point)) (setf left (first anchor-point)) (setf width (- (first new-mouse) left))) (T (setf left (first new-mouse)) (setf width (- (first anchor-point) left)))) (cond ((> (second new-mouse) (second anchor-point)) (setf top (second anchor-point)) (setf height (- (second new-mouse) top))) (T (setf top (second new-mouse)) (setf height (- (second anchor-point) top)))) ;; draw it (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; slow down ;;(sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;(setf final-mouse-position (host-mouse-position)) ;07FEB2015 ;(format t "~% final-mouse-position is ~s " final-mouse-position) ;; Finally erase it. (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) );;end (with-pen-values );; end (with-focused-canvas ;; HERE ;(format t "~% returned will be L ?T W H ~d ~d ~d ~d" ; left (- (canvas-to-host-y canvas top) height) ; width height) (values left (- (canvas-to-host-y canvas top) height) ;;(+ top height) width height) );; end (flet ((host-mouse-position );; end (let* ((anchor-point ) ;; end wrapper );; end (defun select-canvas-rect (defun select-screen-rect ( &optional (width 50) (height 50) limit-region) "Mouse-selects a rectangle on the screen by selecting a location on the~ screen with the mouse and ~ sweeping out the region to be selected. The rectangle selected is confined to limit-region ~ which defaults to the boundary of the screen. ~ Returns the region information as ~ multiple values (left bottom width height) in ~ screen coordinates." (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((root-window (cg::screen cg::*system*)) (anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable root-window) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) ) (flet ((host-mouse-position () (let ((pos (cg::with-device-context (hdc root-window) (cg::cursor-position drawable)))) (list (cg::position-x pos) (cg::position-y pos)))) (check-bound (old-list new-list) "Assumes old-left is current drawing left ~ old-draw is current drawing bottom ~ new-list comes from host-mouse-position ~ so its car is new-left, cdr is new-bottom.~ Checks for switches." (let ((old-left (first old-list)) (old-top (second old-list)) (new-left (first new-list)) (new-top (second new-list))) (cond ((and (>= new-left old-left) (>= new-top old-top)) (setf left old-left) (setf top old-top) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (>= new-left old-left) (< new-top old-top)) (setf left old-left) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) ((and (< new-left old-left) (>= new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top old-top) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (< new-left old-left) (< new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) )) (list left top width height) ) ) (setq limit-region (or limit-region (screen-region))) (loop until (mouse-down-p)) (setf old-mouse (host-mouse-position)) (setf anchor-point (copy-tree old-mouse)) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height))) (loop (unless (mouse-down-p) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; update to get new one (check-bound anchor-point old-mouse ) ;; draw it (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) );; end (loop ;; Finally erase it. (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) );; end (cg::with-paint-operation (values left (- (screen-to-host-y top) height) width height) );; end (flet ((host-mouse-position );; end let* ((root-window );; end with-device-context ) (defun sweep-for-canvas (&rest args) "Sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (multiple-value-bind (left bottom width height) (select-rectangle) (apply #'make-canvas :left left :bottom bottom :width width :height height args))) (defun prompt-for-canvas (&rest args) "Prompts user to sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (declare (special *box-cursor*)) (quail-print "Sweep out a region for the canvas with the mouse.") (with-cursor *box-cursor* (apply #'sweep-for-canvas args))) (defun reshape-canvas-rect (canvas rect &key (draw? t) limit-region (corner-width 10)) "Reshapes a rectangle on the canvas using the mouse ~ to relocate the corner of rectangle closest to the mouse. ~ The selected corner should be within corner-width ~ (horizontally and vertically) of the mouse location.~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let ((d corner-width) mouse-x mouse-y vl vb vr vt fix-x fix-y move-x move-y) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (if draw? (draw-rect&corners canvas rect :corner-width d)) (loop until (mouse-down-p)) (setq mouse-x (mouse-x canvas) mouse-y (mouse-y canvas)) (if draw? (erase-rect&corners canvas rect :corner-width d)) (if (< mouse-x (truncate (+ vl vr) 2)) (setq move-x vl fix-x vr) (setq move-x vr fix-x vl)) (if (< mouse-y (truncate (+ vb vt) 2)) (setq move-y vb fix-y vt) (setq move-y vt fix-y vb)) (if (and (< (abs (- mouse-x move-x)) d) (< (abs (- mouse-y move-y)) d)) (select-rectangle :canvas canvas :limit-region limit-region :width (- mouse-x fix-x) :height (- fix-y mouse-y )))) ) ;; end with-device-context )
34,021
Common Lisp
.l
729
30.603567
110
0.482014
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e569dd3102e60b19c00ff01ba8445d21ffc24978d2167ab937af8b91ce29ebaa
33,508
[ -1 ]
33,510
clip-pc.lsp
rwoldford_Quail/source/window-basics/canvas-regions/clip-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; clip-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) 1988-1992 Statistical Computing Laboratory, University of Waterloo ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; G.W. Benentt 1996 ;;;---------------------------------------------------------------------------------- (in-package :window-basics) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(clipping-region-of))) (defun clipping-region-of (canvas) "Returns the content region of the canvas which I take to ~ mean the interior of its window in (Q)screen coords." (let ((clip-left (cg::box-left ;(cg::window-interior canvas) 28oct05 (cg::interior canvas) ;28oct05 )) (clip-bottom (host-to-screen-y (cg::box-bottom ;(cg::window-interior canvas) 28oct05 (cg::interior canvas) ;28oct05 ))) (clip-width ;(cg::window-interior-width canvas) 28oct05 (cg::width (cg::interior canvas)) ;28oct05 ) (clip-height ;(cg::window-interior-height canvas) 28oct05 (cg::height (cg::interior canvas)) ;28oct05 )) (make-region clip-left clip-bottom clip-width clip-height) ) )
1,617
Common Lisp
.l
33
36.818182
87
0.436387
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3d9d9a988d74c824fb282391e1d36419e5796790ca9f82d9b3efb47d2674c028
33,510
[ -1 ]
33,512
canvas-regions-pc.lsp
rwoldford_Quail/source/window-basics/canvas-regions/canvas-regions-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-regions-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; G.W. Bennett 1996 ;;;---------------------------------------------------------------------------------- (in-package :window-basics) #| (defun display-rect (window) "Returns the rectangle in which the display is drawn inside the window in ~ local coordinates." (when (wptr window) (let ((rgn (%get-ptr (rref (wptr window) :window.contRgn)))) (make-record :rect :top 0 :left 0 :bottom (- (%get-signed-word rgn 6) (%get-signed-word rgn 2) 15) :right (- (%get-signed-word rgn 8) (%get-signed-word rgn 4) 15))))) (defun display-rect-right (display-rect) (rref display-rect rect.right)) (defun display-rect-bottom (display-rect) (rref display-rect rect.bottom)) |#
1,443
Common Lisp
.l
32
39.875
87
0.495021
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9e06640679cd3cff444902dc6f8016883d22ad21d8533358fb238ba733657135
33,512
[ -1 ]
33,513
orig-drag-pc.lsp
rwoldford_Quail/source/window-basics/canvas-regions/orig-drag-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; drag-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(drag-region-on-canvas drag-region-on-screen select-rectangle select-canvas-rect select-screen-rect prompt-for-canvas sweep-for-canvas reshape-canvas-rect))) (defun calc-region (canvas &optional region left bottom width height) "Returns left bottom, width height as multiple values ~ if region is provided, its left bottom etc are used ~ if left or bottom are not provided, the mouse position is used instead." (when region (setq left (region-left region)) (setq bottom (region-bottom region)) (setq height (region-height region)) (setq width (region-width region))) (setq left (or left (if canvas (mouse-x canvas) (screen-mouse-x)))) (setq bottom (or bottom (- (if canvas (mouse-y canvas) (screen-mouse-y)) height))) (values left bottom width height)) (defun drag-region-on-canvas (canvas &key region (limit-region (canvas-region canvas)) left bottom (width 50) (height 50) (axis :both)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively. ~ Returns a region." ;; bounds for top ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; top -> draw-pt (declare (special :boole-xor cg::invert)) (sleep 10) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) (let* ((old-mouse NIL) (new-mouse NIL) (top (canvas-to-host-y canvas (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (canvas-to-host-y canvas (region-top limit-region))) (limit-bottom (canvas-to-host-y canvas (region-bottom limit-region))) (limit-right (region-right limit-region)) (draw-pt (screen-to-host-y (+ bottom height))) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower limit-left) (setf left-upper (max limit-left (- limit-right width))) ;; bounds Right ;;(setf right-upper limit-right) ;;(setf right-lower (min limit-right (+ limit-left width))) ;; bound draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position draw-pt (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let (position (cg::cursor-position canvas)) (list (cg::position-x position) (cg::position-y position))) ) ) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) (with-focused-canvas canvas (with-pen-values canvas NIL 1 :boole-xor ;; draw the rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) )) (make-region left (host-to-canvas-y canvas (+ draw-pt height)) width height) )) )) (defun drag-region-on-screen (canvas &key region left bottom (width 50) (height 50) (axis :both) (limit-region NIL)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively, :none => no motion. ~ Returns a region." ;; bounds for draw-pt ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; draw-pt -> draw-pt (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) (let* ((old-mouse NIL) (new-mouse NIL) (draw-pt (screen-to-host-y (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; wrap all this in the correct painting operation (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower (+ limit-left width)) (setf left-upper (max limit-right (+ limit-left width))) ;; bounds draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position Top (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) ;; draw the rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ) ;; Since we are drawing from bottom-right there is no need to add ;; height to draw-pt (make-region left (host-to-screen-y draw-pt ) width height) )) (defun select-rectangle (&key canvas (width 10) (height 10) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ If no canvas is supplied the action is taken on the screen in ~ screen coordinates. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas or screen. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ (or screen) coordinates." (if canvas (select-canvas-rect canvas width height limit-region) (select-screen-rect width height limit-region))) (defun select-canvas-rect (canvas &optional (width 0) (height 0) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." (declare (special *gray-shade* :boole-xor cg::invert)) (loop until (mouse-down-p )) (let* ((anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable (cg::frame-child canvas)) ) (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) (setq limit-region (or limit-region (canvas-region canvas))) (setf old-mouse (host-mouse-position)) (setf anchor-point (list (max (- (first old-mouse) width) (region-left limit-region)) (max (- (second old-mouse) height) (canvas-to-host-y canvas (region-top limit-region))) )) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (with-focused-canvas canvas (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 ; (with-pen-values canvas *gray-shade* 1 :boole-xor ;; draw the rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) (loop (unless (mouse-down-p ) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; update to get new one (cond ((> (first new-mouse) (first anchor-point)) (setf left (first anchor-point)) (setf width (- (first new-mouse) left))) (T (setf left (first new-mouse)) (setf width (- (first anchor-point) left)))) (cond ((> (second new-mouse) (second anchor-point)) (setf top (second anchor-point)) (setf height (- (second new-mouse) top))) (T (setf top (second new-mouse)) (setf height (- (second anchor-point) top)))) ;; draw it (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; slow down ;;(sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) );;end (with-pen-values );; end (with-focused-canvas (values left (- (canvas-to-host-y canvas top) height) ;;(+ top height) width height) );; end (flet ((host-mouse-position );; end (let* ((anchor-point );; end (defun select-canvas-rect (defun select-screen-rect ( &optional (width 50) (height 50) limit-region) "Mouse-selects a rectangle on the screen by selecting a location on the~ screen with the mouse and ~ sweeping out the region to be selected. The rectangle selected is confined to limit-region ~ which defaults to the boundary of the screen. ~ Returns the region information as ~ multiple values (left bottom width height) in ~ screen coordinates." (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) (let* ((root-window (cg::screen cg::*system*)) (anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable root-window) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) ) (flet ((host-mouse-position () (let ((pos (cg::with-device-context (hdc root-window) (cg::cursor-position drawable)))) (list (cg::position-x pos) (cg::position-y pos)))) (check-bound (old-list new-list) "Assumes old-left is current drawing left ~ old-draw is current drawing bottom ~ new-list comes from host-mouse-position ~ so its car is new-left, cdr is new-bottom.~ Checks for switches." (let ((old-left (first old-list)) (old-top (second old-list)) (new-left (first new-list)) (new-top (second new-list))) (cond ((and (>= new-left old-left) (>= new-top old-top)) (setf left old-left) (setf top old-top) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (>= new-left old-left) (< new-top old-top)) (setf left old-left) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) ((and (< new-left old-left) (>= new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top old-top) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (< new-left old-left) (< new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) )) (list left top width height) ) ) (setq limit-region (or limit-region (screen-region))) (loop until (mouse-down-p)) (setf old-mouse (host-mouse-position)) (setf anchor-point (copy-tree old-mouse)) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height))) (loop (unless (mouse-down-p) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; update to get new one (check-bound anchor-point old-mouse ) ;; draw it (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) );; end (loop ;; Finally erase it. (cg::with-device-context (hdc roo-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) );; end (cg::with-paint-operation (values left (- (screen-to-host-y top) height) width height) );; end (flet ((host-mouse-position );; end let* ((root-window ) (defun sweep-for-canvas (&rest args) "Sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (multiple-value-bind (left bottom width height) (select-rectangle) (apply #'make-canvas :left left :bottom bottom :width width :height height args))) (defun prompt-for-canvas (&rest args) "Prompts user to sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (declare (special *box-cursor*)) (quail-print "Sweep out a region for the canvas with the mouse.") (with-cursor *box-cursor* (apply #'sweep-for-canvas args))) (defun reshape-canvas-rect (canvas rect &key (draw? t) limit-region (corner-width 10)) "Reshapes a rectangle on the canvas using the mouse ~ to relocate the corner of rectangle closest to the mouse. ~ The selected corner should be within corner-width ~ (horizontally and vertically) of the mouse location.~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." (let ((d corner-width) mouse-x mouse-y vl vb vr vt fix-x fix-y move-x move-y) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (if draw? (draw-rect&corners canvas rect :corner-width d)) (loop until (mouse-down-p)) (setq mouse-x (mouse-x canvas) mouse-y (mouse-y canvas)) (if draw? (erase-rect&corners canvas rect :corner-width d)) (if (< mouse-x (truncate (+ vl vr) 2)) (setq move-x vl fix-x vr) (setq move-x vr fix-x vl)) (if (< mouse-y (truncate (+ vb vt) 2)) (setq move-y vb fix-y vt) (setq move-y vt fix-y vb)) (if (and (< (abs (- mouse-x move-x)) d) (< (abs (- mouse-y move-y)) d)) (select-rectangle :canvas canvas :limit-region limit-region :width (- mouse-x fix-x) :height (- fix-y mouse-y )))) )
32,320
Common Lisp
.l
694
30.157061
113
0.475392
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
fcd5fca5e0ab38d9c8c541dc7b8674583e89bd55c65939bea6447e2783656240
33,513
[ -1 ]
33,514
clip.lsp
rwoldford_Quail/source/window-basics/canvas-regions/clip.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; clip.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(clip-code clipped-bitblt clipped-bltshade clipped-draw-line clipped-draw-between clipped-draw-to clipped-relative-draw-to clipped-plot-at clipped-draw-string ))) ;; Clipped display functions (defun clip-code (x y left right top bottom) ;; Cohen-Sutherland clip codes. Assumes integer args RIGHT and ;; TOP are one past the region. (let ((abovebit (if (> y top) 8 0)) (belowbit (if (> bottom y) 4 0)) (rightbit (if (> x right) 2 0)) (leftbit (if (> left x) 1 0))) (logior abovebit belowbit rightbit leftbit))) (defun clipped-bitblt (canvas bitmap clipping-region &key (bitmap-left 0) (bitmap-bottom 0) (canvas-left 0) (canvas-bottom 0) operation (width (bitmap-width bitmap)) (height (bitmap-height bitmap))) ;; Assume that source must be a window or a bitmap -- and hence ;; has scale 1 Process defaults (let* ((clip-left (region-left clipping-region)) (clip-bottom (region-bottom clipping-region)) (clip-width (region-width clipping-region)) (clip-height (region-height clipping-region)) (new-left canvas-left) (new-bottom canvas-bottom) (new-width width) (new-height height) (clipped-p nil)) (when (> clip-left new-left) (setq clipped-p t) (setq new-width (- new-width (- clip-left new-left))) (setq new-left clip-left)) (when (> clip-bottom new-bottom) (setq clipped-p t) (setq new-height (- new-height (- clip-bottom new-bottom))) (setq new-bottom clip-bottom)) (when (> (+ new-left new-width) (+ clip-left clip-width)) (setq clipped-p t) (setq new-width (- (+ clip-left clip-width) new-left))) (when (> (+ new-bottom new-height) (+ clip-bottom clip-height)) (setq clipped-p t) (setq new-height (- (+ clip-bottom clip-height) new-bottom))) (cond ((null clipped-p) ;; No clipping (canvas-bitblt canvas bitmap :bitmap-left bitmap-left :bitmap-bottom bitmap-bottom :canvas-left canvas-left :canvas-bottom canvas-bottom :width width :height height :operation operation)) ((or (<= new-width 0) (<= new-height 0)) ;; Gross clipping nil) (t ;; Adjusted bitblt (canvas-bitblt canvas bitmap :bitmap-left (+ bitmap-left (- new-left canvas-left)) :bitmap-bottom (+ bitmap-bottom (- new-bottom canvas-bottom)) :canvas-left new-left :canvas-bottom new-bottom :width new-width :height new-height :operation operation))))) (defun clipped-bltshade (canvas texture clipping-region &key (canvas-left 0) (canvas-bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas)) operation) (let ((clip-left (region-left clipping-region)) (clip-bottom (region-bottom clipping-region)) (clip-width (region-width clipping-region)) (clip-height (region-height clipping-region)) (new-left canvas-left) (new-bottom canvas-bottom) (new-width width) (new-height height)) (when (> clip-left new-left) (setq new-width (- new-width (- clip-left new-left))) (setq new-left clip-left)) (when (> clip-bottom new-bottom) (setq new-height (- new-height (- clip-bottom new-bottom))) (setq new-bottom clip-bottom)) (if (> (+ new-left new-width) (+ clip-left clip-width)) (setq new-width (- (+ clip-left clip-width) new-left))) (if (> (+ new-bottom new-height) (+ clip-bottom clip-height)) (setq new-height (- (+ clip-bottom clip-height) new-bottom))) (if (or (>= 0 new-width) (>= 0 new-height)) ;; Gross clipping nil ;; Adjusted bitblt (canvas-bltshade canvas texture :canvas-left new-left :canvas-bottom new-bottom :width new-width :height new-height :operation operation)))) ;;; Clip against CLIPPINGREGION and draw in STREAM. Implements ;;; Cohen-Sutherland clipping. From Foley and Van Dam, pg. 146 (defun clipped-draw-line (canvas x1 y1 x2 y2 clipping-region &key width operation color dashing) (with-focused-canvas canvas (let* ((clip-left (region-left clipping-region)) (clip-bottom (region-bottom clipping-region)) (clip-right (1- (+ clip-left (region-width clipping-region)))) (clip-top (1- (+ clip-bottom (region-height clipping-region)))) (old-x2 x2) (old-y2 y2) (accept-p nil) (done-p nil) outcode-1 outcode-2) (loop (if done-p (return nil)) (setq outcode-1 (clip-code x1 y1 clip-left clip-right clip-top clip-bottom)) (setq outcode-2 (clip-code x2 y2 clip-left clip-right clip-top clip-bottom)) (if (= 0 (logand outcode-1 outcode-2)) ;; Possible accept (if (setq accept-p (= 0 (logior outcode-1 outcode-2))) (setq done-p t) ;; accept (progn ;; Find intersections (when (= 0 outcode-1) ;; Swap points so (X1 Y1) is guaranteed to be outside (rotatef x1 x2) (rotatef y1 y2) (rotatef outcode-1 outcode-2)) (cond ((/= 0 (logand outcode-1 8)) ;; divide line at top (incf x1 (truncate (* (- x2 x1) (- clip-top y1)) (- y2 y1))) (setq y1 clip-top)) ((not (= 0 (logand outcode-1 4))) ;; divide line at bottom (incf x1 (truncate (* (- x2 x1) (- clip-bottom y1)) (- y2 y1))) (setq y1 clip-bottom)) ((/= 0 (logand outcode-1 2)) ;; divide line at right (incf y1 (truncate (* (- y2 y1) (- clip-right x1)) (- x2 x1))) (setq x1 clip-right)) (t ;; divide line at left (incf y1 (truncate (* (- y2 y1) (- clip-left x1)) (- x2 x1))) (setq x1 clip-left))))) ;; Reject (setq done-p t))) (when accept-p ;; actually draw a line if one accepted (canvas-draw-line canvas x1 y1 x2 y2 :width width :operation operation :color color :dashing dashing)) ;; Correctly update position in stream (canvas-move-to canvas old-x2 old-y2)))) (defun clipped-draw-between (canvas position-1 position-2 clipping-region &key width operation color dashing) (clipped-draw-line canvas (position-x position-1) (position-y position-1) (position-x position-2) (position-y position-2) clipping-region :width width :operation operation :color color :dashing dashing)) (defun clipped-draw-to (canvas x y clipping-region &key width operation color dashing) (clipped-draw-line canvas (canvas-x canvas) (canvas-y canvas) x y clipping-region :width width :operation operation :color color :dashing dashing)) (defun clipped-relative-draw-to (canvas dx dy clipping-region &key width operation color dashing) (let ((x (canvas-x canvas)) (y (canvas-y canvas))) (clipped-draw-line canvas x y (+ x dx) (+ y dy) clipping-region :width width :operation operation :color color :dashing dashing))) (defun clipped-plot-at (canvas position-x position-y glyph clipping-region &key operation) (let* ((glyph-width (bitmap-width glyph)) (glyph-height (bitmap-height glyph)) (newx (- position-x (truncate glyph-width 2))) (newy (- position-y (truncate glyph-height 2)))) (clipped-bitblt glyph canvas clipping-region :canvas-left newx :canvas-bottom newy :width glyph-width :height glyph-height :operation operation))) (defun clipped-draw-string (canvas string clipping-region) "Draw the string clipped to the given region of the canvas." (let ((string-region (canvas-string-region canvas string))) (if (subregion-p clipping-region string-region) (canvas-princ-string canvas string) (let ((iregion (intersect-regions string-region clipping-region))) (if (and iregion (= (region-height iregion) (region-height string-region))) ;; Some chars visible (let* ((minx (region-left clipping-region)) (maxx (+ minx (region-width clipping-region))) (x (canvas-x canvas)) (y (canvas-y canvas))) (dotimes (i (length string)) (let* ((char (char string i)) (charwidth (canvas-character-width canvas char)) (nextx (+ x charwidth))) (if (not (or (< x minx) (> nextx maxx))) (canvas-draw-character canvas char) (canvas-move-to canvas nextx y)) (setq x nextx)))))))))
10,933
Common Lisp
.l
239
33.129707
126
0.527654
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f33bb97eb27bbd844f59ecadd050b9ba1d5a5ad9143d2b4d4c96bf0a4e695a0d
33,514
[ -1 ]
33,516
canvas-regions.lsp
rwoldford_Quail/source/window-basics/canvas-regions/canvas-regions.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; canvas-regions.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; G. Desvignes 1988,1989 ;;; R.W. Oldford 1988-1992 ;;; ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :window-basics) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-region canvas-bounds set-canvas-region canvas-x-offset canvas-y-offset set-canvas-x-offset set-canvas-y-offset extent-region-of set-extent-canvas-region ))) (defun canvas-region (canvas) "Returns the region of the canvas that is displayed (in canvas-coordinates)." (make-region 0 0 (canvas-width canvas) (canvas-height canvas))) (defun canvas-bounds (canvas) (region-bounds (canvas-region canvas)) ) (defun set-canvas-region (canvas new-region) (shape-canvas canvas new-region)) (defun canvas-x-offset (canvas) (region-left (canvas-region canvas))) (defun canvas-y-offset (canvas) (region-bottom (canvas-region canvas))) (defun set-canvas-x-offset (canvas value) (let ((er (canvas-region canvas))) (setf (region-left er) value) (set-canvas-region canvas er))) (defun set-canvas-y-offset (canvas value) (let ((er (canvas-region canvas))) (setf (region-bottom er) value) (set-canvas-region canvas er))) (defun extent-region-of (canvas) (canvas-region canvas)) (defun set-extent-canvas-region (canvas extent) (shape-canvas canvas extent)) ;;(setf (extent-region-of canvas) extent))
2,109
Common Lisp
.l
54
34.944444
112
0.580741
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
898c4f3e4a8ed16c6b7babcdfe864a7a98e3d402beaa1a6eebcfa088eb302a1f
33,516
[ -1 ]
33,517
drag-sblx.lsp
rwoldford_Quail/source/window-basics/canvas-regions/drag-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; drag-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(drag-region-on-canvas drag-region-on-screen select-rectangle select-canvas-rect select-screen-rect prompt-for-canvas sweep-for-canvas reshape-canvas-rect))) (defun calc-region (canvas &optional region left bottom width height) "Returns left bottom, width height as multiple values ~ if region is provided, its left bottom etc are used ~ if left or bottom are not provided, the mouse position is used instead." (when region (setq left (region-left region)) (setq bottom (region-bottom region)) (setq height (region-height region)) (setq width (region-width region))) (setq left (or left (if canvas (mouse-x canvas) (screen-mouse-x)))) (setq bottom (or bottom (- (if canvas (mouse-y canvas) (screen-mouse-y)) height))) (values left bottom width height)) (defun drag-region-on-canvas (canvas &key region (limit-region (canvas-region canvas)) left bottom (width 50) (height 50) (axis :both)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively. ~ Returns a region." ;; bounds for top ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; top -> draw-pt ;(declare (special :boole-xor cg::invert)) (sleep 10) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ Wrap all this in a with-device-context ;;+ to see whether this will allow sweeping rather than freezing ;;+ 08 Dec 2014 gwb (let* ((old-mouse NIL) (new-mouse NIL) ;(top (canvas-to-host-y canvas ; (+ bottom height))) ;13MAY2024 (limit-left (region-left limit-region)) (limit-top (canvas-to-host-y canvas (region-top limit-region))) (limit-bottom (canvas-to-host-y canvas (region-bottom limit-region))) (limit-right (region-right limit-region)) (draw-pt (screen-to-host-y (+ bottom height))) ;(drawable (graft canvas));(drawable (cg::parent canvas)) ;13MAY2024 (mp (get-frame-pane canvas 'host-pane)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower limit-left) (setf left-upper (max limit-left (- limit-right width))) ;; bounds Right ;;(setf right-upper limit-right) ;;(setf right-lower (min limit-right (+ limit-left width))) ;; bound draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position draw-pt (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (flet ((host-mouse-position () (let ((position (multiple-value-bind (z1 z2) (stream-cursor-position mp) (list z1 z2))));(cg::cursor-position canvas) position));(cg::position-x position) (cg::position-y position))) ) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) (with-focused-canvas canvas (with-pen-values canvas NIL 1 :boole-xor ;; draw rectangle (h-draw:draw-rectangle canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(::make-box left draw-pt (+ left width) (+ draw-pt height))) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (h-draw:draw-rectangle canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) ; end :both (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (h-draw:draw-rectangle canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) ; end x: (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (h-draw:draw-rectangle canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) ; end y: (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; draw it (h-draw:draw-rectangle canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ) ) ; end :none ) ; end ecase ;; Finally erase it. (h-draw:erase-rect canvas left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box canvas ;(cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) ; with-pen-values ) ; end with-focused-canvas (make-region left (host-to-canvas-y canvas (+ draw-pt height)) width height) ) ; end flet ) ;; end of let* ) (defun drag-region-on-screen (canvas &key region left bottom (width 50) (height 50) (axis :both) (limit-region NIL)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively, :none => no motion. ~ Returns a region." ;; bounds for draw-pt ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; draw-pt -> draw-pt (unless limit-region (setf limit-region (screen-region))) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ See above about wrapper (let* ((old-mouse NIL) (new-mouse NIL) (draw-pt (screen-to-host-y (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) (drawable (graft canvas)) (mp (get-frame-pane canvas 'host-pane)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) (flet ((host-mouse-position () (let ((position (multiple-value-bind (z1 z2) (stream-cursor-position mp) (list z1 z2))));(cg::cursor-position canvas) position));(cg::position-x position) (cg::position-y position))) ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower (+ limit-left width)) (setf left-upper (max limit-right (+ limit-left width))) ;; bounds draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position Top (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) ;; draw the rectangle (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ; end :both (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ; end x: (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ; end y: (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; draw it (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ) ) ; end :none ) ; end ecase ;; Finally erase it. (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ; end flet ;; Since we are drawing from bottom-right there is no need to add ;; height to draw-pt (make-region left (host-to-screen-y draw-pt ) width height) ) ; end let* ) (defun select-rectangle (&key canvas (width 10) (height 10) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ If no canvas is supplied the action is taken on the screen in ~ screen coordinates. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas or screen. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ (or screen) coordinates." (if canvas (select-canvas-rect canvas width height limit-region) (select-screen-rect width height limit-region))) (defun select-canvas-rect (canvas &optional (width 0) (height 0) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." (declare (special *gray-shade* )) ;:boole-xor cg::invert)) (loop until (mouse-down-p )) ;(format t "~%Data from select-canvas-rect:") ;06FEB2015 (let* ((anchor-point NIL) ;(original-mouse-position NIL) ;07FEB2015 ;(final-mouse-position NIL) ;07FEB2015 ;(original-anchor-point NIL) ;07FEB2015 (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (draw-pt (screen-to-host-y (+ bottom height))) (drawable (get-frame-pane canvas 'host-pane)) ) (flet ((host-mouse-position () (let ((position (multiple-value-bind (z1 z2) (stream-cursor-position drawable) (list z1 z2))));(cg::cursor-position canvas) position));(cg::position-x position) (cg::position-y position))) ) ;(format t "~%host-mouse-position is ~s " (host-mouse-position)) ;06FEB2015 (setq limit-region (or limit-region (canvas-region canvas))) ;(format t "~%limit-region is ~s " limit-region) ;06FEB2015 (setf old-mouse (host-mouse-position)) (setf anchor-point (list (max (- (first old-mouse) width) (region-left limit-region)) (max (- (second old-mouse) height) (canvas-to-host-y canvas (region-top limit-region))) )) ;(setf original-anchor-point anchor-point) ;07FEB2015 ;(format t "~%anchor-point is ~s " anchor-point) ;06FEB2015 (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) ;(setf original-mouse-position (host-mouse-position)) ;07FEB2015 ;(format t "~%original-mouse-position is ~s " original-mouse-position) (with-focused-canvas canvas ;; draw the rectangle (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height)) (loop (unless (mouse-down-p ) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height)) ) ;; update to get new one (cond ((> (first new-mouse) (first anchor-point)) (setf left (first anchor-point)) (setf width (- (first new-mouse) left))) (T (setf left (first new-mouse)) (setf width (- (first anchor-point) left)))) (cond ((> (second new-mouse) (second anchor-point)) (setf top (second anchor-point)) (setf height (- (second new-mouse) top))) (T (setf top (second new-mouse)) (setf height (- (second anchor-point) top)))) ;; draw it (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ; (cg::make-box left top (+ left width) (+ top height)) ; ) ;; slow down ;;(sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) ;end loop (setq new-mouse (host-mouse-position)) ;(setf final-mouse-position (host-mouse-position)) ;07FEB2015 ;(format t "~% final-mouse-position is ~s " final-mouse-position) ;; Finally erase it. (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height)) );; end (with-focused-canvas ;; HERE (values left (- (canvas-to-host-y canvas top) height) ;;(+ top height) width height) );; end (flet ((host-mouse-position );; end (let* ((anchor-point );; end (defun select-canvas-rect (defun select-screen-rect ( &optional (width 50) (height 50) limit-region) "Mouse-selects a rectangle on the screen by selecting a location on the~ screen with the mouse and ~ sweeping out the region to be selected. The rectangle selected is confined to limit-region ~ which defaults to the boundary of the screen. ~ Returns the region information as ~ multiple values (left bottom width height) in ~ screen coordinates." ;(declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) (let* ((root-window (find-graft)) ;(cg::screen cg::*system*)) (anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable root-window) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) (draw-pt (screen-to-host-y (+ limit-bottom height))) ) (flet ((host-mouse-position () (let ((position (multiple-value-bind (z1 z2) (stream-cursor-position drawable) (list z1 z2))));(cg::cursor-position canvas) position));(cg::position-x position) (cg::position-y position))) (check-bound (old-list new-list) "Assumes old-left is current drawing left ~ old-draw is current drawing bottom ~ new-list comes from host-mouse-position ~ so its car is new-left, cdr is new-bottom.~ Checks for switches." (let ((old-left (first old-list)) (old-top (second old-list)) (new-left (first new-list)) (new-top (second new-list))) (cond ((and (>= new-left old-left) (>= new-top old-top)) (setf left old-left) (setf top old-top) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (>= new-left old-left) (< new-top old-top)) (setf left old-left) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) ((and (< new-left old-left) (>= new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top old-top) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (< new-left old-left) (< new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) ) ;end cond ) ; end let (list left top width height) ) ; end check-bound ) ; end outer ((host-mouse (setq limit-region (or limit-region (screen-region))) (loop until (mouse-down-p)) (setf old-mouse (host-mouse-position)) (setf anchor-point (copy-tree old-mouse)) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) ;; draw-rectangle (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height))) (loop (unless (mouse-down-p) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::with-device-context (hdc root-window) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height)))) ;; update to get new one (check-bound anchor-point old-mouse ) ;; draw it (h-draw:draw-rectangle drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::with-device-context (hdc root-window) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height)))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) );; end (loop ;; Finally erase it. (h-draw:erase-rect drawable left draw-pt (+ left width) (+ draw-pt height)) ;(cg::with-device-context (hdc root-window) ;(cg::draw-box drawable ;(cg::make-box left top (+ left width) (+ top height)))) (values left (- (screen-to-host-y top) height) width height) );; end (flet ((host-mouse-position );; end let* ((root-window ) (defun sweep-for-canvas (&rest args) "Sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (multiple-value-bind (left bottom width height) (select-rectangle) (apply #'make-canvas :left left :bottom bottom :width width :height height args))) (defun prompt-for-canvas (&rest args) "Prompts user to sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (declare (special *box-cursor*)) (quail-print "Sweep out a region for the canvas with the mouse.") (with-cursor *box-cursor* (apply #'sweep-for-canvas args))) (defun reshape-canvas-rect (canvas rect &key (draw? t) limit-region (corner-width 10)) "Reshapes a rectangle on the canvas using the mouse ~ to relocate the corner of rectangle closest to the mouse. ~ The selected corner should be within corner-width ~ (horizontally and vertically) of the mouse location.~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." ;;+ See above about wrapper (let ((d corner-width) mouse-x mouse-y vl vb vr vt fix-x fix-y move-x move-y) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (if draw? (draw-rect&corners canvas rect :corner-width d)) (loop until (mouse-down-p)) (setq mouse-x (mouse-x canvas) mouse-y (mouse-y canvas)) (if draw? (erase-rect&corners canvas rect :corner-width d)) (if (< mouse-x (truncate (+ vl vr) 2)) (setq move-x vl fix-x vr) (setq move-x vr fix-x vl)) (if (< mouse-y (truncate (+ vb vt) 2)) (setq move-y vb fix-y vt) (setq move-y vt fix-y vb)) (if (and (< (abs (- mouse-x move-x)) d) (< (abs (- mouse-y move-y)) d)) (select-rectangle :canvas canvas :limit-region limit-region :width (- mouse-x fix-x) :height (- fix-y mouse-y )))) )
36,813
Common Lisp
.l
731
33.894665
143
0.490363
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
957692dfd724c101180f31b1c0588b9a52d2433fdf0ed9fe78610217ffc07eb3
33,517
[ -1 ]
33,519
original-drag-pc.lsp
rwoldford_Quail/source/window-basics/canvas-regions/original-drag-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; drag-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(drag-region-on-canvas drag-region-on-screen select-rectangle select-canvas-rect select-screen-rect prompt-for-canvas sweep-for-canvas reshape-canvas-rect))) (defun calc-region (canvas &optional region left bottom width height) "Returns left bottom, width height as multiple values ~ if region is provided, its left bottom etc are used ~ if left or bottom are not provided, the mouse position is used instead." (when region (setq left (region-left region)) (setq bottom (region-bottom region)) (setq height (region-height region)) (setq width (region-width region))) (setq left (or left (if canvas (mouse-x canvas) (screen-mouse-x)))) (setq bottom (or bottom (- (if canvas (mouse-y canvas) (screen-mouse-y)) height))) (values left bottom width height)) (defun drag-region-on-canvas (canvas &key region (limit-region (canvas-region canvas)) left bottom (width 50) (height 50) (axis :both)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively. ~ Returns a region." ;; bounds for top ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; top -> draw-pt (declare (special :boole-xor cg::invert)) (sleep 10) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ Wrap all this in a with-device-context ;;+ to see whether this will allow sweeping rather than freezing ;;+ 08 Dec 2014 gwb (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((old-mouse NIL) (new-mouse NIL) (top (canvas-to-host-y canvas (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (canvas-to-host-y canvas (region-top limit-region))) (limit-bottom (canvas-to-host-y canvas (region-bottom limit-region))) (limit-right (region-right limit-region)) (draw-pt (screen-to-host-y (+ bottom height))) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower limit-left) (setf left-upper (max limit-left (- limit-right width))) ;; bounds Right ;;(setf right-upper limit-right) ;;(setf right-lower (min limit-right (+ limit-left width))) ;; bound draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position draw-pt (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let (position (cg::cursor-position canvas)) (list (cg::position-x position) (cg::position-y position))) ) ) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) (with-focused-canvas canvas (with-pen-values canvas NIL 1 :boole-xor ;; draw the rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box canvas (cg::make-box left draw-pt (+ left width) (+ draw-pt height))) )) (make-region left (host-to-canvas-y canvas (+ draw-pt height)) width height) )) )) ) (defun drag-region-on-screen (canvas &key region left bottom (width 50) (height 50) (axis :both) (limit-region NIL)) "With mouse already depressed, ~ drags a region around following mouse position. ~ If left or bottom are not provided, the mouse position is used instead. ~ Axis = :x or :y limits motion to x or y axis respectively, :none => no motion. ~ Returns a region." ;; bounds for draw-pt ... remember we're in the upside down host mode ;; which means that a zero is the top of the screen and ;; 600 is its bottom ... ;; AND we are drawing with the cursor at the bottom-right of ;; little region we are dragging about. ;; SO .. the minimum value for the bottom-right is ;; the top of the screen (0) + the height of the region ;; otherwise the region's top will poke above the top of the ;; screen .. ;; and the maximum value for the bottom-right is ;; limit-bottom or the bottom of the region ;; will slip below the end of the screen. ;; Hence gwb has re-named some things as follows ;; min-draw-corner -> min-draw-corner ;; max-draw-corner -> max-draw-corner ;; draw-pt -> draw-pt (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) (multiple-value-setq (left bottom width height) (calc-region canvas region left bottom width height)) (if (eql :none axis) ;allow no motion (setq limit-region (make-region left bottom width height))) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((old-mouse NIL) (new-mouse NIL) (draw-pt (screen-to-host-y (+ bottom height))) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) (drawable (cg::parent canvas)) left-lower left-upper ;;right-lower right-upper ;;bottom-lower bottom-upper min-draw-corner max-draw-corner ) ;; wrap all this in the correct painting operation (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) ;; Get width right (setf width (min width (- limit-right limit-left))) ;; Get height right (setf height (min height (- limit-bottom limit-top))) ;; bounds Left (setf left-lower (+ limit-left width)) (setf left-upper (max limit-right (+ limit-left width))) ;; bounds draw-pt (setf min-draw-corner (+ limit-top height)) (setf max-draw-corner limit-bottom ) ;; bounds Bottom ... remember we're in the upside down host mode ;;(setf bottom-upper limit-bottom) ;;(setf bottom-lower (min limit-bottom (+ limit-top height))) ;; starting position Left (cond ((< left left-lower) (setf left left-lower)) ((> left left-upper) (setf left left-upper))) ;; starting position Top (cond ((< draw-pt min-draw-corner) (setf draw-pt min-draw-corner)) ((> draw-pt max-draw-corner) (setf draw-pt max-draw-corner))) (setf old-mouse (host-mouse-position)) (setf new-mouse (copy-tree old-mouse)) ;; draw the rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) (ecase axis (:both (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:x (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf left (max left-lower (min (first new-mouse) left-upper))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:y (loop ;; until mouse button is released (unless (mouse-down-p) (return)) (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; update to get new one (setf draw-pt (max min-draw-corner (min (second new-mouse) max-draw-corner))) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) (:none (loop ;; until mouse button is released (unless (mouse-down-p) (return)) ;; erase rectangle (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ;; draw it (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ;; slow down (sleep 1/60) ) ) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box (- left width) (- draw-pt height) left draw-pt)) ) ) ;; Since we are drawing from bottom-right there is no need to add ;; height to draw-pt (make-region left (host-to-screen-y draw-pt ) width height) )) ) (defun select-rectangle (&key canvas (width 10) (height 10) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ If no canvas is supplied the action is taken on the screen in ~ screen coordinates. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas or screen. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ (or screen) coordinates." (if canvas (select-canvas-rect canvas width height limit-region) (select-screen-rect width height limit-region))) (defun select-canvas-rect (canvas &optional (width 0) (height 0) limit-region) "Mouse-selects a rectangle on the canvas by selecting in canvas and ~ sweeping out the region to be selected. ~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." (declare (special *gray-shade* :boole-xor cg::invert)) (loop until (mouse-down-p )) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable (cg::frame-child canvas)) ) (flet ((host-mouse-position () (let ((pos (cg::cursor-position drawable))) (list (cg::position-x pos) (cg::position-y pos)))) ) (setq limit-region (or limit-region (canvas-region canvas))) (setf old-mouse (host-mouse-position)) (setf anchor-point (list (max (- (first old-mouse) width) (region-left limit-region)) (max (- (second old-mouse) height) (canvas-to-host-y canvas (region-top limit-region))) )) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (with-focused-canvas canvas (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 ; (with-pen-values canvas *gray-shade* 1 :boole-xor ;; draw the rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) (loop (unless (mouse-down-p ) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; update to get new one (cond ((> (first new-mouse) (first anchor-point)) (setf left (first anchor-point)) (setf width (- (first new-mouse) left))) (T (setf left (first new-mouse)) (setf width (- (first anchor-point) left)))) (cond ((> (second new-mouse) (second anchor-point)) (setf top (second anchor-point)) (setf height (- (second new-mouse) top))) (T (setf top (second new-mouse)) (setf height (- (second anchor-point) top)))) ;; draw it (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) ;; slow down ;;(sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) ) ;; Finally erase it. (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)) ) );;end (with-pen-values );; end (with-focused-canvas (values left (- (canvas-to-host-y canvas top) height) ;;(+ top height) width height) );; end (flet ((host-mouse-position );; end (let* ((anchor-point ) ;; end wrapper );; end (defun select-canvas-rect (defun select-screen-rect ( &optional (width 50) (height 50) limit-region) "Mouse-selects a rectangle on the screen by selecting a location on the~ screen with the mouse and ~ sweeping out the region to be selected. The rectangle selected is confined to limit-region ~ which defaults to the boundary of the screen. ~ Returns the region information as ~ multiple values (left bottom width height) in ~ screen coordinates." (declare (special :boole-xor cg::invert)) (unless limit-region (setf limit-region (screen-region))) ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((root-window (cg::screen cg::*system*)) (anchor-point NIL) (old-mouse NIL) (new-mouse NIL) (left NIL) (top NIL) (drawable root-window) (limit-left (region-left limit-region)) (limit-top (screen-to-host-y (region-top limit-region))) (limit-bottom (screen-to-host-y (region-bottom limit-region))) (limit-right (region-right limit-region)) ) (flet ((host-mouse-position () (let ((pos (cg::with-device-context (hdc root-window) (cg::cursor-position drawable)))) (list (cg::position-x pos) (cg::position-y pos)))) (check-bound (old-list new-list) "Assumes old-left is current drawing left ~ old-draw is current drawing bottom ~ new-list comes from host-mouse-position ~ so its car is new-left, cdr is new-bottom.~ Checks for switches." (let ((old-left (first old-list)) (old-top (second old-list)) (new-left (first new-list)) (new-top (second new-list))) (cond ((and (>= new-left old-left) (>= new-top old-top)) (setf left old-left) (setf top old-top) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (>= new-left old-left) (< new-top old-top)) (setf left old-left) (setf width (min (- new-left old-left) (- limit-right old-left))) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) ((and (< new-left old-left) (>= new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top old-top) (setf height (min (- new-top old-top) (- limit-bottom old-top))) ) ((and (< new-left old-left) (< new-top old-top)) (setf left (max limit-left new-left)) (setf width (- old-left left)) (setf top (max limit-top new-top)) (setf height (- old-top top)) ) )) (list left top width height) ) ) (setq limit-region (or limit-region (screen-region))) (loop until (mouse-down-p)) (setf old-mouse (host-mouse-position)) (setf anchor-point (copy-tree old-mouse)) (setf new-mouse (copy-tree old-mouse)) (setf left (first anchor-point)) (setf top (second anchor-point)) (cg::with-paint-operation ;(drawable cg::invert) 19oct05 (drawable cg::po-invert) ;19oct05 (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height))) (loop (unless (mouse-down-p) (return)) ;return when the mouse lets up (unless (equal old-mouse new-mouse) ;; erase rectangle (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; update to get new one (check-bound anchor-point old-mouse ) ;; draw it (cg::with-device-context (hdc root-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) ;; slow down (sleep 1/60) ;; update iteration (setq old-mouse new-mouse)) (setq new-mouse (host-mouse-position)) );; end (loop ;; Finally erase it. (cg::with-device-context (hdc roo-window) (cg::draw-box drawable (cg::make-box left top (+ left width) (+ top height)))) );; end (cg::with-paint-operation (values left (- (screen-to-host-y top) height) width height) );; end (flet ((host-mouse-position );; end let* ((root-window );; end with-device-context ) (defun sweep-for-canvas (&rest args) "Sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (multiple-value-bind (left bottom width height) (select-rectangle) (apply #'make-canvas :left left :bottom bottom :width width :height height args))) (defun prompt-for-canvas (&rest args) "Prompts user to sweep out a region on the screen to determine the ~ size and location of the canvas which will be returned." (declare (special *box-cursor*)) (quail-print "Sweep out a region for the canvas with the mouse.") (with-cursor *box-cursor* (apply #'sweep-for-canvas args))) (defun reshape-canvas-rect (canvas rect &key (draw? t) limit-region (corner-width 10)) "Reshapes a rectangle on the canvas using the mouse ~ to relocate the corner of rectangle closest to the mouse. ~ The selected corner should be within corner-width ~ (horizontally and vertically) of the mouse location.~ The rectangle selected is confined to limit-region ~ which defaults to the boundary of the canvas. ~ Returns the region information as ~ multiple values (left bottom width height) in canvas ~ coordinates." ;;+ See above about wrapper (cg::with-device-context (hdc (cg::screen cg::*system*)) (let ((d corner-width) mouse-x mouse-y vl vb vr vt fix-x fix-y move-x move-y) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (if draw? (draw-rect&corners canvas rect :corner-width d)) (loop until (mouse-down-p)) (setq mouse-x (mouse-x canvas) mouse-y (mouse-y canvas)) (if draw? (erase-rect&corners canvas rect :corner-width d)) (if (< mouse-x (truncate (+ vl vr) 2)) (setq move-x vl fix-x vr) (setq move-x vr fix-x vl)) (if (< mouse-y (truncate (+ vb vt) 2)) (setq move-y vb fix-y vt) (setq move-y vt fix-y vb)) (if (and (< (abs (- mouse-x move-x)) d) (< (abs (- mouse-y move-y)) d)) (select-rectangle :canvas canvas :limit-region limit-region :width (- mouse-x fix-x) :height (- fix-y mouse-y )))) ) ;; end with-device-context )
32,973
Common Lisp
.l
711
30.261603
113
0.478861
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
197bd753363ac10190e0273622d37e59031cf2b81c3462cbcb8c4bbcea894e58
33,519
[ -1 ]
33,520
out-from-instrumented.lsp
rwoldford_Quail/source/window-basics/canvas-regions/out-from-instrumented.lsp
(format t "~% Values to be returned: ") ;06FEB2015 (format t "~%left is ~d " (min (first anchor-point) (first original-mouse-position) (first final-mouse-position))) ;07FEB2015 ;(format t "~%left is ~d " left) ;06FEB2015 (format t "~%top is ~d " (min (second anchor-point) (second original-mouse-position) (second final-mouse-position))) ;07FEB2015 ;(format t "~% (- (canvas-to-host-y canvas top) height) is ~d " (- (canvas-to-host-y canvas top) height)) ;06FEB2015 (format t "~%width is ~d " width) ;06FEB2015 (format t "~%height is ~d " height) ;06FEB2015 (format t "~%host-mouse-position is now ~s " (host-mouse-position)) ;06FEB2015 (values (min (first anchor-point) (first original-mouse-position) (first final-mouse-position)) ; 07FEB22015left (cond ((and ( > (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (canvas-to-host-y canvas (second final-mouse-position))) ((and (< (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (canvas-to-host-y canvas (second final-mouse-position))) ((and (< (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (canvas-to-host-y canvas (second original-mouse-position))) (T ;(and (> (first final-mouse-position) (first original-mouse-position)) ;(< (second final-mouse-position) (second original-mouse-position)) ;) (canvas-to-host-y canvas (second original-mouse-position))) ) ;(min (second anchor-point) (second original-mouse-position) (second final-mouse-position)) ;07FEB2015 ; 07FEB2015(- (canvas-to-host-y canvas top) height) ;;(+ top height) (cond ((and ( > (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (first final-mouse-position) (min (first anchor-point) (first original-mouse-position))) ) ((and (< (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (max (first anchor-point) (first original-mouse-position)) (first final-mouse-position))) ((and (< (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (- (max (first anchor-point) (first original-mouse-position)) (first final-mouse-position))) (T ;(and (> (first final-mouse-position) (first original-mouse-position)) ;(< (second final-mouse-position) (second original-mouse-position)) ;) (- (first final-mouse-position) (min (first anchor-point) (first original-mouse-position)) ) ) );; end width (cond ((and ( > (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (second final-mouse-position) (min (second anchor-point) (second original-mouse-position))) ) ((and (< (first final-mouse-position) (first original-mouse-position)) (> (second final-mouse-position) (second original-mouse-position)) ) (- (second final-mouse-position) (min (second anchor-point) (second original-mouse-position))) ) ((and (< (first final-mouse-position) (first original-mouse-position)) (< (second final-mouse-position) (second original-mouse-position)) ) (- (max (second anchor-point) (second original-mouse-position)) (second final-mouse-position))) (T ;(and (> (first final-mouse-position) (first original-mouse-position)) ;(< (second final-mouse-position) (second original-mouse-position)) ;) (- (max (second anchor-point) (second original-mouse-position)) (second final-mouse-position)) ) );; end height ;width height ;07FEB2015
5,393
Common Lisp
.l
69
52.478261
138
0.501784
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f80bc0c16d70f99648670ccbd05396bbaa1a600c2362f93517892b8e307ad900
33,520
[ -1 ]
33,521
menu.lsp
rwoldford_Quail/source/window-basics/menus/menu.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; menu.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; History: ;;; ;;; - A hierarchical pop-up menu system implemented at the University of Waterloo ;;; as part of the Window-Basics generic window-system interface. ;;; ;;; - The system roughly follows the Xerox Interlisp-D menu model. ;;; ;;; ;;; The Model: ;;; ;;; - A menu is a uniform means to select an item from a list of items ;;; and have something happen as a consequence. ;;; ;;; - A menu is a data structure with the slots (or fields or ...) as ;;; described below. ;;; ;;; items - The list of items to appear in the menu. If the item is a list ;;; then its CAR will appear in the menu. ;;; The default selection functions interpret each item as a list of ;;; three elements: ;;; - a label ;;; - a form whose value is returned upon selection, or ;;; a function which is applied to the value of the ;;; special variable *current-canvas*, and ;;; - a help string which can be printed. ;;; Should a fourth element exist, it is ignored by the default ;;; selection functions but is interpreted by the default sub-item ;;; function. In particular, if the fourth element is the keyword ;;; :sub-items then the fifth element of the list is taken to be a ;;; list of sub-items by the default sub-item function. ;;; These sub-items are just items which appear lower in the menu ;;; hierarchy. ;;; ;;; sub-item-fn - A function to be called to determine whether a given item ;;; has any subitems. It is called with two arguments: ;;; - the menu, and ;;; - the item. ;;; It should return a list of the subitems, if any (NIL otherwise). ;;; If an item has sub-items and the user moves the mouse-cursor ;;; off to the right of that item, a sub-menu will appear having ;;; the sub-items as its items. Selecting from the sub-menu is ;;; handled as if selecting from the main menu. ;;; The default sub-item-fn is called default-sub-item-fn and ;;; simply checks to see whether the item is a list whose fourth ;;; element is the keyword :sub-items. If so, it returns the ;;; fifth element in the list; otherwise it returns NIL. ;;; ;;; when-selected-fn - A function to be called when an item is selected. ;;; It is called with three arguments: ;;; - the item selected, ;;; - the menu, and ;;; - the last mouse key released (:left, :middle, or :right). ;;; The default function, default-when-selected-fn evaluates and ;;; returns the value of the second element of the item if the item ;;; is a list of at least length 2. Otherwise the item is returned. ;;; ;;; when-held-fn - A function called when the user has held a mouse key on ;;; an item for *menu-held-wait* milliseconds (initially 1200). ;;; It is intended to be a means to prompt users. As the default, ;;; default-when-held-fn prints the third element of the item (i.e. ;;; its help string) in the user prompt window. If that element is ;;; missing, the string "This item will be selected when the button ;;; is released." will be printed. ;;; The function takes three arguments: ;;; - the item selected, ;;; - the menu, and ;;; - the last mouse key released (:left, :middle, or :right). ;;; ;;; when-unheld-fn - A function called when:(1) the cursor leaves the ;;; item, or (2) when a mouse button is released, or (3) when ;;; another key is pressed. It's called with the same three ;;; arguments as the when-held-fn and is intended to be used ;;; to clean up after the when-held-fn function. For example, ;;; default-when-unheld-fn clears the prompt window. ;;; ;;; font - The font in which the items will appear in the menu. ;;; Default is value of *default-menu-font*. ;;; ;;; title - If non-NIL, the value of this field will appear in a line ;;; above the menu. ;;; ;;; ;;; ;;; ;;; Comments: ;;; ;;; - The system is defined as part of the Window-Basics package. ;;; However, most menu functions are independent of windows. ;;; ;;; ;;; ;;; ;;; Author(s): ;;; ;;; R.W. Oldford ([email protected]) July 1989. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*default-menu-font* *menu-held-wait* default-sub-item-fn default-when-selected-fn default-when-held-fn default-when-unheld-fn))) ;;;------------------------------------------------------------------------------ ;;; ;;; Default menu variables and functions. ;;; ;;;------------------------------------------------------------------------------ (defvar *default-menu-font* *normal-graphics-font*) (defvar *menu-held-wait* 1200 "The number of milliseconds to wait on a menu before prompting.") (defun default-sub-item-fn (menu item) (declare (ignore menu)) (if (and (typep item 'sequence) (eq (fourth item) :sub-items)) (fifth item))) (defun default-when-selected-fn (item menu mouse-button) "Special selection function that calls the function in the menu ~ on the value of *current-canvas*" (declare (ignore menu mouse-button) (special *current-canvas*)) (if (and (typep item 'sequence) (>= (length item) 2)) (let ((action (second item))) (cond ((functionp action) (funcall action *current-canvas*)) (T (eval action)))) item)) (defun default-when-held-fn (item menu mouse-button) (declare (ignore menu mouse-button)) (let ((message "This item will be selected when the button is released.")) (if (and (typep item 'sequence) (third item)) (setq message (third item))) (print message))) (defun default-when-unheld-fn (item menu mouse-button) (declare (ignore item menu mouse-button)) ()) ;;;----------------------------------------------------------------------------- ;;; ;;; Creating a menu ;;; ;;;----------------------------------------------------------------------------- ;;; ;;; Menu creation is left unspecified at this level. ;;; Many CLs have their own menu implementations and these should be accessed ;;; to avoid a layer of indirection. ;;; However, the implemented function must have the following arguments (with ;;; defaults) and must return a data structure/ object/ whatever that represents ;;; a potentially hierarchical menu. ;;; ;;; (defun make-menu (&key items ;;; (font *default-menu-font*) ;;; (sub-item-fn default-sub-item-fn) ;;; (when-selected-fn default-when-selected-fn) ;;; (when-held-fn default-when-held-fn) ;;; (when-unheld-fn default-when-unheld-fn)) ;;; then-the-body) ;;; ;;; ;;; ------------------------------------------------------------------------------------ ;;; ;;; Other menu functions ;;; ;;; ------------------------------------------------------------------------------------ ;;; ;;; ;;; (defun menu-p (menu) (type menu ........ ;;; ;;; (defun destroy-menu (menu) ... Destroys menu so that its space can be reclaimed. ;;; ;;; (defun set-menu-fns (menu &key (selected nil) (held nil) (unheld nil) (sub-item nil)) ;;; ... Changes the functions when-selected-fn, when-held-fn, ;;; et cetera according to the values of corresponding ;;; keyword arguments. ;;; ;;; (defun put-menu-prop (menu property value) ... Stores value on property of menu. ;;; These are stored on the ;;; "user-properties" slot of the menu. ;;; ;;; (defun get-menu-prop (menu property) ... Returns the value associated with the ;;; property on menu" ;;; ;;; (defun menu (menu &key position) ... Pops menu up at position in screen-coordinates. ;;; (If given, otherwise at current mouse-position.) ;;; ;;; (defun disable-menu-item (menu item-string) Disables the menu item identified by ;;; item-string ;;; ;;; (defun enable-menu-item (menu item-string) Enables the menu item identified by ;;; item-string ;;; ;;; (defun check-menu-item (menu item-string &optional (check-char nil) ;;; Places a check-char beside item identified by ;;; item-string ;;; ;;; (defun set-menu-item-string (menu item-string new-string))
10,109
Common Lisp
.l
216
43.810185
123
0.534725
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
05e7b8378658006d3532903593ca9b0a7ceb2e64ac26eafe73cb7690fdff0d3b
33,521
[ -1 ]
33,522
menu-canvas-sblx.lsp
rwoldford_Quail/source/window-basics/menus/menu-canvas-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; menu-canvas-sblx.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;--------------------------------------------------------------------- ;;; The story: ;;; Want various hierarchical menus to be associated with a canvas. ;;; These will pop-up in response to certain mouse-events while the ;;; mouse is over either the title-bar of the canvas, or over the ;;; body of the canvas. ;;; This file (and others specialized for each CL) contains those ;;; functions which attach menus to, and select menus from, a canvas. ;;; ;;; ------------------------------------------------------------------- ;;; Author(s): ;;; [email protected] ;;; The model is described in menu-canvas. Menus are described in ;;; menu & menu-mcl. ;;; ;;; The model for dealing with menus under mcclim is quite different from the mac/acl model ;;; Neither of these forms is liekly to be useful ;;; If we decide to put menus onto a single quail-menubar using Unmade as a place holder ;;; some version of set-up-title-menus might be needed ;;; GWBennett 07 SEP 2020 (in-package :wb) #| (defun release-menu-space (menu) (destroy-menu menu)) ;;; In MCL the menu-type cannot be :pop-up ;;; ... the default (defmethod set-up-title-menus ((canvas menu-canvas) &key (title-left "Information") (title-middle "Edit-display") (title-right "Canvas") (title-ctrl-left "") (title-ctrl-middle "") (title-ctrl-right "") (menu-type :title) (when-selected-fn #'default-when-selected-fn)) (declare (ignore menu-type)) (install-title-menus canvas :menu-type :pull-down :title-left title-left :title-middle title-middle :title-right title-right :title-ctrl-left title-ctrl-left :title-ctrl-middle title-ctrl-middle :title-ctrl-right title-ctrl-right :when-selected-fn when-selected-fn) (put-title-menus-on-menubar canvas)) |#
3,043
Common Lisp
.l
66
36.833333
97
0.5032
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6b662c7902b7d01fc616f00f5b832f09a49da753d493ad1414b23f2f54e4c8fd
33,522
[ -1 ]
33,524
menu-canvas.lsp
rwoldford_Quail/source/window-basics/menus/menu-canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; menu-canvas.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1989-1991 ;;; ;;; ;;; ;;;------------------------------------------------------------------- ;;; ;;; The story: ;;; ;;; Want various hierarchical menus to be associated with a canvas. ;;; These will pop-up in response to certain mouse-events while the ;;; mouse is over either the title-bar of the canvas, or over the ;;; body of the canvas. ;;; ;;; This file (and others specialized for each CL) contains those ;;; functions which attach menus to a canvas. ;;; ;;; ------------------------------------------------------------------- ;;; ;;; Author(s): ;;; [email protected] ;;; ;;; The model: ;;; ;;; To achieve this, two slots are assigned to each canvas record to ;;; cache these menus. ;;; ;;; The slots are ;;; ;;; title-menus ;;; and simply ;;; ;;; menus ;;; ;;; for those which are typically associated with the body. ;;; ;;; The value of each slot is a collection of keyword-menu pairs. ;;; Interaction with these collections will be through the functions: ;;; ;;; (canvas-put-title-menu canvas &key key menu) ;;; - stores the title-menu "menu" using the look-up key "key" ;;; ;;; (canvas-get-title-menu canvas &key key) ;;; - if no key is given all title-menus are returned in a list, otherwise ;;; only that title-menu associated with key is returned. ;;; ;;; (canvas-put-menu canvas &key key menu) ;;; - stores the menu "menu" using the look-up key "key" ;;; ;;; (canvas-get-menu canvas &key key) ;;; - if no key is given all menus are returned in a list, otherwise ;;; only that menu associated with key is returned. ;;; ;;; ------------------------------------------------------------------------ ;;; ;;; Conventions: ;;; ;;; For the title-menus,the Window-Basics package makes use of keywords ;;; corresponding to mouse-key + modifier selections supported by wb-mouse. ;;; These are: ;;; ;;; :left ;;; :ctrl-left ;;; :middle ;;; :ctrl-middle ;;; ::right ;;; :ctrl-right ;;; ;;; The shift modifier has been ignored - shift is meant to return different ;;; aspects of the lisp object selected. If this recommended style is ;;; followed, no menu should be constructed. ;;; ;;; ;;; It's important to note that the user is free to use their own collection ;;; of keys in any application. This allows the menu interaction to be ;;; easily extended. ;;; ;;; ... rwo ;;; ;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(default-canvas-menu-items add-canvas-title-item remove-canvas-title-item canvas-put-title-menu canvas-get-title-menu canvas-put-menu canvas-get-menu title-menus-of menus-of menu-canvas left-title-items-of ctrl-left-title-items-of middle-title-items-of ctrl-middle-title-items-of right-title-items-of ctrl-right-title-items-of))) ;;;===================================================================== ;;; Want various menus to be associated with a window. ;;; Minimally, these will pop up whenever a mouse button is depressed ;;; while the mouse is over the title-bar of the canvas. ;;; For the Macintosh, these menus will appear in the menu-bar ;;; when that canvas is the active window on the desktop. ;;; ;;; Accomplished by defining an appropriate mixin for canvas: ;;; ;;; menu-canvas ;;; ;;; ...rwo ;;;===================================================================== (defun default-canvas-menu-items () "A menu item list that can be used as the default canvas menu." (list (list "Redisplay" #'(lambda (c) (redisplay c)) "Redisplay this canvas.") (list "Display parameters" NIL "Change some display parameters of this canvas." :sub-items (list (list "Title" #'(lambda (c) (canvas-set-title c (prompt-user :prompt-string "Enter the title: " :read-type :string :result-type 'string))) "Change the title of the canvas.") (list "Background color" #'(lambda (c) (canvas-set-background-color c (prompt-user-for-color))) "Change the background color of the canvas.") (list "Pen color" #'(lambda (c) (set-pen-color c (prompt-user-for-color))) "Change the pen color.") (list "Pen width" #'(lambda (c) (set-pen-width c (prompt-user :prompt-string "Enter the new width (in pixels): " :result-type 'integer :read-type :eval))) "Change the pen width."))) (list "Export canvas" #'canvas-export "Exports the canvas to an appropriate filetype.") (list "Print canvas" #'canvas-hardcopy "Prints the canvas.") (list "Canvas fonts" NIL "Change the font of this canvas." :sub-items (list (list "Font" #'(lambda (c) (let ((f-copy (copy-canvas-font (canvas-font c)))) (set-canvas-font-name f-copy (first (prompt-for-items (canvas-font-names)))) (setf (canvas-font c) f-copy))) "Change the font name used in the canvas.") (list "Font style" #'(lambda (c) (let ((f-copy (copy-canvas-font (canvas-font c)))) (set-canvas-font-style f-copy (prompt-for-items (canvas-font-styles) :selection-type :disjoint)) (setf (canvas-font c) f-copy))) "Change the font style used in the canvas.") (list "Font size" #'(lambda (c) (let ((f-copy (copy-canvas-font (canvas-font c)))) (set-canvas-font-size f-copy (prompt-user :prompt-string "Enter the new font size (1 to 127): " :result-type 'integer :read-type :eval)) (setf (canvas-font c) f-copy))) "Change the font size used in the canvas."))) (list "Draw on canvas" #'(lambda (c) (let (c?) (loop (when (mouse-down-p) (setf c? (which-canvas (screen-mouse-position))) (if (not (eq c c?)) (return)) (let* ((mouse-pos (mouse-position c)) (old-x (position-x mouse-pos)) (old-y (position-y mouse-pos)) new-x new-y) (do ((i 1 (+ i 1))) ((not (mouse-down-p))) (setf mouse-pos (mouse-position c)) (setf new-x (position-x mouse-pos)) (setf new-y (position-y mouse-pos)) (canvas-draw-line c old-x old-y new-x new-y) (setf old-x new-x) (setf old-y new-y)) (return)))))) "Draw on the current canvas.") (list "Clear canvas" #'canvas-clear "Clear the canvas.") (list "Save canvas" #'save-value "Save the current canvas on a symbol.") (list "Inspect canvas" #'inspect "Inspect the current canvas.")) ) (defclass menu-canvas (host-menu-canvas) ((menus :initarg :menus :initform nil :accessor menus-of :documentation "A collection of keyword-menu pairs. These menus will ~ appear when selection is made in the body of the ~ canvas.") (title-menus :initarg :title-menus :initform nil :accessor title-menus-of :documentation "A collection of keyword-menu pairs. These menus will ~ appear when selection is made in the title of the ~ canvas, or in the menubar when the canvas comes to the forefront ~ of the display. Which depends upon the implementation.") (left-title-items :initform NIL :initarg :left-title-items :accessor left-title-items-of) (middle-title-items :initform NIL :initarg :middle-title-items :accessor middle-title-items-of) (right-title-items :initarg :right-title-items :initform (default-canvas-menu-items) :accessor right-title-items-of) (ctrl-left-title-items :initarg :ctrl-left-title-items :initform NIL :accessor ctrl-left-title-items-of) (ctrl-middle-title-items :initarg :ctrl-middle-title-items :initform NIL :accessor ctrl-middle-title-items-of) (ctrl-right-title-items :initarg :ctrl-right-title-items :initform NIL :accessor ctrl-right-title-items-of)) (:documentation "A mixin class for canvas to allow for caching menus and defining~ some menu items on the title bar.")) ;;;-------------------------------------------------------------------------- ;;; ;;; Now the functions. ;;; ;;;-------------------------------------------------------------------------- (defun add-canvas-title-item (canvas item &optional (where :left)) "Adds the item to the title items of canvas corresponding to one of ~ :left :middle :right ~ :ctrl-left :ctrl-middle or :ctrl-right as the optional argument ~ where. The default of where is :left." (case where (:left (setf (left-title-items-of canvas) (append (left-title-items-of canvas) (list item)))) (:middle (setf (middle-title-items-of canvas) (append (middle-title-items-of canvas) (list item)))) (:right (setf (right-title-items-of canvas) (append (right-title-items-of canvas) (list item)))) (:ctrl-left (setf (ctrl-left-title-items-of canvas) (append (ctrl-left-title-items-of canvas) (list item)))) (:ctrl-middle (setf (ctrl-middle-title-items-of canvas) (append (ctrl-middle-title-items-of canvas) (list item)))) (:ctrl-right (setf (ctrl-right-title-items-of canvas) (append (ctrl-right-title-items-of canvas) (list item)))) )) (defun remove-canvas-title-item (canvas item &optional (where :left)) "Removes the item (if found) from ~ the title items of canvas corresponding to one of ~ :left :middle :right ~ :ctrl-left :ctrl-middle or :ctrl-right as the optional argument ~ where (default :left)." (case where (:left (setf (left-title-items-of canvas) (remove item (left-title-items-of canvas) :test #'equal))) (:middle (setf (middle-title-items-of canvas) (remove item (middle-title-items-of canvas) :test #'equal))) (:right (setf (right-title-items-of canvas) (remove item (right-title-items-of canvas) :test #'equal))) (:ctrl-left (setf (ctrl-left-title-items-of canvas) (remove item (ctrl-left-title-items-of canvas) :test #'equal))) (:ctrl-middle (setf (ctrl-middle-title-items-of canvas) (remove item (ctrl-middle-title-items-of canvas) :test #'equal))) (:ctrl-right (setf (ctrl-right-title-items-of canvas) (remove item (ctrl-right-title-items-of canvas) :test #'equal))) ) ) (defun canvas-put-title-menu (canvas &key key menu) (with-accessors ((tm title-menus-of)) canvas "Adds the :menu to the title-menus using :key as a lookup key." (setq tm (acons key menu tm))) ) (defun canvas-get-title-menu (canvas &key key) (with-accessors ((tm title-menus-of)) canvas "Gets the :menu from the title-menus using :key as a lookup key. ~ If no :key is given, the assoc list of title-menus is returned." (if key (cdr (assoc key tm)) tm))) (defun canvas-put-menu (canvas &key key menu) (with-accessors ((m menus-of)) canvas "Adds the :menu to the menus using :key as a lookup key." (setq m (acons key menu m)))) (defun canvas-get-menu (canvas &key key) (with-accessors ((m menus-of)) canvas "Gets the :menu from the menus using :key as a lookup key. If no :key is given, the assoc list of menus is returned." (if key (cdr (assoc key m)) m))) (defun install-title-menus (canvas &key (title-left "Information") (title-middle "Edit-display") (title-right "Canvas") (title-ctrl-left "") (title-ctrl-middle "") (title-ctrl-right "") (menu-type :pop-up) (when-selected-fn #'default-when-selected-fn) ) "Installs the title items found on the browser as title-menus of the canvas." (let (items) ;; release the menu record (some systems have such non-lisp things) (loop for m in (title-menus-of canvas) do (release-menu-space (cdr m))) (setf (title-menus-of canvas) NIL) (loop for f in (list (list :left #'left-title-items-of title-left) (list :middle #'middle-title-items-of title-middle) (list :right #'right-title-items-of title-right) (list :ctrl-left #'ctrl-left-title-items-of title-ctrl-left) (list :ctrl-middle #'ctrl-middle-title-items-of title-ctrl-middle) (list :ctrl-right #'ctrl-right-title-items-of title-ctrl-right)) when (setf items (funcall (second f) canvas)) collect (canvas-put-title-menu canvas :key (first f) :menu (make-menu :items items :title (third f) :menu-type menu-type :when-selected-fn when-selected-fn))) ) ) (defun release-menu-space (menu) (declare (ignore menu))) (defgeneric set-up-title-menus (canvas &key title-left title-middle title-right title-ctrl-left title-ctrl-middle title-ctrl-right menu-type when-selected-fn) (:documentation "Installs the menus and makes them accessible ~ to user interaction ~ (:required (:arg canvas The canvas on which the title menus ~ are installed.))~ (:key ~ (:arg title-left \"Information\" Title of the left-title menu.)~ )")) ;; out 10SEP2020 ;; in 03OCT2020 ;; out 04OCT2023 ;#| (defmethod initialize-instance :after ((canvas menu-canvas) &key (title-left "Information") (title-middle "Edit-display") (title-right "Canvas") (title-ctrl-left "") (title-ctrl-middle "") (title-ctrl-right "") (menu-type :pop-up) (when-selected-fn #'default-when-selected-fn)) "When a new menu-canvas is created, we must set up the title menus ~ for its class ~ if it doesn't already exist." ;; the following calls install-title-menus with appropriate menu-type (set-up-title-menus canvas :title-left title-left :title-middle title-middle :title-right title-right :title-ctrl-left title-ctrl-left :title-ctrl-middle title-ctrl-middle :title-ctrl-right title-ctrl-right :menu-type menu-type :when-selected-fn when-selected-fn) ) ;|#
18,239
Common Lisp
.l
428
30.011682
93
0.493863
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
cfd9fd6013e7b2c02839e0455be9a8f06301fe3f9d9d7eac39514deb547ea01c
33,524
[ -1 ]
33,526
menu-sblx.lsp
rwoldford_Quail/source/window-basics/menus/menu-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; menu-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;----------------------------------------------------------------------------- ;;; Note that a fair bit of this is *NOT* MCL dependent ... rwo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;++ gwb ;++ mcclim's approach to menus is so different from acl/mcl that I am temporarily ;++ ignoring the contents of this file ;++ 09SEP2020 (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-menu wb-pop-up-menu destroy-menu set-menu-fns menu-p put-menu-prop get-menu-prop installed-p menu select-in-menu get-menu-item disable-menu-item enable-menu-item check-menu-item set-menu-item-string menu-installed-p))) ;;(eval-when (compile eval load) ;; (import '(ccl::pop-up-menu-default-item ccl::menu-object ;; ccl::pop-up-menu-auto-update-default) :wb)) ;;; Until I can resolve all the problems with embedding the ;;; source code, or until the methods are included in the ;;; ---------------------------------------------------------------------------- ;;; Hierarchical pop-up menus ;;; ---------------------------------------------------------------------------- ;;; First set up a slot so that each menu-item knows which menu it belongs to. ;;; (defclass wb-menu-mixin () ((user-properties :initarg :user-properties :initform nil :accessor user-properties-of) (sub-item-fn :initarg :sub-item-fn :initform #'default-sub-item-fn :accessor sub-item-fn-of) (when-held-fn :initarg :when-held-fn :initform #'default-when-held-fn :accessor when-held-fn-of) (when-unheld-fn :initarg :when-unheld-fn :initform #'default-when-unheld-fn :accessor when-unheld-fn-of) (when-selected-fn :initarg :when-selected-fn :initform #'default-when-selected-fn :accessor when-selected-fn-of) (items :initarg :items :initform NIL :accessor items-of) (super-menu :accessor super-menu-of :initarg :super-menu :initform NIL :documentation "The menu which contains this menu (or menu-item), if any.") ;(help-string :accessor cg::help-string ; :initarg :help-string ; :initform "" ; :documentation ; "The help-string for this menu") )) (defclass wb-menu (wb-menu-mixin) ()) ;cg::pull-down-menu) ()) #| ;;(defclass wb-menu-item (wb-menu-mixin ccl::menu-item) ()) ;; menu-item is a STRUCTURE in ACLPC (defstruct (wb-menu-item (:include cg::menu-item)) (user-properties NIL) (sub-item-fn #'default-sub-item-fn) (when-held-fn #'default-when-held-fn) (when-unheld-fn #'default-when-unheld-fn) (when-selected-fn #'default-when-selected-fn) (items NIL) (super-menu NIL) ) |# (defclass wb-menu-item (wb-menu-mixin) ;(cg::menu-item) ((user-properties :initform NIL :accessor user-properties-of) (sub-item-fn :initform #'default-sub-item-fn :accessor sub-item-fn-of ) (when-held-fn :initform #'default-when-held-fn :accessor when-held-fn-of) (when-unheld-fn :initform #'default-when-unheld-fn :accessor when-unheld-fn-of) (when-selected-fn :initform #'default-when-selected-fn :accessor when-selected-fn-of) (items :initform NIL :accessor items-of) (super-menu :initform NIL :accessor super-menu-of) ) ) (defmethod when-held-fn-of ((thing wb-menu-mixin)) ;cg::menu-item)) (cdr (assoc 'when-held-fn (second (member 'wb-menu-fns (symbol-plist thing) ;(cg::plist thing) ))))) (defmethod when-held-fn-of ((thing T)) NIL) (defmethod (setf when-selected-fn-of) (new-value (thing T)) NIL) (defmethod (setf when-selected-fn-of) (new-value (thing wb-menu-mixin)) ;cg::menu-item)) (setf (cdr (assoc 'when-selected-fn (second (member 'wb-menu-fns (symbol-plist thing) ;(cg::plist thing) )))) new-value)) (defmethod (setf sub-item-fn-of) (new-value (thing T)) NIL) (defmethod (setf sub-item-fn-of) (new-value (thing wb-menu-mixin)) ;cg::menu-item )) (setf (cdr (assoc 'sub-item-fn (second (member 'wb-menu-fns (symbol-plist thing) ;(cg::plist thing) )))) new-value)) (defmethod (setf when-unheld-fn-of) (new-value (thing T)) NIL) (defmethod (setf when-unheld-fn-of) (new-value (thing wb-menu-mixin)) ;cg::menu-item)) (setf (cdr (assoc 'when-unheld-fn (second (member 'wb-menu-fns (symbol-plist thing) ;(cg::plist thing) )))) new-value)) (defmethod (setf when-unheld-fn-of) (new-value (thing T)) NIL) ;;;----------------------------------------------------------------------------- ;;; pop-up menu ;;;----------------------------------------------------------------------------- (defclass wb-pop-up-menu (wb-menu-mixin) ()) ;cg::pop-up-menu) ()) (defun set-menu-fns (menu &key (selected nil selected?) (held nil held?) (unheld nil unheld?) (sub-item nil sub-item?) (user-props NIL user-props?)) (declare (ignorable menu selected selected? held held? unheld unheld? sub-item sub-item? user-props user-props?)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (cond ((typep menu 'wb-menu-item) (if user-props? (setf (user-properties-of menu) user-props)) (if selected? (setf (when-selected-fn-of menu) selected)) (if held? (setf (when-held-fn-of menu) held)) (if unheld? (setf (when-unheld-fn-of menu) unheld)) (if sub-item? (setf (sub-item-fn-of menu) sub-item)) ) ((cg::menu-item-p menu) (let ((wb-menu-fns (member 'wb-menu-fns (cg::plist menu)))) (cond (wb-menu-fns (if user-props? (setf (cdr (assoc 'user-properties wb-menu-fns)) user-props)) (if selected? (setf (cdr (assoc 'when-selected-fn wb-menu-fns)) selected)) (if held? (setf (cdr (assoc 'when-held-fn wb-menu-fns)) held)) (if unheld? (setf (cdr (assoc 'when-unheld-fn wb-menu-fns)) unheld)) (if sub-item? (setf (cdr (assoc 'sub-item-fn wb-menu-fns)) sub-item)) ) (T (setf (cg::plist menu) (append (list 'wb-menu-fns (list (cons 'user-properties user-props) (cons 'when-selected-fn selected) (cons 'when-held-fn held) (cons 'when-unheld-fn unheld) (cons 'sub-item-fn sub-item))) (cg::plist menu))))))) ((cg::menup menu) (when (typep menu 'wb-menu-mixin) (if selected? (setf (when-selected-fn-of menu) selected)) (if held? (setf (when-held-fn-of menu) held)) (if unheld? (setf (when-unheld-fn-of menu) unheld)) (if sub-item? (setf (sub-item-fn-of menu) sub-item))) ) (T NIL)) |# ) ;;;---------------------------------------------------------------------------- ;;; Making the pop-menu ;;;--------------------------------------------------------------------------- ;;; It would be nice if a single kind of menu record was used. Sigh ... ;;; Don't yet know how to grab the mouse in a menu to tell which item it's ;;; over and for how long. Hence when-held-fn & when-unheld-fn are never ;;; called. ;;; ... rwo ;; An ACLPC version of make-menu follows ;; NOTES on make-menu specific to ACLPC :- ;; (1) menus are OBJECTS which inherit from STANDARD-CLASS ;; (2) menu-items are STRUCTURES which inherit from STRUCTURE-CLASS ;; (3) to make sub-menus, ie menu-items which are in fact menus, ;; proceed as follows : ;; (cg::make-menu-items :title what-should-appear-in-the-supermenu ;; :value menu-to-become-the-submenu) ;; (add-to-menu some-higher-level-menu this-thing-just-made) ;; (4) to get a sub-menu's :title correct try setting it to ;; (cg::stream-title some-higher-level-menu) ;; (5) because menu-items are STRUCTURES I had to change the name of the ;; MCL function make-wb-menu-item to build-wb-menu-item since ;; make-STRUCTURE is a primitive.. ;; (6) .. and I had to replace make-instance by just that primitive to ;; create mi inside build-wb-menu-item. ;; gwb - on February 08, 1996 ;;;;;;;;; ;;; Revised version of make-menu allowing for when-x-fns (defun make-menu (&key items sub-item-fn (when-selected-fn #'default-when-selected-fn) when-held-fn when-unheld-fn (title NIL) (font *default-menu-font*) (change-offset-fn nil) (menu-type :pop-up) &aux menu) (declare (ignorable items sub-item-fn when-selected-fn when-held-fn when-unheld-fn title font change-offset-fn menu-type menu)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (declare (ignore change-offset-fn font) (special *default-menu-font*)) (let ((*menu-class* (if (eq menu-type :pop-up) 'wb-pop-up-menu 'wb-menu))) (labels ((force-string (x) (if (stringp x) x (format nil "~a" x))) (selection-fn-wrap (menu menu-item window) ;; Get the when-selected-fn -- first from the menu-item and if not ;; found there, then from the menu (let ((selected-fn (cdr (assoc 'when-selected-fn (second (member 'wb-menu-fns (cg::plist menu-item))))))) (unless (functionp selected-fn) (setf selected-fn (or (when-selected-fn-of menu) #'(lambda (a b c) (declare (ignore a b c)) (cg::funcall-menu-item menu menu-item window))))) ;; Now call the selected function on the appropriate arguments (funcall selected-fn (cg::value menu-item) menu :left ;; should be the current (mouse-button) ) ) ) (make-wb-sub-menu (outer-menu sub-menu-items) (labels ((build-wb-menu-item (menu sub-menu-item) (let ((mi (make-instance 'wb-menu-item :title (force-string (first sub-menu-item)) :value sub-menu-item :help-string (third sub-menu-item) :items sub-menu-item :super-menu menu))) (set-menu-fns mi :selected when-selected-fn :held when-held-fn :unheld when-unheld-fn :sub-item sub-item-fn) mi))) (if (and (> (length sub-menu-items) 4) (eq (fourth sub-menu-items) :sub-items)) (let ((sub-menu (cg::open-menu '() *menu-class* (cg::screen cg::*system*) :title (force-string (first sub-menu-items)) :items sub-menu-items :super-menu outer-menu :help-string (third sub-menu-items) :selection-function #'selection-fn-wrap) )) (set-menu-fns sub-menu :selected when-selected-fn :held when-held-fn :unheld when-unheld-fn :sub-item sub-item-fn) (loop for sub-item in (fifth sub-menu-items) when sub-item do (cg::add-to-menu sub-menu (make-wb-sub-menu sub-menu sub-item))) ;; Here is where I must convert to a cg::menu-item (make-instance 'cg::menu-item :title (cg::title sub-menu) :help-string (cg::help-string sub-menu) :value sub-menu)) (build-wb-menu-item outer-menu sub-menu-items))))) (setq menu (cg::open-menu '() *menu-class* (cg::screen cg::*system*) :title (if title (force-string title) "Untitled") :help-string (third items) :items items :selection-function #'selection-fn-wrap)) (set-menu-fns menu :selected when-selected-fn :held when-held-fn :unheld when-unheld-fn :sub-item sub-item-fn) (loop for item in items when item do (cg::add-to-menu menu (make-wb-sub-menu menu item))) menu)) |# ) ;;; ---------------------------------------------------------------------------- ;;; Popping the menu ;;; ---------------------------------------------------------------------------- ;;; This is the one that does the job! ;;; In ACLPC terms the menu of the following function will be ;;; assumed to have its handler already defined inside ;;; whatever made it - presumably make-menu (defun menu (menu &key (position NIL position?)) "Pops menu up at position in screen-coordinates. (If given, otherwise at mouse-position). Title will appear on PC only if it's made into the first item otherwise :title slot is ignored completely for pop-up-menus." (declare (ignorable menu position position?)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (when (menu-installed-p menu) ; check if it's already visible (cond (position? (cg::pop-up-menu menu position)) (T (cg::pop-up-menu menu))) ) |# ) ;; Here is an elementary menu-installed-p (defun menu-installed-p (menu) (menu-p menu) ) ;;; The following function needs to operate within an event-handler ;;; (e.g. to be called after a mouse has been depressed inside a window) ;;; In ACLPC terms the selection function is supplied as an option ;;; to the creation of the menu and the mouse actions are integral ;;; although the selection processes are quite different for the ;;; two types pull-down and pop-up ;;;----------------------------------------------------------------------------- ;;; Miscellaneous menu functions ;;;----------------------------------------------------------------------------- ;; Added 19 June 1998. See kill-menu.lsp (defun submenus? (mnu) "Does mnu have submenus ?~ Be careful about types!" (declare (ignorable mnu)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (let* ((mi (cg::menu-items mnu)) (miv (mapcar #'cg::value mi)) (mit (mapcar #'type-of miv))) (values miv (or (position 'wb-menu mit) (position 'wb-pop-up-menu mit))) ) |# ) ;;; Added 19 June 1998. See kill-menu.lsp ;;; was killmenu now is destroy-menu (defun destroy-menu (mnu) "Finds the first outer submenu and kills it.~ Then checks backwards etc. until mnu is closed." (declare (ignorable mnu)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") ;; Following is necessary since submenus? doesn't work on closed streams #| (unless (not (cg::open-stream-p mnu)) ;;(typep mnu 'cg::closed-stream) (multiple-value-setq (a b) (submenus? mnu)) (cond (b (destroy-menu (elt a b)) mnu) (T ;; Grab super-menu NOW in case we need to back-up (let ((sm (super-menu-of mnu))) (cg::close mnu) (when sm (destroy-menu sm))) mnu))) |# ) (defun menu-p (menu) (or (typep menu 'wb-menu) (typep menu 'wb-pop-up-menu))) (defun put-menu-prop (menu property value) "Stores value on property of menu" (setf (user-properties-of menu) (acons property value (user-properties-of menu)))) (defun get-menu-prop (menu property) "Returns the value associated with the property on menu" (cdr (assoc property (user-properties-of menu)))) ;;; ---------------------------------------------------------------------------- ;;; Modifying the menu appearance ;;; ---------------------------------------------------------------------------- ;;; These seem to have to do with disabling and ;;; enabling items of a menu ;;; and with checking which are built-in to ACLPC ;;; fairly directly ;;; Jan 24, 1996 GWB ;;; A list version of finding menu-items #| (defun list-get-menu-item (mi-list item-string) (let ((result NIL)) (loop for m-i in mi-list until result do (if (cg::menup (cg::value m-i)) (setf result (list-get-menu-item (cg::menu-items (cg::value m-i)) item-string)) (if (equal (string (cg::title m-i)) item-string) (setf result m-i)) ) ) (print result) result)) |# (defun list-get-menu-item (mi-list item-string) (declare (ignorable mi-list item-string)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (labels ((lgmi-aux (mi-list) (cond ((and (cg::menu-item-p mi-list) (equal (string (cg::title mi-list)) item-string) ) mi-list) ((null mi-list) NIL) ((listp mi-list) (or (lgmi-aux (first mi-list)) (lgmi-aux (rest mi-list)))) ((cg::menup (cg::value mi-list)) (if (string-equal (string (cg::title mi-list)) item-string) mi-list) (lgmi-aux (cg::menu-items (cg::value mi-list))) ) ))) (lgmi-aux mi-list)) |# ) ;; Now the function we need (defun get-menu-item (menu item-string) (declare (ignorable menu item-string)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (when menu (cond ((cg::menu-item-p menu) (list-get-menu-item (list menu) item-string)) (t (list-get-menu-item (cg::menu-items menu) item-string))) ) |# ) (defun disable-menu-item (menu item-string) "Disables the top-level menu item identified by item-string." (declare (ignorable menu item-string)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-menu-item-available-p item NIL) 18oct05 (setf (cg::available item) NIL) ;18oct05 )) |# ) (defun enable-menu-item (menu item-string) "Enables the menu item identified by item-string." (declare (ignorable menu item-string)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-menu-item-available-p item T) 18oct05 (setf (cg::available item) T) ;18oct05 )) |# ) (defun check-menu-item (menu item-string &optional (check-char nil)) "Places a check-char beside item identified by item-string ~ if check-char is nil no check mark appears ~ if check-char is t a default check mark is used." (declare (ignorable menu item-string check-char)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-menu-item-selected-p item check-char) 18oct05 (setf (cg::selected item) check-char) ;18oct05 )) |# ) (defun set-menu-item-string (menu item-string new-string) "Changes the TITLE for the menu item currently ~ identified by item-string to new-string." (declare (ignorable menu item-string new-string)) ;10MAY2024 (format t "~%Not implemented in mcclim yet.") #| (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-stream-title item new-string) 18oct05 (setf (cg::title item) new-string) ;18oct05 )) |# )
22,953
Common Lisp
.l
536
31.25
124
0.496865
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
60e32393c65d95b35d9593e436a425d8f4536fa83df30b7c51908db15d7547d1
33,526
[ -1 ]
33,527
menu-pc.lsp
rwoldford_Quail/source/window-basics/menus/menu-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; menu-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;----------------------------------------------------------------------------- ;;; Note that a fair bit of this is *NOT* MCL dependent ... rwo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-- gwb (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-menu wb-pop-up-menu destroy-menu set-menu-fns menu-p put-menu-prop get-menu-prop installed-p menu select-in-menu get-menu-item disable-menu-item enable-menu-item check-menu-item set-menu-item-string menu-installed-p))) ;;(eval-when (compile eval load) ;; (import '(ccl::pop-up-menu-default-item ccl::menu-object ;; ccl::pop-up-menu-auto-update-default) :wb)) ;;; Until I can resolve all the problems with embedding the ;;; source code, or until the methods are included in the ;;; ---------------------------------------------------------------------------- ;;; Hierarchical pop-up menus ;;; ---------------------------------------------------------------------------- ;;; First set up a slot so that each menu-item knows which menu it belongs to. ;;; (defclass wb-menu-mixin () ((user-properties :initarg :user-properties :initform nil :accessor user-properties-of) (sub-item-fn :initarg :sub-item-fn :initform #'default-sub-item-fn :accessor sub-item-fn-of) (when-held-fn :initarg :when-held-fn :initform #'default-when-held-fn :accessor when-held-fn-of) (when-unheld-fn :initarg :when-unheld-fn :initform #'default-when-unheld-fn :accessor when-unheld-fn-of) (when-selected-fn :initarg :when-selected-fn :initform #'default-when-selected-fn :accessor when-selected-fn-of) (items :initarg :items :initform NIL :accessor items-of) (super-menu :accessor super-menu-of :initarg :super-menu :initform NIL :documentation "The menu which contains this menu (or menu-item), if any.") (help-string :accessor cg::help-string :initarg :help-string :initform "" :documentation "The help-string for this menu"))) (defclass wb-menu (wb-menu-mixin cg::pull-down-menu) ()) #| ;;(defclass wb-menu-item (wb-menu-mixin ccl::menu-item) ()) ;; menu-item is a STRUCTURE in ACLPC (defstruct (wb-menu-item (:include cg::menu-item)) (user-properties NIL) (sub-item-fn #'default-sub-item-fn) (when-held-fn #'default-when-held-fn) (when-unheld-fn #'default-when-unheld-fn) (when-selected-fn #'default-when-selected-fn) (items NIL) (super-menu NIL) ) |# (defclass wb-menu-item (cg::menu-item) ((user-properties :initform NIL :accessor user-properties-of) (sub-item-fn :initform #'default-sub-item-fn :accessor sub-item-fn-of ) (when-held-fn :initform #'default-when-held-fn :accessor when-held-fn-of) (when-unheld-fn :initform #'default-when-unheld-fn :accessor when-unheld-fn-of) (when-selected-fn :initform #'default-when-selected-fn :accessor when-selected-fn-of) (items :initform NIL :accessor items-of) (super-menu :initform NIL :accessor super-menu-of) ) ) (defmethod when-held-fn-of ((thing cg::menu-item)) (cdr (assoc 'when-held-fn (second (member 'wb-menu-fns (cg::plist thing)))))) (defmethod when-held-fn-of ((thing T)) NIL) (defmethod (setf when-selected-fn-of) (new-value (thing T)) (declare (ignorable new-value)) ; 27JUL2023 NIL) (defmethod (setf when-selected-fn-of) (new-value (thing cg::menu-item)) (setf (cdr (assoc 'when-selected-fn (second (member 'wb-menu-fns (cg::plist thing))))) new-value)) (defmethod (setf sub-item-fn-of) (new-value (thing T)) (declare (ignorable new-value)) ; 27JUL2023 NIL) (defmethod (setf sub-item-fn-of) (new-value (thing cg::menu-item )) (setf (cdr (assoc 'sub-item-fn (second (member 'wb-menu-fns (cg::plist thing))))) new-value)) (defmethod (setf when-unheld-fn-of) (new-value (thing T)) (declare (ignorable new-value)) ; 27JUL2023 NIL) (defmethod (setf when-unheld-fn-of) (new-value (thing cg::menu-item)) (setf (cdr (assoc 'when-unheld-fn (second (member 'wb-menu-fns (cg::plist thing))))) new-value)) ;;;----------------------------------------------------------------------------- ;;; pop-up menu ;;;----------------------------------------------------------------------------- (defclass wb-pop-up-menu (wb-menu-mixin cg::pop-up-menu) ()) (defun set-menu-fns (menu &key (selected nil selected?) (held nil held?) (unheld nil unheld?) (sub-item nil sub-item?) (user-props NIL user-props?)) (cond ((typep menu 'wb-menu-item) (if user-props? (setf (user-properties-of menu) user-props)) (if selected? (setf (when-selected-fn-of menu) selected)) (if held? (setf (when-held-fn-of menu) held)) (if unheld? (setf (when-unheld-fn-of menu) unheld)) (if sub-item? (setf (sub-item-fn-of menu) sub-item)) ) ((cg::menu-item-p menu) (let ((wb-menu-fns (member 'wb-menu-fns (cg::plist menu)))) (cond (wb-menu-fns (if user-props? (setf (cdr (assoc 'user-properties wb-menu-fns)) user-props)) (if selected? (setf (cdr (assoc 'when-selected-fn wb-menu-fns)) selected)) (if held? (setf (cdr (assoc 'when-held-fn wb-menu-fns)) held)) (if unheld? (setf (cdr (assoc 'when-unheld-fn wb-menu-fns)) unheld)) (if sub-item? (setf (cdr (assoc 'sub-item-fn wb-menu-fns)) sub-item)) ) (T (setf (cg::plist menu) (append (list 'wb-menu-fns (list (cons 'user-properties user-props) (cons 'when-selected-fn selected) (cons 'when-held-fn held) (cons 'when-unheld-fn unheld) (cons 'sub-item-fn sub-item))) (cg::plist menu))))))) ((cg::menup menu) (when (typep menu 'wb-menu-mixin) (if selected? (setf (when-selected-fn-of menu) selected)) (if held? (setf (when-held-fn-of menu) held)) (if unheld? (setf (when-unheld-fn-of menu) unheld)) (if sub-item? (setf (sub-item-fn-of menu) sub-item))) ) (T NIL))) ;;;---------------------------------------------------------------------------- ;;; Making the pop-menu ;;;--------------------------------------------------------------------------- ;;; It would be nice if a single kind of menu record was used. Sigh ... ;;; Don't yet know how to grab the mouse in a menu to tell which item it's ;;; over and for how long. Hence when-held-fn & when-unheld-fn are never ;;; called. ;;; ... rwo ;; An ACLPC version of make-menu follows ;; NOTES on make-menu specific to ACLPC :- ;; (1) menus are OBJECTS which inherit from STANDARD-CLASS ;; (2) menu-items are STRUCTURES which inherit from STRUCTURE-CLASS ;; (3) to make sub-menus, ie menu-items which are in fact menus, ;; proceed as follows : ;; (cg::make-menu-items :title what-should-appear-in-the-supermenu ;; :value menu-to-become-the-submenu) ;; (add-to-menu some-higher-level-menu this-thing-just-made) ;; (4) to get a sub-menu's :title correct try setting it to ;; (cg::stream-title some-higher-level-menu) ;; (5) because menu-items are STRUCTURES I had to change the name of the ;; MCL function make-wb-menu-item to build-wb-menu-item since ;; make-STRUCTURE is a primitive.. ;; (6) .. and I had to replace make-instance by just that primitive to ;; create mi inside build-wb-menu-item. ;; gwb - on February 08, 1996 ;;;;;;;;; ;;; Revised version of make-menu allowing for when-x-fns (defun make-menu (&key items sub-item-fn (when-selected-fn #'default-when-selected-fn) when-held-fn when-unheld-fn (title NIL) (font *default-menu-font*) (change-offset-fn nil) (menu-type :pop-up) &aux menu) (declare (ignore change-offset-fn font) (special *default-menu-font*)) (let ((*menu-class* (if (eq menu-type :pop-up) 'wb-pop-up-menu 'wb-menu))) (labels ((force-string (x) (if (stringp x) x (format nil "~a" x))) (selection-fn-wrap (menu menu-item window) ;; Get the when-selected-fn -- first from the menu-item and if not ;; found there, then from the menu (let ((selected-fn (cdr (assoc 'when-selected-fn (second (member 'wb-menu-fns (cg::plist menu-item))))))) (unless (functionp selected-fn) (setf selected-fn (or (when-selected-fn-of menu) #'(lambda (a b c) (declare (ignore a b c)) (cg::funcall-menu-item menu menu-item window))))) ;; Now call the selected function on the appropriate arguments (funcall selected-fn (cg::value menu-item) menu :left ;; should be the current (mouse-button) ) ) ) (make-wb-sub-menu (outer-menu sub-menu-items) (labels ((build-wb-menu-item (menu sub-menu-item) (let ((mi (make-instance 'wb-menu-item :title (force-string (first sub-menu-item)) :value sub-menu-item :help-string (third sub-menu-item) :items sub-menu-item :super-menu menu))) (set-menu-fns mi :selected when-selected-fn :held when-held-fn :unheld when-unheld-fn :sub-item sub-item-fn) mi))) (if (and (> (length sub-menu-items) 4) (eq (fourth sub-menu-items) :sub-items)) (let ((sub-menu (cg::open-menu '() *menu-class* (cg::screen cg::*system*) :title (force-string (first sub-menu-items)) :items sub-menu-items :super-menu outer-menu :help-string (third sub-menu-items) :selection-function #'selection-fn-wrap) )) (set-menu-fns sub-menu :selected when-selected-fn :held when-held-fn :unheld when-unheld-fn :sub-item sub-item-fn) (loop for sub-item in (fifth sub-menu-items) when sub-item do (cg::add-to-menu sub-menu (make-wb-sub-menu sub-menu sub-item))) ;; Here is where I must convert to a cg::menu-item (make-instance 'cg::menu-item :title (cg::title sub-menu) :help-string (cg::help-string sub-menu) :value sub-menu)) (build-wb-menu-item outer-menu sub-menu-items))))) (setq menu (cg::open-menu '() *menu-class* (cg::screen cg::*system*) :title (if title (force-string title) "Untitled") :help-string (third items) :items items :selection-function #'selection-fn-wrap)) (set-menu-fns menu :selected when-selected-fn :held when-held-fn :unheld when-unheld-fn :sub-item sub-item-fn) (loop for item in items when item do (cg::add-to-menu menu (make-wb-sub-menu menu item))) menu))) ;;; ---------------------------------------------------------------------------- ;;; Popping the menu ;;; ---------------------------------------------------------------------------- ;;; This is the one that does the job! ;;; In ACLPC terms the menu of the following function will be ;;; assumed to have its handler already defined inside ;;; whatever made it - presumably make-menu (defun menu (menu &key (position NIL position?)) "Pops menu up at position in screen-coordinates. (If given, otherwise at mouse-position). Title will appear on PC only if it's made into the first item otherwise :title slot is ignored completely for pop-up-menus." (when (menu-installed-p menu) ; check if it's already visible (cond (position? (cg::pop-up-menu menu position)) (T (cg::pop-up-menu menu))) ) ) ;; Here is an elementary menu-installed-p (defun menu-installed-p (menu) (menu-p menu) ) ;;; The following function needs to operate within an event-handler ;;; (e.g. to be called after a mouse has been depressed inside a window) ;;; In ACLPC terms the selection function is supplied as an option ;;; to the creation of the menu and the mouse actions are integral ;;; although the selection processes are quite different for the ;;; two types pull-down and pop-up ;;;----------------------------------------------------------------------------- ;;; Miscellaneous menu functions ;;;----------------------------------------------------------------------------- ;; Added 19 June 1998. See kill-menu.lsp (defun submenus? (mnu) "Does mnu have submenus ?~ Be careful about types!" (let* ((mi (cg::menu-items mnu)) (miv (mapcar #'cg::value mi)) (mit (mapcar #'type-of miv))) (values miv (or (position 'wb-menu mit) (position 'wb-pop-up-menu mit))) )) ;;; Added 19 June 1998. See kill-menu.lsp ;;; was killmenu now is destroy-menu (defun destroy-menu (mnu) "Finds the first outer submenu and kills it.~ Then checks backwards etc. until mnu is closed." (declare (special a b)) ;; Following is necessary since submenus? doesn't work on closed streams (unless (not (cg::open-stream-p mnu)) ;;(typep mnu 'cg::closed-stream) (multiple-value-setq (a b) (submenus? mnu)) (cond (b (destroy-menu (elt a b)) mnu) (T ;; Grab super-menu NOW in case we need to back-up (let ((sm (super-menu-of mnu))) (cg::close mnu) (when sm (destroy-menu sm))) mnu))) ) (defun menu-p (menu) (or (typep menu 'wb-menu) (typep menu 'wb-pop-up-menu))) (defun put-menu-prop (menu property value) "Stores value on property of menu" (setf (user-properties-of menu) (acons property value (user-properties-of menu)))) (defun get-menu-prop (menu property) "Returns the value associated with the property on menu" (cdr (assoc property (user-properties-of menu)))) ;;; ---------------------------------------------------------------------------- ;;; Modifying the menu appearance ;;; ---------------------------------------------------------------------------- ;;; These seem to have to do with disabling and ;;; enabling items of a menu ;;; and with checking which are built-in to ACLPC ;;; fairly directly ;;; Jan 24, 1996 GWB ;;; A list version of finding menu-items #| (defun list-get-menu-item (mi-list item-string) (let ((result NIL)) (loop for m-i in mi-list until result do (if (cg::menup (cg::value m-i)) (setf result (list-get-menu-item (cg::menu-items (cg::value m-i)) item-string)) (if (equal (string (cg::title m-i)) item-string) (setf result m-i)) ) ) (print result) result)) |# (defun list-get-menu-item (mi-list item-string) (labels ((lgmi-aux (mi-list) (cond ((and (cg::menu-item-p mi-list) (equal (string (cg::title mi-list)) item-string) ) mi-list) ((null mi-list) NIL) ((listp mi-list) (or (lgmi-aux (first mi-list)) (lgmi-aux (rest mi-list)))) ((cg::menup (cg::value mi-list)) (if (string-equal (string (cg::title mi-list)) item-string) mi-list) (lgmi-aux (cg::menu-items (cg::value mi-list))) ) ))) (lgmi-aux mi-list)) ) ;; Now the function we need (defun get-menu-item (menu item-string) (when menu (cond ((cg::menu-item-p menu) (list-get-menu-item (list menu) item-string)) (t (list-get-menu-item (cg::menu-items menu) item-string))) )) (defun disable-menu-item (menu item-string) "Disables the top-level menu item identified by item-string." (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-menu-item-available-p item NIL) 18oct05 (setf (cg::available item) NIL) ;18oct05 ))) (defun enable-menu-item (menu item-string) "Enables the menu item identified by item-string." (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-menu-item-available-p item T) 18oct05 (setf (cg::available item) T) ;18oct05 ))) (defun check-menu-item (menu item-string &optional (check-char nil)) "Places a check-char beside item identified by item-string ~ if check-char is nil no check mark appears ~ if check-char is t a default check mark is used." (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-menu-item-selected-p item check-char) 18oct05 (setf (cg::selected item) check-char) ;18oct05 ))) (defun set-menu-item-string (menu item-string new-string) "Changes the TITLE for the menu item currently ~ identified by item-string to new-string." (let ((item (get-menu-item menu item-string))) (if item ;(cg::set-stream-title item new-string) 18oct05 (setf (cg::title item) new-string) ;18oct05 )))
21,495
Common Lisp
.l
475
32.128421
125
0.479996
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a593f9f99212c8a2fb532915b6b5b9904f509aba3a88ef49daff8b479b220101
33,527
[ -1 ]
33,528
menu-canvas-pc.lsp
rwoldford_Quail/source/window-basics/menus/menu-canvas-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; menu-canvas-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;--------------------------------------------------------------------- ;;; The story: ;;; Want various hierarchical menus to be associated with a canvas. ;;; These will pop-up in response to certain mouse-events while the ;;; mouse is over either the title-bar of the canvas, or over the ;;; body of the canvas. ;;; This file (and others specialized for each CL) contains those ;;; functions which attach menus to, and select menus from, a canvas. ;;; ;;; ------------------------------------------------------------------- ;;; Author(s): ;;; [email protected] ;;; The model is described in menu-canvas. Menus are described in ;;; menu & menu-mcl. ;;; (in-package :wb) #| 25SEP2023 Already defined in menu-canvas.lsp (defun release-menu-space (menu) (destroy-menu menu)) |# ;;; In MCL the menu-type cannot be :pop-up ;;; ... the default (defmethod set-up-title-menus ((canvas menu-canvas) &key (title-left "Information") (title-middle "Edit-display") (title-right "Canvas") (title-ctrl-left "") (title-ctrl-middle "") (title-ctrl-right "") (menu-type :title) (when-selected-fn #'default-when-selected-fn)) (declare (ignore menu-type)) (install-title-menus canvas :menu-type :pull-down :title-left title-left :title-middle title-middle :title-right title-right :title-ctrl-left title-ctrl-left :title-ctrl-middle title-ctrl-middle :title-ctrl-right title-ctrl-right :when-selected-fn when-selected-fn) (put-title-menus-on-menubar canvas) )
2,836
Common Lisp
.l
62
34.951613
98
0.467148
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
135c6317620bf73f0da1f8c1213041d0338540377986ffab61b339106c4f5dec
33,528
[ -1 ]
33,529
menu.lsp
rwoldford_Quail/source/window-basics/menus/test/menu.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; menu.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; History: ;;; ;;; - A hierarchical pop-up menu system implemented at the University of Waterloo ;;; as part of the Window-Basics generic window-system interface. ;;; ;;; - The system roughly follows the Xerox Interlisp-D menu model. ;;; ;;; ;;; The Model: ;;; ;;; - A menu is a uniform means to select an item from a list of items ;;; and have something happen as a consequence. ;;; ;;; - A menu is a data structure with the slots (or fields or ...) as ;;; described below. ;;; ;;; items - The list of items to appear in the menu. If the item is a list ;;; then its CAR will appear in the menu. ;;; The default selection functions interpret each item as a list of ;;; three elements: ;;; - a label ;;; - a form whose value is returned upon selection, or ;;; a function which is applied to the value of the ;;; special variable *current-canvas*, and ;;; - a help string which can be printed. ;;; Should a fourth element exist, it is ignored by the default ;;; selection functions but is interpreted by the default sub-item ;;; function. In particular, if the fourth element is the keyword ;;; :sub-items then the fifth element of the list is taken to be a ;;; list of sub-items by the default sub-item function. ;;; These sub-items are just items which appear lower in the menu ;;; hierarchy. ;;; ;;; sub-item-fn - A function to be called to determine whether a given item ;;; has any subitems. It is called with two arguments: ;;; - the menu, and ;;; - the item. ;;; It should return a list of the subitems, if any (NIL otherwise). ;;; If an item has sub-items and the user moves the mouse-cursor ;;; off to the right of that item, a sub-menu will appear having ;;; the sub-items as its items. Selecting from the sub-menu is ;;; handled as if selecting from the main menu. ;;; The default sub-item-fn is called default-sub-item-fn and ;;; simply checks to see whether the item is a list whose fourth ;;; element is the keyword :sub-items. If so, it returns the ;;; fifth element in the list; otherwise it returns NIL. ;;; ;;; when-selected-fn - A function to be called when an item is selected. ;;; It is called with three arguments: ;;; - the item selected, ;;; - the menu, and ;;; - the last mouse key released (:left, :middle, or :right). ;;; The default function, default-when-selected-fn evaluates and ;;; returns the value of the second element of the item if the item ;;; is a list of at least length 2. Otherwise the item is returned. ;;; ;;; when-held-fn - A function called when the user has held a mouse key on ;;; an item for *menu-held-wait* milliseconds (initially 1200). ;;; It is intended to be a means to prompt users. As the default, ;;; default-when-held-fn prints the third element of the item (i.e. ;;; its help string) in the user prompt window. If that element is ;;; missing, the string "This item will be selected when the button ;;; is released." will be printed. ;;; The function takes three arguments: ;;; - the item selected, ;;; - the menu, and ;;; - the last mouse key released (:left, :middle, or :right). ;;; ;;; when-unheld-fn - A function called when:(1) the cursor leaves the ;;; item, or (2) when a mouse button is released, or (3) when ;;; another key is pressed. It's called with the same three ;;; arguments as the when-held-fn and is intended to be used ;;; to clean up after the when-held-fn function. For example, ;;; default-when-unheld-fn clears the prompt window. ;;; ;;; font - The font in which the items will appear in the menu. ;;; Default is value of *default-menu-font*. ;;; ;;; title - If non-NIL, the value of this field will appear in a line ;;; above the menu. ;;; ;;; ;;; ;;; ;;; Comments: ;;; ;;; - The system is defined as part of the Window-Basics package. ;;; However, most menu functions are independent of windows. ;;; ;;; ;;; ;;; ;;; Author(s): ;;; ;;; R.W. Oldford ([email protected]) July 1989. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (export '(*default-menu-font* *menu-held-wait* default-sub-item-fn default-when-selected-fn default-when-held-fn default-when-unheld-fn)) ;;;------------------------------------------------------------------------------ ;;; ;;; Default menu variables and functions. ;;; ;;;------------------------------------------------------------------------------ (defvar *default-menu-font* *normal-graphics-font*) (defvar *menu-held-wait* 1200 "The number of milliseconds to wait on a menu before prompting.") (defun default-sub-item-fn (menu item) (declare (ignore menu)) (sub-items-of item)) (defun default-when-selected-fn (item menu mouse-button) "Special selection function that calls the function in the menu ~ on the value of *current-canvas*" (declare (ignore menu mouse-button) (special *current-canvas*)) (if (item-action-p item) (let ((action (item-action item))) (cond ((functionp action) (funcall action *current-canvas*)) (T (eval action)))) item)) (defun default-when-held-fn (item menu mouse-button) (declare (ignore menu mouse-button)) (wb-inform-user (item-message item))) (defun default-when-unheld-fn (item menu mouse-button) (declare (ignore item menu mouse-button)) ()) ;;;----------------------------------------------------------------------------- ;;; ;;; Creating a menu ;;; ;;;----------------------------------------------------------------------------- ;;; ;;; Menu creation is left unspecified at this level. ;;; Many CLs have their own menu implementations and these should be accessed ;;; to avoid a layer of indirection. ;;; However, the implemented function must have the following arguments (with ;;; defaults) and must return a data structure/ object/ whatever that represents ;;; a potentially hierarchical menu. ;;; ;;; (defun make-menu (&key items ;;; (font *default-menu-font*) ;;; (sub-item-fn default-sub-item-fn) ;;; (when-selected-fn default-when-selected-fn) ;;; (when-held-fn default-when-held-fn) ;;; (when-unheld-fn default-when-unheld-fn)) ;;; then-the-body) ;;; ;;; ;;; ------------------------------------------------------------------------------------ ;;; ;;; Other menu functions ;;; ;;; ------------------------------------------------------------------------------------ ;;; ;;; ;;; (defun menu-p (menu) (type menu ........ ;;; ;;; (defun destroy-menu (menu) ... Destroys menu so that its space can be reclaimed. ;;; ;;; (defun set-menu-fns (menu &key (selected nil) (held nil) (unheld nil) (sub-item nil)) ;;; ... Changes the functions when-selected-fn, when-held-fn, ;;; et cetera according to the values of corresponding ;;; keyword arguments. ;;; ;;; (defun put-menu-prop (menu property value) ... Stores value on property of menu. ;;; These are stored on the ;;; "user-properties" slot of the menu. ;;; ;;; (defun get-menu-prop (menu property) ... Returns the value associated with the ;;; property on menu" ;;; ;;; (defun menu (menu &key position) ... Pops menu up at position in screen-coordinates. ;;; (If given, otherwise at current mouse-position.) ;;; ;;; (defun disable-menu-item (menu item-string) Disables the menu item identified by ;;; item-string ;;; ;;; (defun enable-menu-item (menu item-string) Enables the menu item identified by ;;; item-string ;;; ;;; (defun check-menu-item (menu item-string &optional (check-char nil) ;;; Places a check-char beside item identified by ;;; item-string ;;; ;;; (defun set-menu-item-string (menu item-string new-string))
9,815
Common Lisp
.l
212
43.396226
100
0.531565
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
60def89bb876a1aaff0ad69d61d95cc431078b7c7aabf7eb7e5d9da5fe0920b7
33,529
[ -1 ]
33,531
menu-canvas.lsp
rwoldford_Quail/source/window-basics/menus/test/menu-canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; menu-canvas.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1989-1991 ;;; ;;; ;;; ;;;------------------------------------------------------------------- ;;; ;;; The story: ;;; ;;; Want various hierarchical menus to be associated with a canvas. ;;; These will pop-up in response to certain mouse-events while the ;;; mouse is over either the title-bar of the canvas, or over the ;;; body of the canvas. ;;; ;;; This file (and others specialized for each CL) contains those ;;; functions which attach menus to a canvas. ;;; ;;; ------------------------------------------------------------------- ;;; ;;; Author(s): ;;; [email protected] ;;; ;;; The model: ;;; ;;; To achieve this, two slots are assigned to each canvas record to ;;; cache these menus. ;;; ;;; The slots are ;;; ;;; title-menus ;;; and simply ;;; ;;; menus ;;; ;;; for those which are typically associated with the body. ;;; ;;; The value of each slot is a collection of keyword-menu pairs. ;;; Interaction with these collections will be through the functions: ;;; ;;; (canvas-put-title-menu canvas &key key menu) ;;; - stores the title-menu "menu" using the look-up key "key" ;;; ;;; (canvas-get-title-menu canvas &key key) ;;; - if no key is given all title-menus are returned in a list, otherwise ;;; only that title-menu associated with key is returned. ;;; ;;; (canvas-put-menu canvas &key key menu) ;;; - stores the menu "menu" using the look-up key "key" ;;; ;;; (canvas-get-menu canvas &key key) ;;; - if no key is given all menus are returned in a list, otherwise ;;; only that menu associated with key is returned. ;;; ;;; ------------------------------------------------------------------------ ;;; ;;; Conventions: ;;; ;;; For the title-menus,the Window-Basics package makes use of keywords ;;; corresponding to mouse-key + modifier selections supported by wb-mouse. ;;; These are: ;;; ;;; :left ;;; :ctrl-left ;;; :middle ;;; :ctrl-middle ;;; ::right ;;; :ctrl-right ;;; ;;; The shift modifier has been ignored - shift is meant to return different ;;; aspects of the lisp object selected. If this recommended style is ;;; followed, no menu should be constructed. ;;; ;;; ;;; It's important to note that the user is free to use their own collection ;;; of keys in any application. This allows the menu interaction to be ;;; easily extended. ;;; ;;; ... rwo ;;; ;;; (in-package :wb) (export '(add-canvas-title-item remove-canvas-title-item canvas-put-title-menu canvas-get-title-menu canvas-put-menu canvas-get-menu title-menus-of menus-of menu-canvas left-title-items-of ctrl-left-title-items-of middle-title-items-of ctrl-middle-title-items-of right-title-items-of ctrl-right-title-items-of)) ;;;===================================================================== ;;; Want various menus to be associated with a window. ;;; Minimally, these will pop up whenever a mouse button is depressed ;;; while the mouse is over the title-bar of the canvas. ;;; For the Macintosh, these menus will appear in the menu-bar ;;; when that canvas is the active window on the desktop. ;;; ;;; Accomplished by defining an appropriate mixin for canvas: ;;; ;;; menu-canvas ;;; ;;; ...rwo ;;;===================================================================== (defclass menu-canvas (host-menu-canvas) ((menus :initarg :menus :initform nil :accessor menus-of :documentation "A collection of keyword-menu pairs. These menus will ~ appear on when selection is made in the body of the ~ canvas.") (title-menus :initarg :title-menus :initform nil :accessor title-menus-of :documentation "A collection of keyword-menu pairs. These menus will ~ appear on when selection is made in the title of the ~ canvas.") (left-title-items :initform NIL :initarg :left-title-items :accessor left-title-items-of) (middle-title-items :initform NIL :initarg :middle-title-items :accessor middle-title-items-of) (right-title-items :initarg :right-title-items :initform (list (list "Redisplay" #'(lambda (c) (redisplay c)) "Redisplay this canvas.") (list "Display parameters" NIL "Change some display parameters of this canvas." :sub-items (list (list "Title" #'(lambda (c) (setf (canvas-title c) (prompt-user :prompt-string "Enter the title: " :read-type :string :type 'string))) "Change the title of the canvas.") (list "Background color" #'(lambda (c) (canvas-set-background-color c (prompt-user-for-color))) "Change the background color of the canvas.") (list "Pen color" #'(lambda (c) (set-pen-color c (prompt-user-for-color))) "Change the pen color.") (list "Pen width" #'(lambda (c) (set-pen-width c (prompt-user :prompt-string "Enter the new width (in pixels): " :type 'integer :read-type :eval))) "Change the pen width."))) (list "Canvas fonts" NIL "Change the font of this canvas." :sub-items (list (list "Font" #'(lambda (c) (declare (special *canvas-font-names*)) (let ((f-copy (copy-canvas-font (canvas-font c)))) (set-canvas-font-name f-copy (first (prompt-for-items *canvas-font-names*))) (setf (canvas-font c) f-copy))) "Change the font name used in the canvas.") (list "Font style" #'(lambda (c) (declare (special *canvas-font-styles*)) (let ((f-copy (copy-canvas-font (canvas-font c)))) (set-canvas-font-style f-copy (prompt-for-items *canvas-font-styles* :selection-type :disjoint)) (setf (canvas-font c) f-copy))) "Change the font style used in the canvas.") (list "Font size" #'(lambda (c) (let ((f-copy (copy-canvas-font (canvas-font c)))) (set-canvas-font-size f-copy (prompt-user :prompt-string "Enter the new font size (1 to 127): " :type 'integer :read-type :eval)) (setf (canvas-font c) f-copy))) "Change the font size used in the canvas."))) (list "Draw on canvas" #'(lambda (c) (let (c?) (loop (when (mouse-down-p c) (setf c? (which-canvas (screen-mouse-position))) (if (not (eq c c?)) (return)) (let* ((mouse-pos (mouse-position c)) (old-x (position-x mouse-pos)) (old-y (position-y mouse-pos)) new-x new-y) (do ((i 1 (+ i 1))) ((not (mouse-down-p c))) (setf mouse-pos (mouse-position c)) (setf new-x (position-x mouse-pos)) (setf new-y (position-y mouse-pos)) (canvas-draw-line c old-x old-y new-x new-y) (setf old-x new-x) (setf old-y new-y)) (return)))))) "Draw on the current canvas.") (list "Clear canvas" #'canvas-clear "Clear the canvas.") (list "Save canvas" #'save-value "Save the current canvas on a symbol.") (list "Inspect canvas" #'inspect "Inspect the current canvas.")) :accessor right-title-items-of) (ctrl-left-title-items :initform NIL :accessor ctrl-left-title-items-of) (ctrl-middle-title-items :initform NIL :accessor ctrl-middle-title-items-of) (ctrl-right-title-items :initform NIL :accessor ctrl-right-title-items-of)) (:documentation "A mixin class for canvas to allow for caching menus and defining~ some menu items on the title bar.")) ;;;-------------------------------------------------------------------------- ;;; ;;; Now the functions. ;;; ;;;-------------------------------------------------------------------------- (defun add-canvas-title-item (canvas item &optional (where :left)) "Adds the item to the title items of canvas corresponding to one of ~ :left :middle :right ~ :ctrl-left :ctrl-middle or :ctrl-right as the optional argument ~ where. The default of where is :left." (case where (:left (setf (left-title-items-of canvas) (append (left-title-items-of canvas) (list item)))) (:middle (setf (middle-title-items-of canvas) (append (middle-title-items-of canvas) (list item)))) (:right (setf (right-title-items-of canvas) (append (right-title-items-of canvas) (list item)))) (:ctrl-left (setf (ctrl-left-title-items-of canvas) (append (ctrl-left-title-items-of canvas) (list item)))) (:ctrl-middle (setf (ctrl-middle-title-items-of canvas) (append (ctrl-middle-title-items-of canvas) (list item)))) (:ctrl-right (setf (ctrl-right-title-items-of canvas) (append (ctrl-right-title-items-of canvas) (list item)))) )) (defun remove-canvas-title-item (canvas item &optional (where :left)) "Removes the item (if found) from ~ the title items of canvas corresponding to one of ~ :left :middle :right ~ :ctrl-left :ctrl-middle or :ctrl-right as the optional argument ~ where (default :left)." (case where (:left (setf (left-title-items-of canvas) (remove item (left-title-items-of canvas) :test #'equal))) (:middle (setf (middle-title-items-of canvas) (remove item (middle-title-items-of canvas) :test #'equal))) (:right (setf (right-title-items-of canvas) (remove item (right-title-items-of canvas) :test #'equal))) (:ctrl-left (setf (ctrl-left-title-items-of canvas) (remove item (ctrl-left-title-items-of canvas) :test #'equal))) (:ctrl-middle (setf (ctrl-middle-title-items-of canvas) (remove item (ctrl-middle-title-items-of canvas) :test #'equal))) (:ctrl-right (setf (ctrl-right-title-items-of canvas) (remove item (ctrl-right-title-items-of canvas) :test #'equal))) ) ) (defun canvas-put-title-menu (canvas &key key menu) (with-accessors ((tm title-menus-of)) canvas "Adds the :menu to the title-menus using :key as a lookup key." (setq tm (acons key menu tm)))) (defun canvas-get-title-menu (canvas &key key) (with-accessors ((tm title-menus-of)) canvas "Gets the :menu from the title-menus using :key as a lookup key. If no :key is given, the assoc list of title-menus is returned." (if key (cdr (assoc key tm)) tm))) (defun canvas-put-menu (canvas &key key menu) (with-accessors ((m menus-of)) canvas "Adds the :menu to the menus using :key as a lookup key." (setq m (acons key menu m)))) (defun canvas-get-menu (canvas &key key) (with-accessors ((m menus-of)) canvas "Gets the :menu from the menus using :key as a lookup key. If no :key is given, the assoc list of menus is returned." (if key (cdr (assoc key m)) m))) (defun install-title-menus (canvas &key (title-left "Information") (title-middle "Edit-display") (title-right "Canvas") (ctrl-title-left "") (ctrl-title-middle "") (ctrl-title-right "") (menu-type :pop-up) ) "Installs the title items found on the browser as title-menus of the canvas." (let (items) ;; release the menu record (some systems have such non-lisp things) (loop for m in (title-menus-of canvas) do (release-menu-space (cdr m))) (setf (title-menus-of canvas) NIL) (loop for f in (list (list :left #'left-title-items-of title-left) (list :middle #'middle-title-items-of title-middle) (list :right #'right-title-items-of title-right) (list :ctrl-left #'ctrl-left-title-items-of ctrl-title-left) (list :ctrl-middle #'ctrl-middle-title-items-of ctrl-title-middle) (list :ctrl-right #'ctrl-right-title-items-of ctrl-title-right)) when (setf items (funcall (second f) canvas)) collect (canvas-put-title-menu canvas :key (first f) :menu (make-menu :canvas canvas :items items :title (third f) :menu-type menu-type :when-selected-fn #'default-when-selected-fn))) ) ) (defun release-menu-space (menu) (declare (ignore menu))) ;;; In MCL the menu-type cannot be :pop-up ;;; ... the default (defmethod set-up-title-menus ((canvas menu-canvas)) (install-title-menus canvas)) (defmethod initialize-instance :after ((canvas menu-canvas) &key) "When a new menu-canvas is created, we must set up the title menus ~ for its class ~ if it doesn't already exist." ;; the following calls install-title-menus with appropriate menu-type (set-up-title-menus canvas) )
16,549
Common Lisp
.l
386
29.989637
90
0.483701
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6237ad92af78e3645b24af0b2ea6908093c1f402d5553709d14e2d147ceb9895
33,531
[ -1 ]
33,534
canvas-button-pc.lsp
rwoldford_Quail/source/window-basics/mouse/canvas-button-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-button-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;=========================================================================== (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) ;;;=================================================================== ;;; Now make button events function uniformly ;;;=================================================================== #| ;; defined on host-window-pc ;; which loads earlier (defclass host-pane (cg::bitmap-pane) NIL) (defmethod cg::default-pane-class ((window host-window)) 'host-pane) ;;; Methods on mouse-left-down & co go here = see Wayne's email. (defmethod cg::mouse-left-down ((pane host-pane) (buttons T) (cursor-position T)) (mouse-left-button-event-fn (cg::owner pane) (make-position (h-draw:point-x cursor-position) (host-to-canvas-y (cg::owner pane) (h-draw:point-y cursor-position)))) ) (defmethod cg::mouse-right-down ((pane host-window) (buttons T) (cursor-position T)) (mouse-right-button-event-fn pane (make-position (h-draw:point-x cursor-position) (host-to-canvas-y pane (h-draw:point-y cursor-position))))) (defmethod cg::mouse-middle-down ((pane host-window) (buttons T) (cursor-position T)) (mouse-middle-button-event-fn pane (make-position (h-draw:point-x cursor-position) (host-to-canvas-y pane (h-draw:point-y cursor-position))))) |# #| 02Dec 2014 (defmethod cg::event ((pane host-pane) event (button-state t) data ) (call-next-method) (let ((canvas (cg::parent pane))) (cond ;; ((eql event cg::null-event) NIL) ((cg::mouse-event-p event) (mouse-button-event-fn canvas (mouse-position canvas))) (T (call-next-method)) ) ) ) |# ;;; 04Dec 2014 (defmethod cg::mouse-left-down ((pane host-pane) (buttons T) (cursor-position T)) (let* ((canvas (cg::parent pane)) (mouse-position (make-position (h-draw:point-x cursor-position) (host-to-canvas-y canvas (h-draw:point-y cursor-position)) )) ) (mouse-left-button-event-fn canvas mouse-position) ) ) (defmethod cg::mouse-right-down ((pane host-pane) (buttons T) (cursor-position T)) (let* ((canvas (cg::parent pane)) (mouse-position (make-position (h-draw:point-x cursor-position) (host-to-canvas-y canvas (h-draw:point-y cursor-position)) )) ) (mouse-right-button-event-fn canvas mouse-position) ) ) (defmethod cg::mouse-middle-down ((pane host-pane) (buttons T) (cursor-position T)) (let* ((canvas (cg::parent pane)) (mouse-position (make-position (h-draw:point-x cursor-position) (host-to-canvas-y canvas (h-draw:point-y cursor-position)) )) ) (mouse-middle-button-event-fn canvas mouse-position) ) )
3,901
Common Lisp
.l
84
37.821429
132
0.519716
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
12289f652ffccb2ec4cd4e0c888af4d027293a42a5c1cb2ee4e54db30ce36c3a
33,534
[ -1 ]
33,535
canvas-button.lsp
rwoldford_Quail/source/window-basics/mouse/canvas-button.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; canvas-button.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;;=========================================================================== (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-button get-left-button-fn get-shift-left-button-fn get-ctrl-left-button-fn get-middle-button-fn get-shift-middle-button-fn get-ctrl-middle-button-fn get-right-button-fn get-shift-right-button-fn get-ctrl-right-button-fn set-left-button-fn set-shift-left-button-fn set-ctrl-left-button-fn set-middle-button-fn set-shift-middle-button-fn set-ctrl-middle-button-fn set-right-button-fn set-shift-right-button-fn set-ctrl-right-button-fn))) ;;;===================================================================== ;;; Want various button behaviours for interior of windows. ;;; Accomplished by defining an appropriate mixin for canvas: ;;; ;;; canvas-button ;;; ;;; ...rwo ;;;===================================================================== (defclass canvas-button () ((left-button-fn :initarg :left-button-fn :initform #'default-left-button-fn :accessor left-button-fn-of) (middle-button-fn :initarg :middle-button-fn :initform #'default-middle-button-fn :accessor middle-button-fn-of) (right-button-fn :initarg :right-button-fn :initform #'default-right-button-fn :accessor right-button-fn-of) (shift-left-button-fn :initarg :shift-left-button-fn :initform #'default-shift-left-button-fn :accessor shift-left-button-fn-of) (shift-middle-button-fn :initarg :shift-middle-button-fn :initform #'default-shift-middle-button-fn :accessor shift-middle-button-fn-of) (shift-right-button-fn :initarg :shift-right-button-fn :initform #'default-shift-right-button-fn :accessor shift-right-button-fn-of) (ctrl-left-button-fn :initarg :ctrl-left-button-fn :initform #'default-ctrl-left-button-fn :accessor ctrl-left-button-fn-of) (ctrl-middle-button-fn :initarg :ctrl-middle-button-fn :initform #'default-ctrl-middle-button-fn :accessor ctrl-middle-button-fn-of) (ctrl-right-button-fn :initarg :ctrl-right-button-fn :initform #'default-ctrl-right-button-fn :accessor ctrl-right-button-fn-of))) ;;;======================================================================================== ;;; functions for accessing and setting button functions, cbh ;;;======================================================================================== (defun get-left-button-fn (canvas) (left-button-fn-of canvas)) (defun get-shift-left-button-fn (canvas) (shift-left-button-fn-of canvas)) (defun get-ctrl-left-button-fn (canvas) (ctrl-left-button-fn-of canvas)) (defun get-middle-button-fn (canvas) (middle-button-fn-of canvas)) (defun get-shift-middle-button-fn (canvas) (shift-middle-button-fn-of canvas)) (defun get-ctrl-middle-button-fn (canvas) (ctrl-middle-button-fn-of canvas)) (defun get-right-button-fn (canvas) (right-button-fn-of canvas)) (defun get-shift-right-button-fn (canvas) (shift-right-button-fn-of canvas)) (defun get-ctrl-right-button-fn (canvas) (ctrl-right-button-fn-of canvas)) (defun set-left-button-fn (canvas new-fn) (setf (left-button-fn-of canvas) new-fn)) (defun set-shift-left-button-fn (canvas new-fn) (setf (shift-left-button-fn-of canvas) new-fn)) (defun set-ctrl-left-button-fn (canvas new-fn) (setf (ctrl-left-button-fn-of canvas) new-fn)) (defun set-middle-button-fn (canvas new-fn) (setf (middle-button-fn-of canvas) new-fn)) (defun set-shift-middle-button-fn (canvas new-fn) (setf (shift-middle-button-fn-of canvas) new-fn)) (defun set-ctrl-middle-button-fn (canvas new-fn) (setf (ctrl-middle-button-fn-of canvas) new-fn)) (defun set-right-button-fn (canvas new-fn) (setf (right-button-fn-of canvas) new-fn)) (defun set-shift-right-button-fn (canvas new-fn) (setf (shift-right-button-fn-of canvas) new-fn)) (defun set-ctrl-right-button-fn (canvas new-fn) (setf (ctrl-right-button-fn-of canvas) new-fn))
5,456
Common Lisp
.l
110
40.872727
99
0.544512
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
db14fe184ba8bc5cc7c65bbfef6d280b8fb250f684ad3997a92a65f417b1525b
33,535
[ -1 ]
33,536
mouse-sblx.lsp
rwoldford_Quail/source/window-basics/mouse/mouse-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; mouse-sblx.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1996 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;========================================================================== ;;; - created to provide ;;; uniform three-button mouse interaction ;;; left ;;; middle ;;; right ;;; Each key can also be modified by either the shift-key or the ;;; control-key. ;;; NOTES: ;;; For the purposes of PCs with only L and R buttons (eg laptops) ;;; meta-L or meta-R have been defined to function as a middle ;;; button. meta- corresponds to alt- on PCs. ;;; ;;;=========================================================================== (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;; ;;; Redefining shadowed symbols SEE DEFPACKAGE ;;;(shadow '(mouse-down-p shift-key-p control-key-p)) ;now in window-basics-package.lsp 01SEP2021 (defun mouse-down-p () "Determines whether the mouse pointer in down" (if (> (pointer-button-state (port-pointer (find-port))) 0) T NIL)) (defun shift-key-p () "Tests whether a shift key is being held down." (if (eql (port-modifier-state (find-port)) +shift-key+) T nil)) (defun control-key-p () "Tests whether a control key is being held down." (if (eql (port-modifier-state (find-port)) +control-key+) T nil)) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(mouse-down-p shift-key-p control-key-p))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (eval-when (:compile-toplevel :load-toplevel :execute) (export '(mouse-state mouse-position mouse-x mouse-y screen-mouse-position screen-mouse-x screen-mouse-y))) (defun mouse-state () (let ((result (pointer-button-state (port-pointer (find-port))))) (cond ((eql result +pointer-left-button+) (setf result :left)) ((eql result +pointer-middle-button+) (setf result :middle)) ((eql result +pointer-right-button+) (setf result :right)) (t (setf result :none))) result )) ;;; Old form .. in which position would NOT be one! #| (defun mouse-position (canvas) (let ((mp (get-frame-pane canvas 'host-pane))) (let ((position (stream-cursor-position mp))) ;; Now convert to window-basics position (make-position (h-draw:point-x position) (host-to-canvas-y canvas (h-draw:point-y position)))))) |# ;;; New version (defun mouse-position (canvas) (let* ((mp (get-frame-pane canvas 'host-pane)) (coord-list (multiple-value-list (stream-cursor-position mp)))) (h-draw:make-point (first coord-list) (host-to-canvas-y canvas (second coord-list))))) (defun mouse-x (canvas) (h-draw:point-x (mouse-position canvas))) (defun mouse-y (canvas) (h-draw:point-y (mouse-position canvas))) ;;;======================================================================================== ;;; mouse position in screen coordinates, cbh ;;;======================================================================================== (defun screen-mouse-position () "Returns position of mouse in screen coords." (let ((pointer-pos (multiple-value-list (pointer-position (port-pointer (find-port)))))) (make-position (first pointer-pos) (second pointer-pos)) )) (defun screen-mouse-x () (position-x (screen-mouse-position))) (defun screen-mouse-y () (position-y (screen-mouse-position)))
4,071
Common Lisp
.l
95
39.336842
107
0.558682
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
74f65b8266c09034573ed01fa14cf6474500dcfa7f5550b5beb89b92fcd029d7
33,536
[ -1 ]
33,538
mouse.lsp
rwoldford_Quail/source/window-basics/mouse/mouse.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; mouse.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1989-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) ;;; The mouse event dispatcher (defun mouse-button-event-fn (canvas mouse-pos) "Function dispatches to other button-event-fn's on basis of the ~ state of the mouse buttons." (case (mouse-state) (:left (mouse-left-button-event-fn canvas mouse-pos)) (:middle (mouse-middle-button-event-fn canvas mouse-pos)) (:right (mouse-right-button-event-fn canvas mouse-pos)) (:none (mouse-no-button-event-fn canvas mouse-pos)))) ;;; Decided to mimic the Xerox Interlisp-D windows - attaching left, ;;; middle, and right button event functions directly on each window. ;;; Each of these can be modified with either the shift-key or the ctrl-key. ;;; Note that these functions are instance variables and hence can be ;;; different for each instance of canvas-button. ;;; (defun mouse-left-button-event-fn (canvas mouse-pos) (if (shift-key-p) (funcall (shift-left-button-fn-of canvas) canvas mouse-pos) (if (control-key-p) (funcall (ctrl-left-button-fn-of canvas) canvas mouse-pos) (funcall (left-button-fn-of canvas) canvas mouse-pos)))) (defun mouse-middle-button-event-fn (canvas mouse-pos) (if (shift-key-p) (funcall (shift-middle-button-fn-of canvas) canvas mouse-pos) (if (control-key-p) (funcall (ctrl-middle-button-fn-of canvas) canvas mouse-pos) (funcall (middle-button-fn-of canvas) canvas mouse-pos)))) (defun mouse-right-button-event-fn (canvas mouse-pos) (if (shift-key-p) (funcall (shift-right-button-fn-of canvas) canvas mouse-pos) (if (control-key-p) (funcall (ctrl-right-button-fn-of canvas) canvas mouse-pos) (funcall (right-button-fn-of canvas) canvas mouse-pos)))) (defun mouse-no-button-event-fn (canvas mouse-pos) (declare (ignore canvas mouse-pos)) )
2,584
Common Lisp
.l
59
40.813559
85
0.621611
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
3ab74f5d8aad1fe0249dac47d9b19305e703bc6403654d997d7aea5fd0d2187e
33,538
[ -1 ]
33,539
button-default.lsp
rwoldford_Quail/source/window-basics/mouse/button-default.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; button-default.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1989-1991 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(default-left-button-fn default-middle-button-fn default-right-button-fn default-ctrl-left-button-fn default-ctrl-middle-button-fn default-ctrl-right-button-fn default-shift-left-button-fn default-shift-middle-button-fn default-shift-right-button-fn))) ;;;===================================================================== ;;; Default button event functions. ;;;===================================================================== ;;; ;;; These can/should be replaced on any particular canvas by ;;; application specific functions. ;;; There is some consistency intended here but you are free to follow ;;; your own rules. ;;; In particular, we imagine that a canvas has a 'display' variable ;;; holding the graphical display structure. ;;; ;;; We propose that: ;;; ;;; - left and middle buttons be used to interact with elements ;;; of the underlying display ;;; - right button behaviours be associated with the canvas ;;; itself ;;; - ctrl modifier be reserved to return the pointer to the ;;; selected object (in keeping with above rules) ;;; - shift modifier be used for multiply accessing objects ;;; (not implemented) ;;; ;;; (defun draw-on-canvas-fn (canvas mouse-pos) (let ((old-x (position-x mouse-pos)) (old-y (position-y mouse-pos)) new-mouse-pos new-x new-y) (do ((i 1 (+ i 1))) ((not (mouse-down-p))) (setf new-mouse-pos (mouse-position canvas)) (setf new-x (position-x new-mouse-pos)) (setf new-y (position-y new-mouse-pos)) (canvas-draw-line canvas old-x old-y new-x new-y) (setf old-x new-x) (setf old-y new-y)))) (defun default-left-button-fn (canvas mouse-pos) (draw-on-canvas-fn canvas mouse-pos)) (defun default-middle-button-fn (canvas mouse-pos) (let* ((x (position-x mouse-pos)) (y (position-y mouse-pos)) (left (max 0 (- x 10))) (bottom (max 0 (- y 10)))) (canvas-flash-region canvas :left left :bottom bottom :width 20 :height 20 :times 5))) (defun default-right-button-fn (canvas mouse-pos) (declare (ignore mouse-pos)) (do ((i 1 (+ i 1))) ((not (mouse-down-p))) (let* ((new-mouse-pos (mouse-position canvas)) (x (position-x new-mouse-pos)) (y (position-y new-mouse-pos)) (left (max 0 (- x 10))) (right (+ x 10)) (r-diff (- right (canvas-width canvas))) (bottom (max 0 (- y 10))) (width (if (> r-diff 0) (- 20 r-diff) 20)) (height 20)) (canvas-invert canvas :canvas-left left :canvas-bottom bottom :width width :height height)))) (defun default-ctrl-left-button-fn (canvas mouse-pos) (declare (ignore mouse-pos)) (quail-print (canvas-display canvas))) (defun default-ctrl-middle-button-fn (canvas mouse-pos) (declare (ignore canvas)) (quail-print mouse-pos)) (defun default-ctrl-right-button-fn (canvas mouse-pos) (declare (ignore mouse-pos)) (quail-print canvas)) ;;; No suggestion at all what shift button selection should do. ;;; (defun default-shift-left-button-fn (canvas mouse-pos) (declare (ignore canvas mouse-pos))) (defun default-shift-middle-button-fn (canvas mouse-pos) (declare (ignore canvas mouse-pos))) (defun default-shift-right-button-fn (canvas mouse-pos) (declare (ignore canvas mouse-pos)))
4,535
Common Lisp
.l
111
34.261261
89
0.547092
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
92f600fb746560c97ee93843d25b161eda1841bae20b922e71ad700c4e6a6ecb
33,539
[ -1 ]
33,540
canvas-button-sblx.lsp
rwoldford_Quail/source/window-basics/mouse/canvas-button-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; canvas-button-sblx.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;=========================================================================== (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) ;;;=================================================================== ;;; Now make button events function uniformly ;;;=================================================================== (defmethod handle-event ((pane host-pane) (p-event pointer-button-press-event)) (declare (ignore p-event)) ;; seems like we don't need it here? (let ((canvas (pane-frame pane))) (mouse-button-event-fn canvas (mouse-position canvas)) ) (call-next-method) ;; probably need this still? )
1,423
Common Lisp
.l
31
44.064516
85
0.466236
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d43ba6983aa13ad3af31e39c9ae0c02845026e11be4e703e361de64fdbb0eb90
33,540
[ -1 ]
33,542
alternate-mouse-down-p.lsp
rwoldford_Quail/source/window-basics/mouse/alternate-mouse-down-p.lsp
;;; This is alternate-mouse-down-p.lsp ;;; holding the original from Q/S/W-B/Mouse/mouse-pc.lsp ;;; which seems to cause a 'freeze' in the form of an infinite loop ;;; since the call (cg::key-is-down-p cg::left-mouse-button) [and its relatives] ;;; returns the same as (values): absolutely nothing! ;;; and a possible alternative which came from ;;; (1) checking mouse in ACL's permuted index, and ;;; (2) following up on these virtual buttons as mentioned ;;; on the page for key-is-down-p ;;; from which I followed to key-names where there are the trio vk-[l,m,r]button. ;;; Here is the original (in-package :wb), of course (defun mouse-down-p () (or (cg::key-is-down-p cg::left-mouse-button) (cg::key-is-down-p cg::middle-mouse-button) (cg::key-is-down-p cg::right-mouse-button))) ;;; Here is the alternate (defun mouse-down-p () (or (cg::key-is-down-p cg::vk-lbutton) (cg::key-is-down-p cg::vk-mbutton) (cg::key-is-down-p cg::vk-rbutton))) ;;; This alternate definition allows sweeping to start and avoids the 'freeze', ;;; but it does not 'release' when the button is released. ;;; Perhaps we also need (cg::wait-for-mouse-buttons-up) ?
1,208
Common Lisp
.l
23
49.173913
81
0.678814
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
8ad2ba0c1deafb9aeceea520b64626b8ddaa021f0c784d46097cd5b876482b3f
33,542
[ -1 ]
33,543
mouse-pc.lsp
rwoldford_Quail/source/window-basics/mouse/mouse-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; mouse-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1996 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;========================================================================== ;;; - created to provide ;;; uniform three-button mouse interaction ;;; left ;;; middle ;;; right ;;; Each key can also be modified by either the shift-key or the ;;; control-key. ;;; NOTES: ;;; For the purposes of PCs with only L and R buttons (eg laptops) ;;; meta-L or meta-R have been defined to function as a middle ;;; button. meta- corresponds to alt- on PCs. ;;; ;;;=========================================================================== (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;; ;;; Redefining shadowed symbols SEE DEFPACKAGE ;;;(shadow '(mouse-down-p shift-key-p control-key-p)) (defun mouse-down-p () (cg::process-pending-events-if-event-handler) (let ((result)) ; 27JUL2023 (setf result (or (cg::key-is-down-p cg::vk-lbutton) (cg::key-is-down-p cg::vk-mbutton) (cg::key-is-down-p cg::vk-rbutton))) result) ) ;27JUL2023 (defun shift-key-p () "Tests whether a shift key is being held down." (or (cg::key-is-down-p cg::vk-shift) (cg::key-is-down-p cg::vk-left-shift) (cg::key-is-down-p cg::vk-right-shift) )) (defun control-key-p () "Tests whether a control key is being held down." (let ((result)) ;27JUL2023 (setf result (or (cg::key-is-down-p cg::vk-control) (cg::key-is-down-p cg::vk-left-control) (cg::key-is-down-p cg::vk-right-control) )) ;(when result (cg.gtk::update-key-state cg::vk-right-control :up) ;; 23JUL2023 package cg.gtk nolonger exists ; (cg.gtk::update-key-state cg::vk-left-control :up)) ;; DITTO result) ; 27JUL2023 ) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(mouse-down-p shift-key-p control-key-p))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (eval-when (:compile-toplevel :load-toplevel :execute) (export '(mouse-state mouse-position mouse-x mouse-y screen-mouse-position screen-mouse-x screen-mouse-y))) #| (defun mouse-state () (cg::process-pending-events) (let ((state (cg::mouse-button-state))) (cond ((cg::button-match state (or cg::middle-mouse-button ;;(and cg::left-mouse-button cg::right-mouse-button) (and cg::meta-key (or cg::left-mouse-button cg::right-mouse-button)))) :middle) ((cg::button-match state cg::left-mouse-button) :left) ((cg::button-match state cg::right-mouse-button) :right) ( T :none)))) |# (defun mouse-state () ;(format t "Calling mouse-state~%") (let ((result)) ; 27JUL2023 (setf result (cond ((cg::key-is-down-p cg::vk-lbutton) :left) ((cg::key-is-down-p cg::vk-mbutton) :middle) ((cg::key-is-down-p cg::vk-rbutton) :right) ( T :none))) (cg::process-pending-events) result) ) ; 27JUL2023 (defun mouse-position (canvas) (let ((position (cg::cursor-position canvas))) ;; Now convert to window-basics position (make-position (h-draw:point-x position) (host-to-canvas-y canvas (h-draw:point-y position))))) (defun mouse-x (canvas) (h-draw:point-x (cg::cursor-position canvas))) (defun mouse-y (canvas) (host-to-canvas-y canvas (h-draw:point-y (cg::cursor-position canvas)))) ;;;======================================================================================== ;;; mouse position in screen coordinates, cbh ;;;======================================================================================== (defun screen-mouse-position () "Returns position of mouse in screen coords." (cg::with-device-context (hdc (cg::screen cg::*system*)) (let* ((scrn (cg::screen cg::*system*)) ; 27JUL2023 (position (cg::cursor-position scrn))) (make-position (h-draw::point-x position) (- (screen-height) (h-draw::point-y position)))))) (defun screen-mouse-x () (position-x (screen-mouse-position))) (defun screen-mouse-y () (position-y (screen-mouse-position)))
5,074
Common Lisp
.l
118
36.491525
111
0.522215
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c87c583f0c73bd3bd01f0466e3435f6e0fae0ae2de010343b5c4515a49271606
33,543
[ -1 ]
33,547
start-windows-sblx.lsp
rwoldford_Quail/source/window-basics/start-windows/start-windows-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; start-windows-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; R.W. Oldford 1994 ;;; ;;; A copy of start-windows-excl.lisp <= *** ;;; There is no SI package there is an Allegro getenv function ! ;;; It needs a C pointer as an argument!!! ;;; I'm not sure what the MP package is either! ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(start-windows stop-windows))) (defun default-host () "Returns value of *default-host* if it's non-NIL ~ otherwise queries the system environment variable DISPLAY for the ~ host, assigns the result to *default-host* and returns it." (declare (special *default-host*)) #| (unless *default-host* (let ((system-host (si:getenv "DISPLAY"))) (setf *default-host* (subseq system-host 0 (position #\: system-host))))) *default-host* |# ) (defun start-windows () "Starts up the windowing environment for this implementation." #| (default-display) (mp:process-run-function "Quail Event Handler" #'event-handler *default-display*) |# ) (defun stop-windows () "Shuts down the windowing environment for this implementation." #| (let ((quail-event-handler (find-if #'(lambda (proc) (string-equal "Quail Event Handler" (mp:process-name proc))) mp:*all-processes*))) (if quail-event-handler (mp:process-kill quail-event-handler)) (setf *current-canvas* NIL) (setf *default-display* (xlib:close-display *default-display*))) |# )
2,225
Common Lisp
.l
57
33.964912
94
0.554017
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6f7043ed6e3c23063faee0b640bef9c36ec12f5a94573adc27722c4974907dd7
33,547
[ -1 ]
33,548
start-windows-pc.lsp
rwoldford_Quail/source/window-basics/start-windows/start-windows-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; start-windows-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; R.W. Oldford 1994 ;;; ;;; A copy of start-windows-excl.lisp <= *** ;;; There is no SI package there is an Allegro getenv function ! ;;; It needs a C pointer as an argument!!! ;;; I'm not sure what the MP package is either! ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(start-windows stop-windows))) (defun default-host () "Returns value of *default-host* if it's non-NIL ~ otherwise queries the system environment variable DISPLAY for the ~ host, assigns the result to *default-host* and returns it." (declare (special *default-host*)) #| (unless *default-host* (let ((system-host (si:getenv "DISPLAY"))) (setf *default-host* (subseq system-host 0 (position #\: system-host))))) *default-host* |# ) (defun start-windows () "Starts up the windowing environment for this implementation." #| (default-display) (mp:process-run-function "Quail Event Handler" #'event-handler *default-display*) |# ) (defun stop-windows () "Shuts down the windowing environment for this implementation." #| (let ((quail-event-handler (find-if #'(lambda (proc) (string-equal "Quail Event Handler" (mp:process-name proc))) mp:*all-processes*))) (if quail-event-handler (mp:process-kill quail-event-handler)) (setf *current-canvas* NIL) (setf *default-display* (xlib:close-display *default-display*))) |# )
2,282
Common Lisp
.l
57
33.929825
95
0.539397
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ac7183e4faea7e44c41847f21b1bbefe82e2269d80f2b7c0d7eb8ef44151f0ef
33,548
[ -1 ]
33,549
color-canvas-sblx.lsp
rwoldford_Quail/source/window-basics/canvas/color-canvas-sblx.lsp
;;; This is ~/RESERVE/lc2-Quail/source/window-basics/canvas/new-color-canvas-sblx.lsp ;;; modeled on (same-dir)/new-bw-canvas-sblx.lsp ;;; to fix location, names, threads etc.. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; color-canvas-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1993 ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-color-canvas))) ;;; ======================================================================= ;;; Creating a colour canvas ;;; ======================================================================= ;;; a new copy ;(define-application-frame quail-color-canvas (canvas) ;24SEP2024 (define-application-frame color-canvas (canvas) ;24SEP2024 ((left :initarg :left :accessor left) (bottom :initarg :bottom :accessor bottom) (height :initarg :height :accessor height) (width :initarg :width :accessor width) (title :initarg :title :accessor title) (color :initarg :color :accessor color) (canvas-keywords :initarg :canvas-keywords :accessor canvas-keywords) (pen-color :initarg :pen-color :accessor pen-color) (pen-width :initarg :pen-width :accessor pen-width) (pen-operation :initarg :pen-operation :accessor pen-operation) (font :initarg :font :accessor font) (region :initarg :region :accessor region-of ) (background-color :initarg :background-color :accessor background-of) ) (:menu-bar nil) ;quail-canvas-command-table) ;<- here (:panes (host-pane :application :scroll-bars T :width (width *application-frame*) :height (height *application-frame*) :background (background-of *application-frame*) :foreground (pen-color *application-frame*) :text-style (canvas-font-to-host-font (font *application-frame*)) :display-time nil) ) (:layouts (default host-pane ))) ;;; 05MAR2021 - START defun to replace the :after method of pen-mixin (defun set-color-initial-penproperties (self &rest initargs &key pen-color pen-width pen-operation) (declare (ignore initargs)) (format t "~%Entering set-color-inital-pen&properties") (format t "~%s-c-i-pp input pen-color is ~s " pen-color) (format t "~%s-c-i-pp input pen-width is ~s " pen-width) (format t "~%s-c-i-pp input pen-operation is ~s " pen-operation) (format t "~%s-c-i-pp input self is ~s " self) (format t "~%s-c-i-pp is self a frame ? ~s " (clim:application-frame-p self)) (format t "~%s-c-i-pp does is have a host-pane ? ~s " (clim:get-frame-pane self 'host-pane)) (format t "~%s-c-i-pp is self a pen-mixin ? ~s" (member (find-class 'pen-mixin) (sb-mop:class-direct-superclasses (first (sb-mop:class-direct-superclasses (class-of self)))))) (unless (pen-of self) (setf (slot-value self 'pen) (make-instance 'pen))) (canvas-set-pen self :width pen-width :operation pen-operation :color pen-color) ) #| (defmethod initialize-instance :after ((self pen-mixin) &rest initargs &key pen-color pen-width pen-operation) (declare (ignore initargs)) (sleep 10) ;; 05MAR2021 (format t "~%i-i input pen-color is ~s " pen-color) (format t "~%i-i input pen-width is ~s " pen-width) (format t "~%i-i input pen-operation is ~s " pen-operation) (format t "~%i-i input self is ~s " self) (format t "~%i-i is self a frame ~s , a colored-canvas ~s " (clim:application-frame-p self) (colored-canvas-p self)) (format t "~%i-i does it have a host-pane ~s " (clim:get-frame-pane self 'host-pane)) (unless (pen-of self) (setf (slot-value self 'pen) (make-instance 'pen))) (canvas-set-pen self :width pen-width :operation pen-operation :color pen-color) ) |# ;;; 05MAR2021 - END defun to replace the :after method of pen-mixin ;;; 10MAR2021 - START defun to replace the initialize-instance :after method of font-mixin (defun set-color-initial-font (self &rest initargs &key font) (declare (ignore initargs)) (format t "~%Entering set-inital-font") (format t "~%s-i-f input font is ~s " font) (format t "~%s-i-f is it a canvas-font ~s" (canvas-font-p font)) (format t "~%s-i-f is it a host-font ~s " (eql (type-of font) 'standard-text-style)) (format t "~%s-i-f input self is ~s " self) (format t "~%s-i-f is self a frame ? ~s " (clim:application-frame-p self)) (format t "~%s-i-f does is have a host-pane ? ~s " (clim:get-frame-pane self 'host-pane)) (format t "~%s-i-f is self a font-mixin ? ~s" (member (find-class 'font-mixin) (sb-mop:class-direct-superclasses (first (sb-mop:class-direct-superclasses (class-of self)))))) (if (canvas-font-p font);(canvas-font-p self) (setf (canvas-font self) font) (setf (canvas-font self) (host-font-to-canvas-font font))) ) ;;; 10MAR2021 - END defun to replace the initialize-instance :after method of font-mixin (defun make-color-canvas (&rest canvas-keywords &key left bottom width height ;; (type (device-type)) (canvas-class 'canvas) (title "Color Canvas") (background-color NIL) (pen-color NIL) (pen-width nil) (pen-operation nil) (font *normal-graphics-font*) &allow-other-keys) "Creates and returns a color canvas." (declare (special *normal-graphics-font* *default-canvas-background-color* *default-canvas-pen-color* *white-color* *black-color*) (ignorable canvas-class)) (format t "~%mcc-input pen-color is ~s " pen-color) (format t "~%mcc-input pen-width is ~s " pen-width) (let ((frame (make-application-frame 'color-canvas :pretty-name title :left left :bottom (- (screen-height) bottom) :width width :height height :pen-color pen-color :pen-width pen-width :pen-operation pen-operation :font font :canvas-keywords (list NIL) :color? T :region (make-region left bottom width height) :background-color background-color :&allow-other-keys T ))) (sb-thread::make-thread (lambda () (run-frame-top-level frame))) (sleep 1) ;<<== IMPORTANT .. allows thread to start (?) ;; Set the pen attributes (set-color-initial-penproperties frame :pen-color pen-color :pen-width pen-width :pen-operation pen-operation) ;; Set the font/text-style (set-color-initial-font frame :font font) ;; Now set the colors ;; (canvas-set-background-color frame (or background-color *default-canvas-background-color*)) ;; Finally get the pen back to the correct origin (canvas-move-to frame 0 0) frame)) ;;; gesture so that l-click on pane makes frame *current-canvas* (define-presentation-action do-change-canvas ;(blank-area nil quail-color-canvas :gesture :select) (blank-area nil color-canvas :gesture :select) (object) (with-application-frame (frame) (update-ccqc frame) ))
8,019
Common Lisp
.l
169
40.153846
138
0.592952
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
76fe3c24fc89f5119f0b538e699434b3bdcd55f16610db790c4aa792ac339226
33,549
[ -1 ]
33,551
color-canvas-pc.lsp
rwoldford_Quail/source/window-basics/canvas/color-canvas-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; color-canvas-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1993 ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-color-canvas))) ;;; ======================================================================= ;;; Creating a colour canvas ;;; ======================================================================= (defmethod initialize-instance :after ((self pen-mixin) &rest initargs &key pen-color pen-width pen-operation) (declare (ignore initargs)) (unless (pen-of self) (setf (slot-value self 'pen) (make-instance 'pen))) (canvas-set-pen self :width pen-width :operation pen-operation :color pen-color) ) ;;; 05MAR2021 - END defun to replace the :after method of pen-mixin (defun make-color-canvas (&rest canvas-keywords &key left bottom width height ;; (type (device-type)) (canvas-class 'canvas) (title "Color Canvas") (background-color NIL) (pen-color NIL) (pen-width nil) (pen-operation nil) (font *normal-graphics-font*) &allow-other-keys) "Creates and returns a black and white canvas." (declare (special *normal-graphics-font* *default-canvas-background-color* *default-canvas-pen-color* *white-color* *black-color*)) (unless left (setq left (round (/ (- (screen-width) width) 2)))) (unless bottom (setq bottom (round (/ (- (screen-height) height) 2)))) (when font (setf canvas-keywords (remove :font canvas-keywords)) (setf canvas-keywords (remove font canvas-keywords))) (let* ((top (+ bottom height)) (c (apply #'cg::make-window (gensym "canvas") :device canvas-class :parent (cg::screen cg::*system*) :scrollbars T :exterior (cg::make-box left (- (screen-height) top 25) (+ left width) (- (screen-height) bottom 25)) #| Lines below replaced with the defn of :exterior above :window-exterior-top-left (cg::make-position left (- (screen-height) top 25) ) :visible-box (cg::make-box left (- bottom height ) (+ left width) bottom ) |# :title title :color? T :allow-other-keywords t canvas-keywords)) ) ;; ;; Now set the colors ;; (canvas-set-background-color c (or background-color *default-canvas-background-color*)) (canvas-set-pen c :color (or pen-color *default-canvas-pen-color* (canvas-default-draw-color c)) :width pen-width :operation pen-operation) ;; ;; Now set the fonts ;; (setf (canvas-font c) font) ;; ;; ;; Finally get the pen back to the correct origin ;; (canvas-move-to c 0 0) c))
4,222
Common Lisp
.l
96
30.822917
87
0.442523
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
a57c80460dad52eeaa4463e8cea9a17ca9eef0c772f3499790972834feed1781
33,551
[ -1 ]
33,552
color-canvas-ops-sblx.lsp
rwoldford_Quail/source/window-basics/canvas/color-canvas-ops-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; color-canvas-ops-sblx.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 2021 ;;; ;;;---------------------------------------------------------------------------------- ;;; Collects the forms to operate on color-canvases ;;; the specialiser of canvas needs to exist so this file comes ;;; after color-canvas-sblx.lsp in the asd module for canvas (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(;;size-changed-p canvas-visible-p at-top-p close-canvas hide-canvas show-canvas canvas-width canvas-height canvas-title canvas-set-title which-canvas move-canvas shape-canvas canvas-to-top canvas-at-top canvases ))) ;(eval-when (:compile-toplevel :load-toplevel :execute) ; (export '(*current-canvas* *quail-canvases* revise-ccqc update-ccqc))) #| next 4 definitions are in redisplay/canvas-ops-sblx.lsp (defvar *current-canvas* NIL) (defvar *quail-canvases* '()) (defun update-ccqc (canvas) "set *current-canvas* to be canvas, remove the canvas entry from *q-c,*~ (cons (cons canvas (frame-state canvas)) *q-c*" (setf *current-canvas* canvas) (setf *quail-canvases* (cons (cons canvas :ENABLED) ;(frame-state canvas)) (remove-if #'(lambda (x) (eql (car x) canvas)) *quail-canvases*))) ) (defun revise-ccqc (canvas) "set *current-canvas* to be the first :ENABLED car on *quail-canvases*~ minus the entry for canvas itself [NIL if find-if fails - OK]~ if there is a *current-canvas*, set *quail-canvases* to be (update-ccqc *current-canvas*)~ otherwise exit" (setf *current-canvas* (car (find-if #'(lambda (x) (eql (cdr x) :ENABLED)) (remove-if #'(lambda (y) (eql (car y) canvas)) *quail-canvases*)))) (if *current-canvas* (update-ccqc *current-canvas*) NIL) ) |# #| now in color/bw-canvas-sblx.lsp (define-presentation-action do-change-canvas (blank-area nil quail-color-canvas :gesture :select) (object) (with-application-frame (frame) (update-ccqc frame) )) |# (defmethod enable-frame :after ((self canvas)) "The :before method will have set the frame-state of self to :DISABLED~ so now this part of the call to enable-frame will pop it back up. Then update-ccqc." ;(format t "~%:after on enable-frame called.") (update-ccqc self) ) (defmethod enable-frame :before ((self canvas)) "If self is not :ENABLED, disable-it so that the :after method can pop it back up." ;(format t "~%:before on enable-frame called.") (unless (eql (frame-state self) :ENABLED) (disable-frame self)) ) (defmethod destroy-frame :after ((self canvas)) "First reset the state of canvas on *quail-canvases* to be :DISOWNED - then revise-ccqc" (setf (cdr (find-if #'(lambda (x) (eql (car x) self)) *quail-canvases*)) :DISOWNED) (revise-ccqc self)) (defmethod raise-frame :after ((self canvas)) (cond ((eql self *current-canvas*) NIL) ((not (eql :ENABLED (frame-state self))) NIL) (T (update-ccqc self)) )) (defmethod shrink-frame :after ((self canvas)) "First reset the state of canvas on *quail-canvases* to be :SHRUNK - then revise-ccqc" (setf (cdr (find-if #'(lambda (x) (eql (car x) self)) *quail-canvases*)) :SHRUNK) (revise-ccqc self)) (defmethod move-sheet ((self canvas) (x fixnum) (y fixnum)) ) (defmethod move-sheet ((self canvas) (x fixnum) (y fixnum)) (move-sheet (frame-top-level-sheet self) x y) (update-ccqc self)) (defmethod resize-sheet ((self canvas) (x fixnum) (y fixnum)) ;(format t "~%Entering do-nothing primary on resize-sheet") ) (defmethod resize-sheet ((self canvas) (w fixnum) (h fixnum)) (resize-sheet (frame-top-level-sheet self) w h) (update-ccqc self)) #| (defun size-changed-p (display) ; cbh ;; for a particular kind of display, redefine this (declare (ignore display)) T) |# #| next 4 forms are in redisplay/canvas-ops-sblx.lsp ;;; see canvases below (defun at-top-p (canvas) "Test whether the canvas is the top-most in the display." (and ((canvas-p canvas) (eql canvas (caar *quail-canvases*)) ) )) ; destroy-frame (defun close-canvas (canvas) "Close the canvas if it's open." (clim::destroy-frame canvas)) ;; need to setf state to be :shrunk NOPE just shrink-frame (defun hide-canvas (canvas) "Hides the canvas from display." (clim::shrink-frame canvas)) ;; raise-frame brings it to the top of the list but does not actually show it (defun show-canvas (canvas) "Displays the canvas." (clim::enable-frame canvas) ) |# #| next 3 definitions are in redisplay/canvas-ops-sblx.lsp ;; the outside of canvas (defun exterior-frame-rect (canvas) "Returns the exterior rectangle of canvas ~ in screen coordinates x L -> R, y T -> B." (transform-region (sheet-delta-transformation (frame-top-level-sheet canvas) (graft canvas)) (sheet-region (frame-top-level-sheet canvas)))) (defun canvas-width (canvas) "Returns the display width of the canvas (in pixels)." (rectangle-width (exterior-frame-rect canvas))) ;(- (cg::visible-box-width canvas) (cg::vertical-scrollbar-thickness))) ;;05may06 (defun canvas-height (canvas) "Returns the display height of the canvas (in pixels)." (rectangle-height (exterior-frame-rect canvas))) ;(- (cg::visible-box-height canvas) (cg::horizontal-scrollbar-thickness))) ;;05may06 |# ;;;============================================================ ;;; Canvas properties ;;;============================================================ ;;; assuming to the front means to the top of some list ;;; raise-frame should do #| next 9 definitions are in redisplay/canvas-ops-sblx.lsp (defun canvas-to-top (canvas) "Brings the canvas to the front of all other windows." (clim::raise-frame canvas)) ;;; the value of *application-frame* shoud do - can't use this, only available inside a frame (defun canvas-at-top () "Returns the canvas at the front of all other canvases." (first (canvases))) ;;; don't yet know how to get this ;;; Aha! see clim-spec under frammanager ;;; (frame-manager-frames (frame-manager *quail-menubar-window*)) ;;; returns a list of frames ;;; (eql (car *this*) *application-frame*) ;;; returns T (defun canvases () "Returns a list of all existing canvases." *quail-canvases*) (defun which-canvas (screen-position) "Returns the canvas at the screen-position, if it exists." ;;loop over all windows, find the frontmost one containing position ;; return it if it is a canvas (find-if #'(lambda (w) (clim::region-contains-position-p (clim::sheet-region (clim::frame-top-level-sheet w)) (h-draw::point-x screen-position) (h-draw::point-y screen-position))) (canvases))) (defun canvas-title (canvas) (clim::frame-pretty-name canvas)) ;;; Changed 18 Feb 1998 from (cg::set-stream-title to (setf (cg::stream-title (defsetf canvas-title (canvas) (new-value) `(let ((my-new-value ,new-value)) (setf (clim::frame-pretty-name ,canvas) my-new-value) ) ) (defun canvas-set-title (c title) "Sets the canvas title to be the value of the second argument ~ title must be a string." (setf (clim::frame-pretty-name c) title)) (defun move-canvas (canvas x &optional y) "Reposition the canvas to the position (x y) in screen coordinates. ~ If only one argument is given then it is assumed to be a position." (let ((ftls (frame-top-level-sheet canvas))) (cond ((integerp y) (move-sheet ftls x y) ) (T (move-sheet ftls (h-draw::point-x x) (h-draw::point-y x)) )) )) (defun shape-canvas (canvas width &optional height) "Resize a canvas to have width and height as given. If the optional ~ argument height is not supplied, then it is assumed that the first argument ~ is either a position specifying the width and height as its x and y coordinates, ~ or a region whose width and height specify the corresponding attributes of the canvas." (let ((ftls (frame-top-level-sheet canvas))) (cond (height (resize-sheet ftls width height) ) ((position-p width) (resize-sheet ftls (h-draw::point-x width) (h-draw::point-y width))) (region-p width) (resize-sheet ftls (region-width width) (region-height width)) (T nil) ))) |# ;=================================================== ; canvas-visible-p things ; mcclim does not seem to have facilities for accessing the z-order of its frames ; and all its region-X functions are with region coords rather than screen coords ; hence much of what follows ; gwb august 2021 ;=================================================== #| all definitions are in redisplay/canvas-ops-sblx.lsp (defun canvas-in-screen-coords (canvas &optional (v-kludge 30)) "Returns the clim bounding rectangle of the exterior of canvas ~ in *screen* units. ~ mcclim does not know about the 'title-bar' and so the bounding rectangle ~ returned has v-min too big by its height .. hence v-kludge." (declare (optimize (speed 3))) (let ((basic-region (transform-region (sheet-delta-transformation (frame-top-level-sheet canvas) (graft (frame-top-level-sheet canvas))) (sheet-region (frame-top-level-sheet canvas))))) (list (bounding-rectangle-min-x basic-region) (bounding-rectangle-max-x basic-region) (- (bounding-rectangle-min-y basic-region) v-kludge) (bounding-rectangle-max-y basic-region)))) (defun screen-point-on-canvas (canvas h v) "Determines whether the screen point pt h v is in or on the boundary of canvas" (declare (fixnum h v h-min h-max v-min v-max) (optimize (speed 3))) (let* ((canvas-exterior (canvas-in-screen-coords canvas )) (h-min (first canvas-exterior)) (h-max (second canvas-exterior)) (v-min (third canvas-exterior)) (v-max (fourth canvas-exterior))) (if (and (>= h h-min) (<= h h-max) (>= v v-min) (<= v v-max)) T nil) ) ) (defun range-covered-p (list-of-canvases h-min h-max v-min v-max) (declare (fixnum h-min h-max v-min v-max) (optimize (speed 3))) (let ((h-range (make-list-from-ends h-min h-max)) (v-range (make-list-from-ends v-min v-max))) (if (every #'(lambda (v) (every #'(lambda (h) (some #'(lambda (c) (screen-point-on-canvas c h v)) list-of-canvases)) h-range)) v-range) T NIL ) )) (defun revise-canvas-list (canvas list-of-cons-canvas-and-state) "Returns a new list of just the canvas components which are (1) not [the arg] ~ nor (2) have cdr not equal to :ENABLED" (let ((new-list '())) (setf new-list (mapcar #'(lambda (y) (car y)) (remove-if #'(lambda (x) (or (eql (car x) canvas) (not (eql (cdr x) :ENABLED)))) list-of-cons-canvas-and-state))) new-list)) ;;; ;;; I need to make an integer list including from l-min l0max (defun make-list-from-ends (l-min l-max) "Returns an integer list including from l-max to l-min" (declare (fixnum l-min l-max) (optimize (speed 3))) (let ((result '())) (do ((i l-min (1+ i))) ((> i l-max)) (setf result (cons i result))) result )) (defun canvas-visible-p (canvas) "Determines whether some part of canvas is not covered by any other canvas" (cond ((eql canvas *current-canvas*) T) ((not (eql (frame-state canvas) :ENABLED)) NIL) (T (let* ((screen-canvas (canvas-in-screen-coords canvas)) (ch-min (first screen-canvas)) (ch-max (second screen-canvas)) (cv-min (third screen-canvas)) (cv-max (fourth screen-canvas)) (updated-canvas-list (revise-canvas-list canvas *quail-canvases*))) (not (range-covered-p updated-canvas-list ch-min ch-max cv-min cv-max)))))) ;;; |#
12,438
Common Lisp
.l
289
38.681661
99
0.64438
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ba0d958c7b9aa493020b023a3470dd80e2eca854462faecc871448b00f438acc
33,552
[ -1 ]
33,553
make-canvas.lsp
rwoldford_Quail/source/window-basics/canvas/make-canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; make-canvas.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1993 ;;; J.R. MacPhail 1995 ;;; R.W. Oldford 1994 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-canvas))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; User-controllable margins to leave free at window creation (1995, jrm) ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Let user control margins left free when e.g. the Browser asks for a huge window. ;; (We can't fault the browser for optimism.) ;; (User may want easy access to other X-Windows or Mac programs. Also there exist ;; Mac utilities that react to a click at one of the screen edges.) ;; Four pixels is a good default. We might use defparameter, but a defvar wrapped ;; in a boundp is nicest to the user, maximizing the ease of setting the thing ;; before this code or after it. (User can change it anytime at all.) ;(declare (special *screen-left-margin* *screen-bottom-margin* *screen-right-margin* *screen-left-margin)) ; 06AUG2023 ;(defvar *screen-left-margin* 0) ; 07AUG2023 ;(defvar *screen-top-margin* 0) ; 07AUG2023 ;(defvar *screen-bottom-margin* 0) ; 07AUG2023 ;(defvar *screen-right-margin* 0) ; 07AUG2023 ;(unless (boundp '*screen-top-margin*) (defvar *screen-top-margin* 4 "Top margin to leave when making big window") ; ) ;(unless (boundp '*screen-left-margin*) (defvar *screen-left-margin* 4 "Left margin to leave when making big window") ; ) ;(unless (boundp '*screen-bottom-margin*) (defvar *screen-bottom-margin* 4 "Bottom margin to leave when making big window") ; ) ;(unless (boundp '*screen-right-margin*) (defvar *screen-right-margin* 4 "Right margin to leave when making big window") ; ) ;; Assume a smart screen-height function (e.g. subtracting menubar on MacOS) (defun window-max-height () "Maximum height for a window, including title-bar, scrollbar and so on" (declare (special *screen-top-margin* *screen-bottom-margin*)) (- (screen-height) *screen-top-margin* *screen-bottom-margin*)) (defun window-max-width () "Maximum width for a window, including scrollbar and so on" (declare (special *screen-left-margin* *screen-right-margin*)) (- (screen-width) *screen-left-margin* *screen-right-margin*)) (defun window-min-left () "Minimum left for a window being created, but not to hinder window movement" (declare (special *screen-left-margin*)) *screen-left-margin*) (defun window-min-bottom () "Minimum bottom for a window being created, but not to hinder window movement" (declare (special *screen-bottom-margin*)) *screen-bottom-margin*) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Default screen positions for a canvas (modified 1995, jrm) ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #| 26SEP2023 already defined in canvas/canvas.lsp (defvar *default-canvas-region* (make-region *screen-left-margin* *screen-bottom-margin* 300 300) "Set to a default screen region where the canvas will appear.") ; already defined in canvas/canvas.lsp 09MAR2022 gwb (defun set-up-default-canvas-region (&optional (left *screen-left-margin*) (bottom *screen-bottom-margin*) (width 300) (height 300)) "Sets the default region where a new canvas will appear on the ~ screen." (setf *default-canvas-region* (make-region left bottom width height))) |# ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Canvas functions ;;; #-:sbcl-linux(defun make-canvas (&rest canvas-keywords &key left bottom width height region (color? (color-device-p)) (type (device-type)) (canvas-class 'canvas) (font *normal-graphics-font*) (title "Canvas") background-color pen-color &allow-other-keys) "Creates and returns a canvas. Canvas size is calculated by: ~ first, using left/bottom/width/height if they are given; ~ second, using the bounding box of region if it is a region; ~ third, using *default-canvas-region* if region is NIL; ~ fourth, prompting user to use pointing device to give size." (declare (special *default-canvas-region* *normal-graphics-font*)) (declare (ignore pen-color background-color title font canvas-class)) ;; If left/bottom/width/height not given, try to extract from region. ;; Where all these things are NIL, we quietly use the default. -- jrm (unless (and left bottom width height) (when (null region) (setf region *default-canvas-region*)) (when (region-p region) (setf left (region-left region) bottom (region-bottom region) width (region-width region) height (region-height region)))) (if (and left bottom width height) (apply (if (and color? (color-device-p)) #'make-color-canvas #'make-b&w-canvas) :left (max left (window-min-left)) :bottom (max bottom (window-min-bottom)) :width (min width (window-max-width)) :height (min height (window-max-height)) :type type :allow-other-keys t canvas-keywords) (apply #'prompt-for-canvas canvas-keywords)) ) #+:sbcl-linux(defun make-canvas (&rest canvas-keywords &key left bottom width height region (color? (color-device-p)) (type (device-type)) (canvas-class 'color-canvas) (font *normal-graphics-font*) (title "Canvas") background-color pen-color &allow-other-keys) "Creates and returns a canvas. Canvas size is calculated by: ~ first, using left/bottom/width/height if they are given; ~ second, using the bounding box of region if it is a region; ~ third, using *default-canvas-region* if region is NIL; ~ fourth, prompting user to use pointing device to give size." (declare (special *default-canvas-region* *normal-graphics-font*)) (declare (ignore pen-color background-color title font canvas-class)) ;; If left/bottom/width/height not given, try to extract from region. ;; Where all these things are NIL, we quietly use the default. -- jrm (unless (and left bottom width height) (when (null region) (setf region *default-canvas-region*)) (when (region-p region) (setf left (region-left region) bottom (region-bottom region) width (region-width region) height (region-height region)))) (if (and left bottom width height) (apply (if (and color? (color-device-p)) #'make-color-canvas #'make-b&w-canvas) :left (max left (window-min-left)) :bottom (max bottom (window-min-bottom)) :width (min width (window-max-width)) :height (min height (window-max-height)) :type type :allow-other-keys t canvas-keywords) (apply #'prompt-for-canvas canvas-keywords)) )
8,343
Common Lisp
.l
176
39.198864
119
0.577554
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
472515ce44c8c826b0728ae2925f5c1d307516b333ae435edfdde51531d7d8fc
33,553
[ -1 ]
33,554
cr-bw-canvas-pc.lsp
rwoldford_Quail/source/window-basics/canvas/cr-bw-canvas-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; cr-bw-canvas-pc.lsp ;;; 12MAR02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;FROM .. (defun make-b&w-canvas (&rest canvas-keywords &key left bottom width height ;; (type (device-type)) (canvas-class 'canvas) (title "Canvas") (pen-color *black-shade*) (pen-width nil) (pen-operation nil) (font *normal-graphics-font*) &allow-other-keys) "Creates and returns a black and white canvas." (declare (special *normal-graphics-font* *black-shade* c)) (unless left (setq left (round (/ (- (screen-width) width) 2)))) (unless bottom (setq bottom (round (/ (- (screen-height) height) 2)))) (when font (setf canvas-keywords (remove :font canvas-keywords)) (setf canvas-keywords (remove font canvas-keywords))) (let* ((top (+ bottom height)) (c (apply #'cg::make-window (gensym "canvas") :device 'canvas-class :parent (cg::screen cg::*system*) :scrollbars T :window-exterior-top-left (cg::make-position left (- (screen-height) top 25)) :title title :visible-box (cg::make-box left (- bottom height) (+ left width) bottom) :color? nil :allow-other-keywords t canvas-keywords)) )) ;; ;; Now set the pen ;; ;; (canvas-set-pen c :color pen-color :width pen-width :operation pen-operation) ;; ;; Finally get the pen back to the correct origin ;; ;; (canvas-move-to c 0 0) c) ---------------------------------------------------------------------- FUNCTION-TOO-LONG: Definition way too long! ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like CANVAS-KEYWORDS -- and usually useless. ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like BOTTOM -- and usually useless. ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like LEFT -- and usually useless. ----------------------------------------------------------------------
2,719
Common Lisp
.l
60
32.183333
90
0.423004
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
af18384f61dc06a8cabd17f9967b565a73cd56e0b0d930d80feafdd4807f12bf
33,554
[ -1 ]
33,556
key-event-sblx.lsp
rwoldford_Quail/source/window-basics/canvas/key-event-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; key-event-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; A preliminary version to capture what is ;;; available in aclwin ;;; ;;; G.W.Bennett 2020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(;*backspace-event* *space-event* *tab-event* *linefeed-event* *page-event* ;*return-key-event* *delete-event* *enter-key-event* *escape-key-event* ;*home-key-event* *up-arrow-event* *down-arrow-event* ;*back-arrow-event* *forward-arrow-event* *rubout-event* +backspace-event-event+ +space-event+ +tab-event+ +linefeed-event+ +page-event+ +return-key-event+ +delete-event+ +enter-key-event+ +escape-key-event+ +home-key-event+ +up-arrow-event+ +down-arrow-event+ +back-arrow-event+ +forward-arrow-event+ +rubout-event+ ) )) ;(defmethod cg::character-message ((pane host-pane) buttons data ) ; (declare (ignore buttons)) ; (let ((canvas (cg::parent pane))) ; (wb::handle-key-event canvas data) ; )) ;;; The Semi-standard characters of CL (defconstant +backspace-event+ #\backspace ;*backspace-event* #\backspace 23FEB2022 gwb "Captures the backspace keyboard event") (defconstant +space-event+ #\space ;*space-event* #\space 23FEB2022 gwb "Captures the space keyboard event") (defconstant +tab-event+ #\tab ;*tab-event* #\tab 23FEB2022 gwb "Captures the tab keyboard event") (defconstant +linefeed-event+ #\return ;*linefeed-event* #\Newline ;#\return 23FEB2022 gwb "Captures the linefeed keyboard event") (defconstant +page-event+ #\page ;*page-event* #\page ;cg::vk-pagedown 23FEB2022 gwb "Captures the page keyboard event") (defconstant +return-key-event+ #\Return ;*return-key-event* #\Return ;#\newline 23FEB2022 gwb "Captures the return keyboard event") (defconstant +rubout-event+ #\Rubout ;*rubout-event* #\Rubout 23FEB2022 gwb "Captures the rubout keyboard event") ;;; Some non-standard and hence non-portable characters. (defconstant +delete-event+ #\backspace ;*delete-event* #\backspace 23FEB2022 gwb "Captures the delete keyboard event") (defconstant +enter-key-event+ #\esc ;*enter-key-event* #\esc 23FEB2022 gwb "Captures the enter keyboard event") (defconstant +escape-key-event+ #\Esc ;*escape-key-event* #\Esc 23FEB2022 gwb "Captures the escape key keyboard event") (defconstant +home-key-event+ :home ;*home-key-event* :home 23FEB2022 gwb "Captures the home keyboard event") ;;; The (again non-standard) arrow movement keys. (defconstant +up-arrow-event+ :up ;*up-arrow-event* :up 23FEB2022 gwb "Captures the up arrow keyboard event") (defconstant +down-arrow-event+ :down ;*down-arrow-event* :down 23FEB2022 gwb "Captures the down arrow keyboard event") (defconstant +back-arrow-event+ :left ;*back-arrow-event* :left 23FEB2022 gwb "Captures the back arrow keyboard event") (defconstant +forward-arrow-event+ :right ;*forward-arrow-event* :right 23FEB2022 gwb "Captures the forward arrow keyboard event") ;;; And not some which Unix and Apple may not have ;;; One of the pageup / pagedown may correpsond to page ;;; The rest remain to be checked (defconstant +end-event+ :end ;*end-event* :end 23FEB2022 gwb "Captures the end keyboard event") (defconstant +pageup-event+ :prior ;*pageup-event* :prior 23FEB2022 gwb "Captures the page up keyboard event") (defconstant +pagedown-event+ :next ;*pagedown-event* :next 23FEB2022 gwb "Captures the pagedown keyboard event") (defconstant +insert-event+ :insert ;*insert-event* :insert 23FEB2022 gwb "Captures the insert keyboard event") (defconstant +cancel-event+ #\Can ;*cancel-event* #\Can 23FEB2022 gwb "Captures the cancel keyboard event") ;(defconstant *backtab-event* cg::vk-backtab ; "Captures the backtab keyboard event") #| ;;; (in-package :clim-user) and therefore (in-package :wb) ;;; output from key presses: delete event-type is :KEY-PRESS character associated with k-event is #\Rubout keyboard-event-key-name for k-event is :DELETE home event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :HOME enter event-type is :KEY-PRESS character associated with k-event is #\Return keyboard-event-key-name for k-event is :RETURN escape event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :ESCAPE up-arrow event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :UP down-arrow event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :DOWN back-arrow event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :LEFT forward-arrow event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :RIGHT end event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :END pageup event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :PRIOR pagedown event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :NEXT insert event-type is :KEY-PRESS character associated with k-event is NIL keyboard-event-key-name for k-event is :INSERT cancel NO KEY backtab NO KEY backspace event-type is :KEY-PRESS character associated with k-event is #\Backspace keyboard-event-key-name for k-event is :BACKSPACE space event-type is :KEY-PRESS character associated with k-event is #\ keyboard-event-key-name for k-event is :| | tab event-type is :KEY-PRESS character associated with k-event is #\Tab keyboard-event-key-name for k-event is :TAB linefeed NO KEY page NO KEY return event-type is :KEY-PRESS character associated with k-event is #\Return keyboard-event-key-name for k-event is :RETURN rubout (presumably = delete) event-type is :KEY-PRESS character associated with k-event is #\Rubout keyboard-event-key-name for k-event is :DELETE |#
6,228
Common Lisp
.l
153
38.287582
95
0.733875
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
71d183ea0fe88bd54f565bb2c5feb0c720c27c93fb62aa64abf8a27b396dde64
33,556
[ -1 ]
33,557
bw-canvas-sblx.lsp
rwoldford_Quail/source/window-basics/canvas/bw-canvas-sblx.lsp
;;; This is ~/RESERVE/lc2-Quail/source/window-basics/canvas/new-bw-canvas-sblx.lsp ;;; to try to fix :left and :bottom args ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; bw-canvas-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1993 ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-b&w-canvas))) ;;; Wholesale import of color-canvas-sbxl then modify ;;; ======================================================================= ;;; Creating a black&white canvas ;;; ======================================================================= ;;; Replacement for initialiaze-instance :afrer until that gets fixed gwb 18MAR2021 (defun set-bw-initial-penproperties (self &rest initargs &key pen-color pen-width pen-operation) (declare (ignore initargs)) (format t "~%Entering set-color-inital-pen&properties") (format t "~%s-bw-i-pp input pen-color is ~s " pen-color) (format t "~%s-bw-i-pp input pen-width is ~s " pen-width) (format t "~%s-bw-i-pp input pen-operation is ~s " pen-operation) (format t "~%s-bw-i-pp input self is ~s " self) (format t "~%s-bw-i-pp is self a frame ? ~s " (clim:application-frame-p self)) (format t "~%s-bw-i-pp does is have a host-pane ? ~s " (clim:get-frame-pane self 'host-pane)) (format t "~%s-bw-i-pp is self a pen-mixin ? ~s" (member (find-class 'pen-mixin) (sb-mop:class-direct-superclasses (first (sb-mop:class-direct-superclasses (class-of self)))))) (unless (pen-of self) (setf (slot-value self 'pen) (make-instance 'pen))) (canvas-set-pen self :width pen-width :operation pen-operation :color pen-color) ) ;;; 10MAR2021 - START defun to replace the initialize-instance :after method of font-mixin (defun set-bw-initial-font (self &rest initargs &key font) (declare (ignore initargs)) (format t "~%Entering set-inital-font") (format t "~%s-i-f input font is ~s " font) (format t "~%s-i-f is it a canvas-font ~s" (canvas-font-p font)) (format t "~%s-i-f is it a host-font ~s " (eql (type-of font) 'standard-text-style)) (format t "~%s-i-f input self is ~s " self) (format t "~%s-i-f is self a frame ? ~s " (clim:application-frame-p self)) (format t "~%s-i-f does is have a host-pane ? ~s " (clim:get-frame-pane self 'host-pane)) (format t "~%s-i-f is self a font-mixin ? ~s" (member (find-class 'font-mixin) (sb-mop:class-direct-superclasses (first (sb-mop:class-direct-superclasses (class-of self)))))) (if (canvas-font-p font);(canvas-font-p self) (setf (canvas-font self) font) (setf (canvas-font self) (host-font-to-canvas-font font))) ) ;;; 10MAR2021 - END defun to replace the initialize-instance :after method of font-mixin ;;; a new copy (define-application-frame quail-bw-canvas (canvas) ((left :initarg :left :accessor left) (bottom :initarg :bottom :accessor bottom) (height :initarg :height :accessor height) (width :initarg :width :accessor width) (title :initarg :title :accessor title) ;(color :initarg :color :accessor color) (canvas-keywords :initarg :canvas-keywords :accessor canvas-keywords) (pen-color :initarg :pen-color :accessor pen-color) (pen-width :initarg :pen-width :accessor pen-width) (pen-operation :initarg :pen-operation :accessor pen-operation) (font :initarg :font :accessor font) ) (:menu-bar nil) ;quail-canvas-command-table) ;<- here (:panes (host-pane :application :scroll-bars T :min-width (width *application-frame*) :min-height (height *application-frame*) :background *default-canvas-background-color* :foreground (pen-color *application-frame*) :text-style (canvas-font-to-host-font (font *application-frame*))) ) (:layouts (default host-pane ))) (defun make-b&w-canvas (&rest canvas-keywords &key left bottom width height ;; (type (device-type)) (canvas-class 'canvas) (title "Color Canvas") (background-color NIL) (pen-color NIL) (pen-width nil) (pen-operation nil) (font *normal-graphics-font*) &allow-other-keys) "Creates and returns a color canvas." (declare (special *normal-graphics-font* *default-canvas-background-color* *default-canvas-pen-color* *white-color* *black-color*) (ignorable canvas-class background-color canvas-keywords) ;10MAY2024 ) (format t "~%mcc-input pen-color is ~s " pen-color) (format t "~%mcc-input pen-width is ~s " pen-width) (let ((frame (make-application-frame 'quail-bw-canvas :pretty-name title :left left :bottom (- (screen-height) bottom) :width width :height height :pen-color pen-color :pen-width pen-width :pen-operation pen-operation :canvas-keywords (list NIL) :font font :&allow-other-keys T ))) (sb-thread::make-thread (lambda () (run-frame-top-level frame))) (sleep 1) ;;<<== IMPORTANT .. allows thread to start and panes to be instantiated ;; ;; set inital pen properties (set-bw-initial-penproperties frame :pen-color pen-color :pen-width pen-width :pen-operation pen-operation) ;; Set the font/text-style (set-bw-initial-font frame :font font) ;; Finally get the pen back to the correct origin ;; (canvas-move-to frame 0 0) frame)) ;;; gesture to that l-click on pane makes frame *current-canvas* (define-presentation-action do-change-canvas (blank-area nil quail-bw-canvas :gesture :select) (object) (with-application-frame (frame) (update-ccqc frame) ))
6,574
Common Lisp
.l
142
39.711268
122
0.592616
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
03133aa92a3ed0b22d2427f3d5d3b7a8545a63ffc1755f98bbe2a1fca9a6a302
33,557
[ -1 ]
33,558
cr-make-canvas.lsp
rwoldford_Quail/source/window-basics/canvas/cr-make-canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; cr-make-canvas.lsp ;;; 12MAR02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;FROM .. (defun set-up-default-canvas-region (&optional (left *screen-left-margin*) (bottom *screen-bottom-margin*) (width 300) (height 300)) "Sets the default region where a new canvas will appear on the ~ screen." (setf *default-canvas-region* (make-region left bottom width height))) ---------------------------------------------------------------------- SETS-GLOBALS: GLOBALS!! Don't use global variables, i.e., *DEFAULT-CANVAS-REGION* ---------------------------------------------------------------------- OPTIONALS: Multiple optional arguments get confusing. Use &KEY for SET-UP-DEFAULT-CANVAS-REGION. ---------------------------------------------------------------------- NEEDLESS-SETF: Why do you think you need that SETF on *DEFAULT-CANVAS-REGION*? ---------------------------------------------------------------------- ;;FROM .. (defun make-canvas (&rest canvas-keywords &key left bottom width height region (color? (color-device-p)) (type (device-type)) (canvas-class 'canvas) (font *normal-graphics-font*) (title "Canvas") background-color pen-color &allow-other-keys) "Creates and returns a canvas. Canvas size is calculated by: ~ first, using left/bottom/width/height if they are given; ~ second, using the bounding box of region if it is a region; ~ third, using *default-canvas-region* if region is NIL; ~ fourth, prompting user to use pointing device to give size." (declare (special *default-canvas-region* *normal-graphics-font*)) (declare (ignore pen-color background-color title font canvas-class)) ;; If left/bottom/width/height not given, try to extract from region. ;; Where all these things are NIL, we quietly use the default. -- jrm (unless (and left bottom width height) (when (null region) (setf region *default-canvas-region*)) (when (region-p region) (setf left (region-left region) bottom (region-bottom region) width (region-width region) height (region-height region)))) (if (and left bottom width height) (apply (if (and color? (color-device-p)) #'make-color-canvas #'make-b&w-canvas) :left (max left (window-min-left)) :bottom (max bottom (window-min-bottom)) :width (min width (window-max-width)) :height (min height (window-max-height)) :type type :allow-other-keys t canvas-keywords) (apply #'prompt-for-canvas canvas-keywords)) ) ---------------------------------------------------------------------- FUNCTION-TOO-LONG: Definition way too long! ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like REGION -- and usually useless. ----------------------------------------------------------------------
3,303
Common Lisp
.l
69
38.608696
78
0.505787
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
348468fb274e8adc76dcb98961f3cebd982d459fe99a2dcf7bb6a89cc4b08bf4
33,558
[ -1 ]
33,559
cr-color-canvas-pc.lsp
rwoldford_Quail/source/window-basics/canvas/cr-color-canvas-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; cr-color-canvas-pc.lsp ;;; 12MAR02 ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;FROM .. (defun make-color-canvas (&rest canvas-keywords &key left bottom width height ;; (type (device-type)) (canvas-class 'canvas) (title "Color Canvas") (background-color NIL) (pen-color NIL) (pen-width nil) (pen-operation nil) (font *normal-graphics-font*) &allow-other-keys) "Creates and returns a black and white canvas." (declare (special *normal-graphics-font* *default-canvas-background-color* *default-canvas-pen-color* *white-color* *black-color*)) (unless left (setq left (round (/ (- (screen-width) width) 2)))) (unless bottom (setq bottom (round (/ (- (screen-height) height) 2)))) (when font (setf canvas-keywords (remove :font canvas-keywords)) (setf canvas-keywords (remove font canvas-keywords))) (let* ((top (+ bottom height)) (c (apply #'cg::make-window (gensym "canvas") :device canvas-class :parent (cg::screen cg::*system*) :scrollbars T :exterior (cg::make-box left (- (screen-height) top 25) (+ left width) (- (screen-height) bottom 25)) #| Lines below replaced with the defn of :exterior above :window-exterior-top-left (cg::make-position left (- (screen-height) top 25) ) :visible-box (cg::make-box left (- bottom height ) (+ left width) bottom ) |# :title title :color? T :allow-other-keywords t canvas-keywords)) ) ;; ;; Now set the colors ;; (canvas-set-background-color c (or background-color *default-canvas-background-color*)) (canvas-set-pen c :color (or pen-color *default-canvas-pen-color* (canvas-default-draw-color c)) :width pen-width :operation pen-operation) ;; ;; Now set the fonts ;; (setf (canvas-font c) font) ;; ;; ;; Finally get the pen back to the correct origin ;; (canvas-move-to c 0 0) c)) ---------------------------------------------------------------------- FUNCTION-TOO-LONG: Definition way too long! ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like CANVAS-KEYWORDS -- and usually useless. ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like BOTTOM -- and usually useless. ---------------------------------------------------------------------- SETS-PARAMETERS: It's bad style to reassign input parameters like LEFT -- and usually useless. ----------------------------------------------------------------------
3,481
Common Lisp
.l
82
28.865854
77
0.430003
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5ed5a65473772e0e12eb2ed0935776264b8100f80962a9f83b6929e20484a854
33,559
[ -1 ]
33,560
cr-canvas.lsp
rwoldford_Quail/source/window-basics/canvas/cr-canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; cr-canvas.lsp ;;; 12MAR02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;FROM .. (defun set-up-default-canvas-region (&optional (left 10) (bottom 10) (width 300) (height 300)) "Sets the default region where a new canvas will appear on the ~ screen." (setf *default-canvas-region* (make-region left bottom width height))) ---------------------------------------------------------------------- SETS-GLOBALS: GLOBALS!! Don't use global variables, i.e., *DEFAULT-CANVAS-REGION* ---------------------------------------------------------------------- OPTIONALS: Multiple optional arguments get confusing. Use &KEY for SET-UP-DEFAULT-CANVAS-REGION. ---------------------------------------------------------------------- NEEDLESS-SETF: Why do you think you need that SETF on *DEFAULT-CANVAS-REGION*? ----------------------------------------------------------------------
959
Common Lisp
.l
21
41.238095
74
0.431647
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
94b0cd071ab0a32b337fff17de2279a6abf9a8d1613004012de08d3c89df1d33
33,560
[ -1 ]
33,561
key-event.lsp
rwoldford_Quail/source/window-basics/canvas/key-event.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; key-event.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1996 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(handle-key-event))) (defgeneric handle-key-event (receiver event) (:documentation "Generic function called on the receiver when the keyboard event, ~ event, has occurred. Methods should be defined for particular receivers ~ and events. If receiver does handle the event, for whatever ~ reason, then this function must return NIL. Otherwise it returns ~ non-NIL.") ) (defmethod handle-key-event ((receiver T) (event T)) "Ignores both receiver and event and returns NIL. The default behaviour ~ in that most things just do not handle key-events." (declare (ignorable receiver event)) ;(declare (ignore receiver event)) ; 28JUL2023 NIL) (defmethod handle-key-event ((receiver canvas) (event T)) "For a canvas, the event is handed off to its display." (let ((handled? NIL)) (loop for vp-v in (display-of receiver) do (setf handled? (or handled? (handle-key-event (cdr vp-v) event)))) handled?) ) (defmethod handle-key-event ((receiver list) (event t)) ;(defmethod handle-key-event ((receivers list) (event T)) ; 28JUL2023 "Recursively calls handle-key-event on the elements of the list giving each ~ the opportunity to handle the event." (let ((handled? NIL)) (when receiver ;(when receivers ; 28JUL2023 (loop for r in receiver ;(loop for r in receivers ; 28JUL2023 do (setf handled? (or handled? (handle-key-event r event)))) ) handled?))
2,410
Common Lisp
.l
53
39.339623
126
0.56258
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d816747c487ae4a5e7e28bf9430c87050a791f7e5cc0c5a4afb50b881c71f0fd
33,561
[ -1 ]
33,563
key-event-pc.lsp
rwoldford_Quail/source/window-basics/canvas/key-event-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; key-event-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; A preliminary version to capture what is ;;; available in aclwin ;;; ;;; G.W.Bennett 1997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(;*backspace-event* *tab-event* *linefeed-event* *page-event* ;*return-key-event* *delete-event* *enter-key-event* *escape-key-event* ;*home-key-event* *up-arrow-event* *down-arrow-event* ;*back-arrow-event* *forward-arrow-event* *rubout-event* +backspace-event+ +tab-event+ +linefeed-event+ +page-event+ +return-key-event+ +delete-event+ +enter-key-event+ +escape-key-event+ +home-key-event+ +up-arrow-event+ +down-arrow-event+ +back-arrow-event+ +forward-arrow-event+ +rubout-event+ ) )) (defmethod cg::character-message ((pane host-pane) buttons data ) (declare (ignore buttons)) (let ((canvas (cg::parent pane))) (wb::handle-key-event canvas data) )) ;;; The Semi-standard characters of CL (defconstant +backspace-event+ #\backspace ;*backspace-event* #\backspace 23FEB2022 gwb "Captures the backspace keyboard event") (defconstant +space-event+ #\space ;*space-event* #\space 23FEB2022 gwb "Captures the space keyboard event") (defconstant +tab-event+ #\tab ;*tab-event* #\tab 23FEB2022 gwb "Captures the tab keyboard event") (defconstant +linefeed-event+ #\return ;*linefeed-event* #\return 23FEB2022 gwb "Captures the linefeed keyboard event") (defconstant +page-event+ cg::vk-pagedown ;*page-event* cg::vk-pagedown 23FEB2022 gwb "Captures the page keyboard event") (defconstant +return-event+ #\newline ;*return-key-event* #\newline 23FEB2022 gwb "Captures the return keyboard event") (defconstant +rubout-event+ #\rubout ;*rubout-event* #\rubout 23FEB2022 gwb "Captures the rubout keyboard event") ;;; Some non-standard and hence non-portable characters. (defconstant +delete-event+ #\backspace ;*delete-event* #\backspace 23FEB2022 gwb "Captures the delete keyboard event") (defconstant +enter-key-event+ #\esc ;*enter-key-event* #\esc 23FEB2022 gwb "Captures the enter keyboard event") (defconstant +escape-key-event+ #\esc ;*escape-key-event* #\esc 23FEB2022 gwb "Captures the escape key keyboard event") (defconstant +home-key-event+ cg::vk-home ;*home-key-event* cg::vk-home 23FEB2022 gwb "Captures the home keyboard event") ;;; The (again non-standard) arrow movement keys. (defconstant +up-arrow-event+ cg::vk-up ;*up-arrow-event* cg::vk-up 23FEB2022 gwb "Captures the up arrow keyboard event") (defconstant +down-arrow-event+ cg::vk-down ;*down-arrow-event* cg::vk-down 23FEB2022 gwb "Captures the down arrow keyboard event") (defconstant +back-arrow-event+ cg::vk-left ;*back-arrow-event* cg::vk-left 23FEB2022 gwb "Captures the back arrow keyboard event") (defconstant +forward-arrow-event+ cg::vk-right ;*forward-arrow-event* cg::vk-right 23FEB2022 gwb "Captures the forward arrow keyboard event") ;;; And not some which Unix and Apple may not have ;;; One of the pageup / pagedown may correpsond to page ;;; The rest remain to be checked (defconstant +end-event+ cg::vk-end ;*end-event* cg::vk-end 23FEB2022 gwb "Captures the end keyboard event") (defconstant +pageup-event+ cg::vk-pageup ;*pageup-event* cg::vk-pageup 23FEB2022 gwb "Captures the page up keyboard event") (defconstant +pagedown-event+ cg::vk-pagedown ;*pagedown-event* cg::vk-pagedown 23FEB2022 gwb "Captures the pagedown keyboard event") (defconstant +insert-event+ cg::vk-insert ;*insert-event* cg::vk-insert 23FEB2022 gwb "Captures the insert keyboard event") (defconstant +cancel-event+ cg::vk-cancel ;*cancel-event* cg::vk-cancel 23FEB2022 gwb "Captures the cancel keyboard event") (defconstant +backtab-event+ cg::vk-backtab ;*backtab-event* cg::vk-backtab 23FEB2022 gwb "Captures the backtab keyboard event")
4,042
Common Lisp
.l
73
52.041096
97
0.701496
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d8c05f9b005c5d9c24e4ae42deed92497f2e2d1f1467d599841565d62f3ec18a
33,563
[ -1 ]
33,565
bw-canvas-pc.lsp
rwoldford_Quail/source/window-basics/canvas/bw-canvas-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; bw-canvas-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1993 ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(make-b&w-canvas))) ;;; ======================================================================= ;;; Creating a black and white canvas ;;; ======================================================================= (defun make-b&w-canvas (&rest canvas-keywords &key left bottom width height ;; (type (device-type)) (canvas-class 'canvas) (title "Canvas") (pen-color *black-shade*) (pen-width nil) (pen-operation nil) (font *normal-graphics-font*) &allow-other-keys) (declare (ignore pen-color pen-width pen-operation)) "Creates and returns a black and white canvas." (declare (special *normal-graphics-font* *black-shade*)) (unless left (setq left (round (/ (- (screen-width) width) 2)))) (unless bottom (setq bottom (round (/ (- (screen-height) height) 2)))) (when font (setf canvas-keywords (remove :font canvas-keywords)) (setf canvas-keywords (remove font canvas-keywords))) (let* ((top (+ bottom height)) (c (apply #'cg::make-window (gensym "canvas") :device canvas-class :parent (cg::screen cg::*system*) :scrollbars T :window-exterior-top-left (cg::make-position left (- (screen-height) top 25)) :title title :visible-box (cg::make-box left (- bottom height) (+ left width) bottom) :color? nil :allow-other-keywords t canvas-keywords)) ) ;; ;; Now set the pen ;; ;; (canvas-set-pen c :color pen-color :width pen-width :operation pen-operation) ;; ;; Finally get the pen back to the correct origin ;; ;; (canvas-move-to c 0 0) c))
3,035
Common Lisp
.l
65
34.184615
90
0.423442
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d10af81a80c2b0bedecfde8f01f8431f1662ce03e52e6d17342d079ab6be04b3
33,565
[ -1 ]
33,566
canvas.lsp
rwoldford_Quail/source/window-basics/canvas/canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; canvas.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*default-canvas-region* set-up-default-canvas-region *current-canvas* canvas canvas-p canvas-font))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Default screen positions for a canvas ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar *default-canvas-region* (make-region 10 10 300 300) "Set to a default screen region where the canvas will appear.") (defun set-up-default-canvas-region (&optional (left 10) (bottom 10) (width 300) (height 300)) "Sets the default region where a new canvas will appear on the ~ screen." (setf *default-canvas-region* (make-region left bottom width height))) (defvar *current-canvas* NIL "The identity of the active canvas.") ;;;============================================================ ;;; Canvas - A CLOS Object ;;; ;;; ;;; ... rwo ;;;============================================================ ;;; host-window inherits from clim::standard-application-frame (defclass canvas (color-mixin pen-mixin postscript-canvas canvas-button menu-canvas canvas-redisplay-mixin host-window font-mixin #+:sbcl-linux sheet ) () (:documentation "Canvas is a window on which one can draw.")) (defun canvas-p (canvas) "Returns T if the argument is a canvas, NIL otherwise." (typep canvas 'canvas)) (defun current-canvas-p (canvas) (eq canvas *current-canvas*)) ;;; ;;; SETTING FONTS ;;; (defmethod (setf canvas-font) (new-font (self canvas)) (let ((result (call-next-method))) (with-display-mode self (display-mode-of self) ;; set-canvas-font is just a bogus function so that ;; printer-set-canvas-font and ps-set-canvas-font ;; are used in this macro (set-canvas-font self new-font) ) result)) (defun set-canvas-font (canvas new-font) (declare (ignore canvas new-font)) )
3,180
Common Lisp
.l
84
30.821429
136
0.478204
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
dc20343bac2fd41156ba6486f48c4bcd39d8b35cfd3c057a53c0067a1c67e805
33,566
[ -1 ]
33,568
canvas-to-ps.lsp
rwoldford_Quail/source/window-basics/postscript/canvas-to-ps.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; canvas-to-ps.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Copyright (c) 1991 Statistical Computing Laboratory, University of Waterloo ;;; ;;; ;;; Authors: ;;; R.W. Oldford 1991 - 1992. ;;; ;;; ;;;-------------------------------------------------------------------------------- (in-package :window-basics) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-to-ps))) (defun canvas-to-ps (canvas &key (prompt? T)) "Writes out to files the postscript commands necessary to ~ reproduce the canvas as displayed. ~ (:key ~ (:arg prompt? T If non-NIL, the user is prompted for ~ file and postscript information.))" (let ((old-mode (display-mode-of canvas))) (unwind-protect (progn (when prompt? (when (and (prompt-for-ps-page-properties canvas) (prompt-for-ps-filenames canvas)) (setf (display-mode-of canvas) :postscript) (redisplay canvas) ;; this next line ensures that the concatenate-ps does ;; not redisplay the postscript file, but rather the screen (setf (display-mode-of canvas) old-mode) (concatenate-ps canvas) (delete-header-file canvas) (delete-body-file canvas) ))) (setf (display-mode-of canvas) old-mode) (re-enable-menubars))))
1,630
Common Lisp
.l
40
32.65
84
0.47601
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6d3b66f60e93f5871c3b2f185d558105f00c072faa965344db2c849ef4e83bb5
33,568
[ -1 ]
33,569
ps-prompt.lsp
rwoldford_Quail/source/window-basics/postscript/ps-prompt.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ps-prompt.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; ;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(prompt-for-ps-filenames prompt-for-ps-page-properties ))) (defun prompt-for-ps-filenames (canvas) "Prompt user for postscript file information for the given canvas." (let* ((pi-info (postscript-info-of canvas)) (directory-prompt "Directory:") (directory-default (or (write-directory-of pi-info) "q:tmp;")) (postscript-prompt "Postscript filename (no ext.):") (oldname (postscript-file-of pi-info)) (oldname-length (length oldname)) (postscript-default (if (> oldname-length 3) (cond ((equal (subseq oldname (- oldname-length 3) oldname-length) ".ps") (subseq oldname 0 (- oldname-length 3))) ((equal (subseq oldname (- oldname-length 4) oldname-length) ".eps") (subseq oldname 0 (- oldname-length 4))) (T oldname)) "canvas")) (result NIL) new-info) (setf new-info (collect-input (list (cons directory-prompt directory-default) (cons postscript-prompt postscript-default)))) (setf result new-info) (when new-info (setf (write-directory-of pi-info) (cdr (assoc directory-prompt new-info :test #'string=))) (reset-includes canvas) (let* ((new-name (cdr (assoc postscript-prompt new-info :test #'string=))) (directory (write-directory-of pi-info)) (full-file-name (if (multiple-pages-p pi-info) (concatenate 'string directory new-name ".ps") (concatenate 'string directory new-name ".eps")))) (when (probe-file full-file-name) (if (prompt-t-or-f (format NIL "The file '~a' already exists. Click Retry to choose new name." new-name) :true-text "Overwrite" :false-text "Retry...") (delete-file full-file-name) (setf new-name (cdr (assoc postscript-prompt (prompt-for-ps-filenames canvas) :test #'string=))))) (if (multiple-pages-p pi-info) (setf (postscript-file-of pi-info) (concatenate 'string new-name ".ps")) (setf (postscript-file-of pi-info) (concatenate 'string new-name ".eps"))) (setf (header-file-of pi-info) (concatenate 'string new-name "-header.temp")) (setf (body-file-of pi-info) (concatenate 'string new-name "-body.temp")))) result)) (defun prompt-for-ps-page-properties (canvas) "Prompt user for postscript page information for the given canvas." (let* ((pi-info (postscript-info-of canvas)) (x-origin-prompt "x-origin:") (x-origin-default (if (stringp (ps-x-origin-of pi-info)) (format NIL (ps-x-origin-of pi-info)) (format NIL "~a" (ps-x-origin-of pi-info)))) (y-origin-prompt "y-origin:") (y-origin-default (if (stringp (ps-y-origin-of pi-info)) (format NIL (ps-y-origin-of pi-info)) (format NIL "~a" (ps-y-origin-of pi-info)))) (x-scale-prompt "x-scale:") (x-scale-default (format NIL "~a" (ps-x-scale-of pi-info))) (y-scale-prompt "y-scale:") (y-scale-default (format NIL "~a" (ps-y-scale-of pi-info))) (horizontal-margin-prompt "postscript horizontal margin (1/72 inches):") (horizontal-margin-default (format NIL "~a" (ps-horizontal-margin-of pi-info))) (vertical-margin-prompt "postscript vertical margin (in 1/72 inches):") (vertical-margin-default (format NIL "~a" (ps-vertical-margin-of pi-info))) (result NIL) new-info ) (flet ((test-val-for-num (read-val) (if (and (symbolp read-val) (not (boundp read-val))) :wrong (progn (setf read-val (eval read-val)) (if (not (numberp read-val)) :wrong read-val)))) ;(test-val-for-boole (read-val) ; 28JUL2023 ; (if (and (symbolp read-val) ; (not (boundp read-val))) ; :wrong ; (if (eval read-val) ; T ; NIL))) ; 28JUL2023 ) (setf new-info (collect-input (list (cons x-origin-prompt x-origin-default) (cons y-origin-prompt y-origin-default) (cons x-scale-prompt x-scale-default) (cons y-scale-prompt y-scale-default) (cons horizontal-margin-prompt horizontal-margin-default) (cons vertical-margin-prompt vertical-margin-default) ) :prompt-text "Postscript output page properties." )) (setf result new-info) (when new-info (let* ((ans-x (cdr (assoc x-origin-prompt new-info :test #'string=))) (ans-y (cdr (assoc y-origin-prompt new-info :test #'string=))) (center-x (equal ans-x "CENTER")) (center-y (equal ans-y "CENTER"))) (when center-x (rplacd (assoc x-origin-prompt new-info) (format NIL "~a" (round (/ (- *ps-paper-width* (* 2 (read-from-string (cdr (assoc horizontal-margin-prompt new-info :test #'string=)))) (* (ps-width-of canvas) (read-from-string (cdr (assoc x-scale-prompt new-info :test #'string=))))) 2)))) (setf (center-horizontal-p pi-info) T)) (when center-y (rplacd (assoc y-origin-prompt new-info) (format NIL "~a" (round (/ (- *ps-paper-height* (* 2 (read-from-string (cdr (assoc vertical-margin-prompt new-info :test #'string=)))) (* (ps-height-of canvas) (read-from-string (cdr (assoc y-scale-prompt new-info :test #'string=))))) 2)))) (setf (center-vertical-p pi-info) T))) (setf new-info (loop for pair in new-info collect (let ((read-val (read-from-string (cdr pair)))) (cons (car pair) (do ((ans (test-val-for-num read-val) (test-val-for-num (read-from-string (prompt-user :prompt-string (concatenate 'string (car pair) " MUST BE A NUMBER") :result-type 'string))))) ;; from :type 16JAN2021 ((not (eq ans :wrong)) ans)))))) (setf (ps-x-origin-of pi-info) (cdr (assoc x-origin-prompt new-info :test #'string=))) (setf (ps-y-origin-of pi-info) (cdr (assoc y-origin-prompt new-info :test #'string=))) (setf (ps-x-scale-of pi-info) (cdr (assoc x-scale-prompt new-info :test #'string=))) (setf (ps-y-scale-of pi-info) (cdr (assoc y-scale-prompt new-info :test #'string=))) (setf (ps-horizontal-margin-of pi-info) (cdr (assoc horizontal-margin-prompt new-info :test #'string=))) (setf (ps-vertical-margin-of pi-info) (cdr (assoc vertical-margin-prompt new-info :test #'string=))) (if (is-multiple-pages? canvas) (setf (multiple-pages-p pi-info) T) (setf (multiple-pages-p pi-info) NIL)) )) result)) (defun is-multiple-pages? (canvas) "If either the scaled x-width is larger than the page width, or the scaled y-height is larger than the page height, then return T else return NIL." (let* ((pi-info (postscript-info-of canvas)) (width (canvas-width canvas)) (height (canvas-height canvas)) (x-origin (ps-x-origin-of pi-info)) (y-origin (ps-y-origin-of pi-info)) (x-scale (ps-x-scale-of pi-info)) (y-scale (ps-y-scale-of pi-info)) (x-margin (ps-horizontal-margin-of pi-info)) (y-margin (ps-vertical-margin-of pi-info))) (if (or (> (+ x-origin (* x-scale width)) (- *ps-paper-width* (* 2 x-margin))) (> (+ y-origin (* y-scale height)) (- *ps-paper-height* (* 2 y-margin)))) T NIL)))
9,613
Common Lisp
.l
197
35.233503
149
0.501169
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
70466f9ca1c3ee1f275430f733fcdac9914354a99601009ba65b84a350287838
33,569
[ -1 ]
33,570
ps-draw.lsp
rwoldford_Quail/source/window-basics/postscript/ps-draw.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ps-draw.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :window-basics) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defun ps-canvas-set-background-color (canvas color) "This function sets the postscript canvas background.~ NOTE: This function should only be called at the beginning of a canvas~ definition, for it clears the entire canvas while setting the background." (write-ps canvas b (canvas-to-ps-red canvas (red-of color)) (canvas-to-ps-green canvas (green-of color)) (canvas-to-ps-blue canvas (blue-of color)))) (defun ps-set-canvas-x (canvas x) "This function sets the x coordinate of the pen on the postscript~ canvas while maintaining the current y coordinate of the pen." (write-ps canvas x (canvas-to-ps-x canvas x))) (defun ps-set-canvas-y (canvas y) "This function sets the y coordinate of the pen on the postscript~ canvas while maintaining the current x coordinate of the pen." (write-ps canvas y (canvas-to-ps-y canvas y))) (defun ps-canvas-draw-to (canvas x y) "This function draws a line from the current point to (x,y) on the~ postscript canvas. NOTE: The current point MUST be set for this~ function to work correctly." (write-ps canvas t (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y))) (defun ps-canvas-unstroked-draw-to (canvas x y) "This function draws a line from the current point to (x,y) on the~ postscript canvas. NOTE: The current point MUST be set for this~ function to work correctly." (write-ps canvas u (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y))) (defun ps-canvas-clear (canvas &key (canvas-left 0) (canvas-bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas))) "This function clears a rectangular area of the~ postscript canvas bounded by (x1,y1) and (x2,y2)" (write-ps canvas c (canvas-to-ps-x canvas canvas-left) (canvas-to-ps-y canvas canvas-bottom) (canvas-to-ps-x canvas (+ canvas-left width)) (canvas-to-ps-y canvas (+ canvas-bottom height)) (canvas-to-ps-red canvas (red-of (canvas-background-color canvas))) (canvas-to-ps-green canvas (green-of (canvas-background-color canvas))) (canvas-to-ps-blue canvas (blue-of (canvas-background-color canvas))))) (defun ps-canvas-invert (canvas left right bottom top) "This function 'inverts' a rectangular area of the~ postscript canvas bounded by (x1,y1) and (x2,y2)." (write-ps canvas i (canvas-to-ps-x canvas left) (canvas-to-ps-y canvas bottom) (canvas-to-ps-x canvas right) (canvas-to-ps-y canvas top))) (defun ps-canvas-draw-circle (canvas x y radius) "This function mimics the canvas-draw-circle, calling~ ps_canvas_draw_ellipse with both x and y radius arguments~ being the same." (let ((scale (min (ps-x-scale-of canvas) (ps-y-scale-of canvas)))) (write-ps canvas e (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y) (round (* scale radius)) (round (* scale radius))))) (defun ps-canvas-draw-filled-circle (canvas x y radius) "This function is almost the same as ps-canvas-draw-circle~ save that the circle drawn is then filled." ;(declare (ignore operation) ; (ignore width) ; (ignore color)) (let ((scale (min (ps-x-scale-of canvas) (ps-y-scale-of canvas)))) (write-ps canvas fe (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y) (round (* scale radius)) (round (* scale radius))))) ;(defun ps-canvas-draw-polygon (canvas list-of-points) ; "This function draws a polygon on the postscript canvas" ; (declare (ignore operation) ; (ignore width) ; (ignore color)) ; (ps-canvas-move-to canvas ; (canvas-to-ps-x canvas (car (first list-of-points))) ; (canvas-to-ps-y canvas (cdr (first list-of-points)))) ; (dolist (point (cdr list-of-points)) ; (ps-canvas-unstroked-draw-to canvas ; (canvas-to-ps-x canvas (car point)) ; (canvas-to-ps-y canvas (cdr point)))) ; (write-ps canvas closepath) ; (write-ps canvas stroke)) ;;; ;;; updated by Catherine Hurley Nov 1/1996 ;;; (defun ps-canvas-draw-polygon (canvas list-of-points) "This function draws a polygon on the postscript canvas" ;(declare (ignore operation) ; (ignore width) ; (ignore color)) (ps-canvas-move-to canvas (car (first list-of-points)) (cdr (first list-of-points))) (dolist (point (cdr list-of-points)) (ps-canvas-unstroked-draw-to canvas (car point) (cdr point))) (ps-canvas-unstroked-draw-to canvas (car (first list-of-points)) (cdr (first list-of-points))) (write-ps canvas closepath) (write-ps canvas stroke)) ;; ;; a utility function. this should probably be somewhere else, like a wb utility file. cw. ;; (defun flatten-pointlist (alist) (cond ((null alist) nil) ((null (cdr alist)) (list (car (first alist)) (cdr (first alist)))) (T (append (list (car (first alist)) (cdr (first alist))) (flatten-pointlist (cdr alist)))))) ;(defun ps-canvas-draw-filled-polygon (canvas list-of-points) ; "This function draws a filled polygon on the postscript canvas" ; (declare (ignore operation) ; (ignore width) ; (ignore color)) ; (write-ps canvas ; fp ; (append (flatten-pointlist list-of-points) ; (list (length list-of-points))))) ;;; ;;; updated by Catherine Hurley Nov 1/1996 ;;; (defun ps-canvas-draw-filled-polygon (canvas list-of-points) "This function draws a filled polygon on the postscript canvas" ;(declare (ignore operation) ; (ignore width) ; (ignore color)) (setq list-of-points (mapcar #'(lambda(p) (cons (canvas-to-ps-x canvas (car p)) (canvas-to-ps-y canvas (cdr p)))) list-of-points)) (write-ps canvas fp (append (flatten-pointlist list-of-points) (list (length list-of-points))))) (defun ps-canvas-draw-inside-square (canvas x y width) "This function draws a square which is drawn one pixel inside the~ region bounded by (x,y) and (x+width,y+width)" (let* ((scale (min (ps-x-scale-of canvas) (ps-y-scale-of canvas))) (new-width (round (* scale width)))) (write-ps canvas r (canvas-to-ps-x canvas (1+ x)) (canvas-to-ps-y canvas (1+ y)) (+ (canvas-to-ps-x canvas (1- x)) new-width) (+ (canvas-to-ps-y canvas (1- y)) new-width)))) (defun ps-canvas-draw-square (canvas x y width) "This function draws an unfilled square on the postscript canvas." (let* ((scale (min (ps-x-scale-of canvas) (ps-y-scale-of canvas))) (new-width (round (* scale width)))) (write-ps canvas r (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y) (+ (canvas-to-ps-x canvas x) new-width) (+ (canvas-to-ps-y canvas y) new-width)))) (defun ps-canvas-draw-filled-square (canvas x y width) "This function draws a filled square on the postscript canvas." (let* ((scale (min (ps-x-scale-of canvas) (ps-y-scale-of canvas))) (new-width (round (* scale width)))) (write-ps canvas fr (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y) (+ (canvas-to-ps-x canvas x) new-width) (+ (canvas-to-ps-y canvas y) new-width)))) (defun ps-canvas-draw-inside-rectangle (canvas x1 x2 y1 y2) "This function draws a rectangle which is drawn one pixel inside the~ region bounded by (x1,y1) and (x2,y2)" (ps-canvas-draw-rectangle canvas (1+ x1) (1- x2) (1+ y1) (1- y2))) (defun ps-canvas-draw-rectangle (canvas x1 x2 y1 y2) "This function draws an unfilled rectangle on the postscript canvas." (write-ps canvas r (canvas-to-ps-x canvas x1) (canvas-to-ps-y canvas y1) (canvas-to-ps-x canvas x2) (canvas-to-ps-y canvas y2))) (defun ps-canvas-draw-filled-rectangle (canvas x1 x2 y1 y2) "This function draws a filled rectangle on the postscript canvas." (write-ps canvas fr (canvas-to-ps-x canvas x1) (canvas-to-ps-y canvas y1) (canvas-to-ps-x canvas x2) (canvas-to-ps-y canvas y2))) (defun ps-canvas-move-to (canvas x y) "This function moves the pen to (x,y) on the postscript canvas" (write-ps canvas moveto (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y))) (defun ps-canvas-draw-line (canvas x1 y1 x2 y2) "This function draws a line from (x1,y1) to (x2,y2) on the postscript canvas" (write-ps canvas l (canvas-to-ps-x canvas x1) (canvas-to-ps-y canvas y1) (canvas-to-ps-x canvas x2) (canvas-to-ps-y canvas y2) )) (defun ps-canvas-draw-filled-arc (canvas start-angle arc-angle x y xradius yradius) "This function draws a filled arc centred at coordinates x y ~ of radius xradius in the x direction and yradius in the y direction ~ from start-angle degrees to an additional arc-angle degrees." ;(declare (ignore operation) ; (ignore width) ; (ignore color)) (write-ps canvas fa (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y) (canvas-to-ps-x canvas xradius) (canvas-to-ps-y canvas yradius) start-angle arc-angle)) (defun ps-canvas-draw-arc (canvas start-angle arc-angle x y xradius yradius) "This function draws an arc centred at coordinates x y ~ of radius xradius in the x direction and yradius in the y direction ~ from start-angle degrees to an additional arc-angle degrees." ;(declare (ignore operation) ; (ignore width) ; (ignore color)) (write-ps canvas a (canvas-to-ps-x canvas x) (canvas-to-ps-y canvas y) (canvas-to-ps-x canvas xradius) (canvas-to-ps-y canvas yradius) start-angle arc-angle))
11,929
Common Lisp
.l
268
35.421642
102
0.568744
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f942142637268843c8222dda82858adc1c87424652c376822de5ec972697e2b1
33,570
[ -1 ]
33,571
ps-font-sblx.lsp
rwoldford_Quail/source/window-basics/postscript/ps-font-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ps-font-sblx.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;; ;;;---------------------------------------------------------------------------------- ;;; This is a direct copy of ps-font-clx.lsp, as -pc and -mcl seem to be (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*canvas-to-ps-font-name*))) (defun get-ps-font-name (canvas canvas-font) "Returns the PostScript font name corresponding to the canvas-font." (declare (special *canvas-to-ps-font-name*)) (when (and (member :outline (canvas-font-style canvas-font)) (not (command-included-p canvas "Outline Font Generation Procedures"))) (toggle-includes canvas "Outline Font Generation Procedures") (read-write (include-file-of "Outline Font Generation Procedures") (header-file-of canvas))) (flet ((sort-style-list (s-l) (sort (copy-list s-l) #'(lambda (x y) (< (position x (canvas-font-styles)) (position y (canvas-font-styles))))))) (let ((result (assoc canvas-font *canvas-to-ps-font-name* :test #'(lambda (cf key) (and (string-equal (canvas-font-name cf) (canvas-font-name key)) (equal (sort-style-list (canvas-font-style cf)) (sort-style-list (canvas-font-style key)))))))) (if result (cdr result) "Ugly")))) (defun ps-set-canvas-font (canvas font) (with-open-file (ofile (body-full-pathname canvas) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~%/~a findfont ~a scalefont setfont~%" (get-ps-font-name canvas font) (* 0.5 (canvas-font-size font) (+ (ps-x-scale-of canvas) (ps-y-scale-of canvas)))))) (defvar *canvas-to-ps-font-name* (list (cons (canvas-make-font :name "Helvetica" :style :plain) "Helvetica") (cons (canvas-make-font :name "Helvetica" :style :bold) "Helvetica-Bold") (cons (canvas-make-font :name "Helvetica" :style :italic) "Helvetica-Oblique") (cons (canvas-make-font :name "Helvetica" :style (list :bold :italic)) "Helvetica-BoldOblique") (cons (canvas-make-font :name "Helvetica" :style :outline) "Helvetica /Helvetica-Outline MakeOutlinePlainFont~ /Helvetica-Outline") (cons (canvas-make-font :name "Helvetica" :style (list :bold :outline)) "Helvetica-Bold /Helvetica-Bold-Outline MakeOutlinePlainFont~ /Helvetica-Bold-Outline") (cons (canvas-make-font :name "Helvetica" :style (list :italic :outline)) "Helvetica-Oblique /Helvetica-Oblique-Outline MakeOutlinePlainFont~ /Helvetica-Oblique-Outline") (cons (canvas-make-font :name "Helvetica" :style (list :bold :italic :outline)) "Helvetica-BoldOblique /Helvetica-BoldOblique-Outline~ MakeOutlinePlainFont~ /Helvetica-BoldOblique-Outline") (cons (canvas-make-font :name "Avant Garde" :style :plain) "AvantGarde-Book") (cons (canvas-make-font :name "Avant Garde" :style :italic) "AvantGarde-BookOblique") (cons (canvas-make-font :name "Avant Garde" :style :bold) "AvantGarde-Demi") (cons (canvas-make-font :name "Avant Garde" :style (list :bold :italic)) "AvantGarde-DemiOblique") (cons (canvas-make-font :name "Avant Garde" :style :outline) "AvantGarde-Book /AvantGarde-Book-Outline MakeOutlinePlainFont~ /AvantGarde-Book-Outline") (cons (canvas-make-font :name "Avant Garde" :style (list :bold :outline)) "AvantGarde-Demi /AvantGarde-Demi-Outline MakeOutlinePlainFont~ /AvantGarde-Demi-Outline") (cons (canvas-make-font :name "Avant Garde" :style (list :italic :outline)) "AvantGarde-BookOblique /AvantGarde-BookOblique-Outline MakeOutlinePlainFont~ /AvantGarde-BookOblique-Outline") (cons (canvas-make-font :name "Avant Garde" :style (list :bold :italic :outline)) "AvantGarde-DemiOblique /AvantGarde-DemiOblique-Outline~ MakeOutlinePlainFont~ /AvantGarde-DemiOblique-Outline") (cons (canvas-make-font :name "Bookman" :style :plain) "Bookman-Light") (cons (canvas-make-font :name "Bookman" :style :italic) "Bookman-LightItalic") (cons (canvas-make-font :name "Bookman" :style :bold) "Bookman-Demi") (cons (canvas-make-font :name "Bookman" :style (list :bold :italic)) "Bookman-DemiItalic") (cons (canvas-make-font :name "Bookman" :style :outline) "Bookman-Light /Bookman-Light-Outline MakeOutlinePlainFont~ /Bookman-Light-Outline") (cons (canvas-make-font :name "Bookman" :style (list :bold :outline)) "Bookman-Demi /Bookman-Demi-Outline MakeOutlinePlainFont~ /Bookman-Demi-Outline") (cons (canvas-make-font :name "Bookman" :style (list :italic :outline)) "Bookman-LightItalic /Bookman-LightItalic-Outline MakeOutlinePlainFont~ /Bookman-LightItalic-Outline") (cons (canvas-make-font :name "Bookman" :style (list :bold :italic :outline)) "Bookman-DemiItalic /Bookman-DemiItalic-Outline~ MakeOutlinePlainFont~ /Bookman-DemiItalic-Outline") (cons (canvas-make-font :name "Courier" :style :plain) "Courier") (cons (canvas-make-font :name "Courier" :style :italic) "Courier-Oblique") (cons (canvas-make-font :name "Courier" :style :bold) "Courier-Bold") (cons (canvas-make-font :name "Courier" :style (list :bold :italic)) "Courier-BoldOblique") (cons (canvas-make-font :name "Courier" :style :outline) "Courier /Courier-Outline MakeOutlinePlainFont~ /Courier-Outline") (cons (canvas-make-font :name "Courier" :style (list :bold :outline)) "Courier-Bold /Courier-Bold-Outline MakeOutlinePlainFont~ /Courier-Bold-Outline") (cons (canvas-make-font :name "Courier" :style (list :italic :outline)) "Courier-Oblique /Courier-Oblique-Outline MakeOutlinePlainFont~ /Courier-Oblique-Outline") (cons (canvas-make-font :name "Courier" :style (list :bold :italic :outline)) "Courier-BoldOblique /Courier-BoldOblique-Outline~ MakeOutlinePlainFont~ /Courier-BoldOblique-Outline") (cons (canvas-make-font :name "Palatino" :style :plain) "Palatino-Roman") (cons (canvas-make-font :name "Palatino" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "Palatino" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "Palatino" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "Palatino" :style :outline) "Palatino-Roman /Palatino-Roman-Outline MakeOutlinePlainFont~ /Palatino-Roman-Outline") (cons (canvas-make-font :name "Palatino" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "Palatino" :style (list :italic :outline)) "Palatino-Italic-Outline /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "Palatino" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Times" :style :plain) "Times-Roman") (cons (canvas-make-font :name "Times" :style :italic) "Times-Italic") (cons (canvas-make-font :name "Times" :style :bold) "Times-Bold") (cons (canvas-make-font :name "Times" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "Times" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "Times" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "Times" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "Times" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") (cons (canvas-make-font :name "Symbol" :style :plain) "Symbol") (cons (canvas-make-font :name "Symbol" :style :italic) "Symbol") (cons (canvas-make-font :name "Symbol" :style :bold) "Symbol") (cons (canvas-make-font :name "Symbol" :style (list :bold :italic)) "Symbol") (cons (canvas-make-font :name "Symbol" :style :outline) "Symbol /Symbol-Outline MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Symbol" :style (list :bold :outline)) "Symbol /Symbol-Outline MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Symbol" :style (list :italic :outline)) "Symbol /Symbol-Outline MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Symbol" :style (list :bold :italic :outline)) "Symbol /Symbol-Outline~ MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style :plain) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style :italic) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style :bold) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :bold :italic)) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style :outline) "Zapf-Dingbats /Zapf-Dingbats-Outline MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :bold :outline)) "Zapf-Dingbats /Zapf-Dingbats-Outline MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :italic :outline)) "Zapf-Dingbats /Zapf-Dingbats-Outline MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :bold :italic :outline)) "Zapf-Dingbats /Zapf-Dingbats-Outline~ MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style :plain) "NewCenturySchlbk-Roman") (cons (canvas-make-font :name "New Century Schlbk" :style :italic) "NewCenturySchlbk-Italic") (cons (canvas-make-font :name "New Century Schlbk" :style :bold) "NewCenturySchlbk-Bold") (cons (canvas-make-font :name "New Century Schlbk" :style (list :bold :italic)) "NewCenturySchlbk-BoldItalic") (cons (canvas-make-font :name "New Century Schlbk" :style :outline) "NewCenturySchlbk-Roman /NewCenturySchlbk-Roman-Outline MakeOutlinePlainFont~ /NewCenturySchlbk-Roman-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style (list :bold :outline)) "NewCenturySchlbk-Bold /NewCenturySchlbk-Bold-Outline MakeOutlinePlainFont~ /NewCenturySchlbk-Bold-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style (list :italic :outline)) "NewCenturySchlbk-Italic /NewCenturySchlbk-Italic-Outline MakeOutlinePlainFont~ /NewCenturySchlbk-Italic-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style (list :bold :italic :outline)) "NewCenturySchlbk-BoldItalic /NewCenturySchlbk-BoldItalic-Outline~ MakeOutlinePlainFont~ /NewCenturySchlbk-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond Bold" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond Bold" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond Bold" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond Bold" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond Italic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond Italic" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond Italic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond Italic" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond Semibold" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond Semibold" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond Semibold" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style :plain) "Palatino-Bold") (cons (canvas-make-font :name "B Garamond Bold" :style :italic) "Palatino-BoldItalic") (cons (canvas-make-font :name "B Garamond Bold" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "B Garamond Bold" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "B Garamond Bold" :style :outline) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style (list :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :plain) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :italic) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :bold) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :outline) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :bold :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style :plain) "Palatino-Italic") (cons (canvas-make-font :name "I Garamond LightItalic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "I Garamond LightItalic" :style :bold) "Palatino-BoldItalic") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "I Garamond LightItalic" :style :outline) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :bold :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Garamond" :style :plain) "Palatino") (cons (canvas-make-font :name "Garamond" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "Garamond" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "Garamond" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "Garamond" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "Garamond" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "Garamond" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "Garamond" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style :plain) "Palatino") (cons (canvas-make-font :name "Zapf Chancery" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "Zapf Chancery" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "Zapf Chancery" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "Zapf Chancery" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Merrion Square" :style :plain) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style :italic) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style :bold) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style (list :bold :italic)) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style :outline) "Ugly /Ugly-Outline MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Merrion Square" :style (list :bold :outline)) "Ugly /Ugly-Outline MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Merrion Square" :style (list :italic :outline)) "Ugly /Ugly-Outline MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Merrion Square" :style (list :bold :italic :outline)) "Ugly /Ugly-Outline~ MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Chicago" :style :plain) "Times-Roman") (cons (canvas-make-font :name "Chicago" :style :italic) "Times-Italic") (cons (canvas-make-font :name "Chicago" :style :bold) "Times-Bold") (cons (canvas-make-font :name "Chicago" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "Chicago" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "Chicago" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "Chicago" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "Chicago" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") (cons (canvas-make-font :name "Geneva" :style :plain) "AvantGarde") (cons (canvas-make-font :name "Geneva" :style :italic) "AvantGarde-Oblique") (cons (canvas-make-font :name "Geneva" :style :bold) "AvantGarde-Demi") (cons (canvas-make-font :name "Geneva" :style (list :bold :italic)) "AvantGarde-DemiOblique") (cons (canvas-make-font :name "Geneva" :style :outline) "AvantGarde /AvantGarde-Outline MakeOutlinePlainFont~ /AvantGarde-Outline") (cons (canvas-make-font :name "Geneva" :style (list :bold :outline)) "AvantGarde-Demi /AvantGarde-Demi-Outline MakeOutlinePlainFont~ /AvantGarde-Demi-Outline") (cons (canvas-make-font :name "Geneva" :style (list :italic :outline)) "AvantGarde-Oblique /AvantGarde-Oblique-Outline MakeOutlinePlainFont~ /AvantGarde-Oblique-Outline") (cons (canvas-make-font :name "Geneva" :style (list :bold :italic :outline)) "AvantGarde-DemiOblique /AvantGarde-DemiOblique-Outline~ MakeOutlinePlainFont~ /AvantGarde-DemiOblique-Outline") (cons (canvas-make-font :name "Monaco" :style :plain) "Times-Roman") (cons (canvas-make-font :name "Monaco" :style :italic) "Times-Italic") (cons (canvas-make-font :name "Monaco" :style :bold) "Times-Bold") (cons (canvas-make-font :name "Monaco" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "Monaco" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "Monaco" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "Monaco" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "Monaco" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style :plain) "Helvetica") (cons (canvas-make-font :name "N Helvetica Narrow" :style :italic) "Helvetica-Oblique") (cons (canvas-make-font :name "N Helvetica Narrow" :style :bold) "Helvetica-Bold") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :bold :italic)) "Helvetica-BoldOblique") (cons (canvas-make-font :name "N Helvetica Narrow" :style :outline) "Helvetica /Helvetica-Outline MakeOutlinePlainFont~ /Helvetica-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :bold :outline)) "Helvetica-Bold /Helvetica-Bold-Outline MakeOutlinePlainFont~ /Helvetica-Bold-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :italic :outline)) "Helvetica-Oblique /Helvetica-Oblique-Outline MakeOutlinePlainFont~ /Helvetica-Oblique-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :bold :italic :outline)) "Helvetica-BoldOblique /Helvetica-BoldOblique-Outline~ MakeOutlinePlainFont~ /Helvetica-BoldOblique-Outline") (cons (canvas-make-font :name "New York" :style :plain) "Times-Roman") (cons (canvas-make-font :name "New York" :style :italic) "Times-Italic") (cons (canvas-make-font :name "New York" :style :bold) "Times-Bold") (cons (canvas-make-font :name "New York" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "New York" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "New York" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "New York" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "New York" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") ) "This variable maps the standard Macintosh fonts to the~ standard Postscript fonts." )
40,776
Common Lisp
.l
820
32.863415
93
0.521143
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
60f650c17661089314a4e799cb3e4e569fefa4d9fcedb08752ec22e68b7857c3
33,571
[ -1 ]
33,573
old-ps-file.lsp
rwoldford_Quail/source/window-basics/postscript/old-ps-file.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ps-file.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;; ;;; The following functions actually perform the writes to the various postscript files which ;;; are generated by the postscript draw functions. ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(read-write concatenate-ps))) (defun read-write (input output) "Reads from input file and appends on output file." (with-open-file (ifile input :direction :input :if-does-not-exist :error) (with-open-file (ofile output :direction :output :if-exists :append :if-does-not-exist :create) (loop with line = (read-line ifile NIL NIL) while line do (write-line line ofile) (setf line (read-line ifile NIL NIL)))))) (defun ps-setup (canvas) "This function sets up the color, background, line width, and font for the postscript canvas." (toggle-includes canvas "Defaults") (read-write (include-file-of "defaults") (header-full-pathname canvas)) (with-open-file (ofile (header-full-pathname canvas) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~%/canvas_horizontal_margin ~a def~%/canvas_vertical_margin ~a def~%" (ps-horizontal-margin-of canvas) (ps-vertical-margin-of canvas))) (with-open-file (ofile (body-full-pathname canvas) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~% ~A ~A ~A b" (canvas-to-ps-red canvas (red-of (canvas-background-color canvas))) (canvas-to-ps-green canvas (green-of (canvas-background-color canvas))) (canvas-to-ps-blue canvas (blue-of (canvas-background-color canvas)))) (format ofile "~%/~a findfont ~a scalefont setfont~%" (get-ps-font-name canvas (canvas-font canvas)) (* (canvas-font-size (canvas-font canvas)) (floor (/ (+ (ps-x-scale-of canvas) (ps-y-scale-of canvas)) 2))))) (ps-set-pen-width canvas (pen-width-of canvas)) (ps-set-pen-color canvas (pen-color-of canvas)) ) (defmacro write-ps (canvas command-name &rest args) "This macro generates the postscript command for a given canvas command, ensures that the~ correct function definitions have been included, and writes the command to the postscript~ body file." `(let* ((my-args (list ,@args)) (format-string "~&~8T") (file-name (body-full-pathname ,canvas)) (header-file (header-full-pathname ,canvas)) (command-string (string-downcase (string (quote ,command-name))))) (unless (defaults-included-p ,canvas) (ps-setup ,canvas)) (loop for a in my-args do (setf format-string (concatenate 'string format-string " ~a")) finally (setf format-string (concatenate 'string format-string " " command-string))) (if (streamp file-name) (apply #'format file-name format-string my-args) (with-open-file (ofile file-name :direction :output :if-exists :append :if-does-not-exist :create) (if (include-command-p ,canvas command-string) (unless (command-included-p ,canvas command-string) (toggle-includes ,canvas command-string) (read-write (include-file-of command-string) header-file))) (apply #'format ofile format-string my-args))))) (defun toggle-includes (canvas command-name) "This function toggles the 'included' attribute of each postscript command as its definition~ is included in the postscript header. This ensures that each command definition gets added~ only once to the postscript header." (let ((toggle-pair (assoc command-name (included-of canvas) :test #'string-equal))) (if toggle-pair (if (not (cdr toggle-pair)) (setf (cdr toggle-pair) T)) (quail-error "~s not found in the include list." command-name)))) (defvar *include-list* (list (cons "e" NIL) (cons "fe" NIL) (cons "r" NIL) (cons "a" NIL) (cons "fa " NIL) (cons "t" NIL) (cons "l" NIL) (cons "c" NIL) (cons "i" NIL) ;; (cons "redraw" NIL) (cons "x" NIL) (cons "y" NIL) (cons "vshow" NIL) (cons "Outline Font Generation Procedures" NIL) (cons "Defaults" NIL)) "This variable contains the list of commands which have command definitions in the~ include files. It also contains the status of these includable commands. 'T'~ indicates that the command definition has been included and 'NIL' indicates that~ the command definition has not been added to the postscript header file.") (defun postscript-include (filename) "This function adds the correct full pathname to the names of the include files so that~ the functions which use the names of the include files will be MCL independent." (concatenate 'string (mk::fullpath-postscript) filename)) (defun include-file-of (ps-name) "This function returns the correct include file path and name for the postscript command~ given in the command line." (cond ((string-equal ps-name "defaults") (postscript-include "defaults.ps")) ((string-equal ps-name "e") (postscript-include "ellipse.ps")) ((string-equal ps-name "fe") (postscript-include "fellipse.ps")) ((string-equal ps-name "a") (postscript-include "arc.ps")) ((string-equal ps-name "fa") (postscript-include "farc.ps")) ((string-equal ps-name "r") (postscript-include "rect.ps")) ((string-equal ps-name "t") (postscript-include "drawto.ps")) ((string-equal ps-name "l") (postscript-include "drawline.ps")) ((string-equal ps-name "c") (postscript-include "frect.ps")) ((string-equal ps-name "i") (postscript-include "invert.ps")) ((string-equal ps-name "x") (postscript-include "canvasx.ps")) ((string-equal ps-name "y") (postscript-include "canvasy.ps")) ((string-equal ps-name "vshow") (postscript-include "vshow.ps")) ((string-equal ps-name "Outline Font Generation Procedures") (postscript-include "ofont.ps")))) (defun defaults-included-p (canvas) "This function checks to see if the defaults section of the header file has been included.~ It returns 'T' if the defaults have been included, and 'NIL' otherwise." (cdr (assoc "defaults" (included-of canvas) :test #'string-equal))) (defun command-included-p (canvas command-name) "This function checks to see if a given command definition has been included in the postscript~ header file. It returns 'T' if the command has been included, and 'NIL' otherwise." (cdr (assoc command-name (included-of canvas) :test #'string-equal))) (defun include-command-p (canvas command-name) "This function determines whether or not the given command name is an includable command.~ It returns 'T' if the command is includable, and 'NIL' if not." (assoc command-name (included-of canvas) :test #'string-equal)) (defun concatenate-ps (canvas) "Concatenates the header and body postscript files of a postscript canvas ~ together producing a single file that can be sent to a postscript ~ printer." (let* ((file-name (body-full-pathname canvas)) (header-file (header-full-pathname canvas)) (postscript-file (postscript-file-full-pathname canvas)) (xpixels (ps-width-of canvas)) (ypixels (ps-height-of canvas)) (line-max (max-procedure-lines-of canvas))) (cond ((and (< (+ xpixels (* 2 (ps-horizontal-margin-of canvas))) 612) (< (+ ypixels (* 2 (ps-vertical-margin-of canvas))) 792)) (with-open-file (hfile header-file :direction :output :if-does-not-exist :create :if-exists :append) (format hfile "~%ps_set_page_boundaries~%") (format hfile "~%canvas_horizontal_margin canvas_vertical_margin translate~%") (format hfile "~% 612 canvas_horizontal_margin 2 mul sub 1 add ~a sub 2 idiv~ ~% 792 canvas_vertical_margin 2 mul sub 1 add ~a sub 2 idiv~ ~% translate" xpixels ypixels)) (with-open-file (filen file-name :direction :output :if-does-not-exist :create :if-exists :append) (format filen "~%showpage")) (read-write header-file postscript-file) (read-write file-name postscript-file)) (T (cond ((large-canvas-p canvas) (with-open-file (filen file-name :direction :output :if-does-not-exist :create :if-exists :append) (format filen "~%showpage")) (with-open-file (hfile header-file :direction :output :if-does-not-exist :create :if-exists :append) (format hfile "~%ps_set_page_boundaries~%") (format hfile "~%canvas_horizontal_margin canvas_vertical_margin translate~%") ) (concatenate-large-canvas canvas xpixels ypixels)) (T (read-write header-file postscript-file) (with-open-file (pfile postscript-file :direction :output :if-does-not-exist :create :if-exists :append) (let ((ps-name-list NIL) (ps-big-name-list NIL)) (with-open-file (ifile file-name :direction :input) (loop with line = (read-line ifile NIL NIL) with count = 0 with ps-name while line do (when (zerop count) (setf ps-name (string (gensym "c_"))) (format pfile "/~a{~%ps_draw_dict begin~%" ps-name)) (write-line line pfile) (incf count) (setf line (read-line ifile NIL NIL)) (when (>= count line-max) (setf count 0) (format pfile "~%end~%}def~%") (push ps-name ps-name-list) ) (when (>= (length ps-name-list) line-max) (setf ps-name (string (gensym "c_"))) (format pfile "/~a{~%ps_draw_dict begin~%" ps-name) (loop for psn in (reverse ps-name-list) do (format pfile "~&~10T~a" psn)) (format pfile "~%end~%}def~%") (setf ps-name-list NIL) (push ps-name ps-big-name-list)) (when (>= (length ps-big-name-list) line-max) (setf ps-name (string (gensym "c_"))) (format pfile "/~a{~%ps_draw_dict begin~%" ps-name) (loop for psn in (reverse ps-big-name-list) do (format pfile "~&~10T~a" psn)) (format pfile "~%end~%}def~%") (setf ps-big-name-list (list ps-name))) finally ;; tidy up (progn (when (< count line-max) (format pfile "~%end~%}def~%") (push ps-name ps-name-list)) (when ps-name-list (setf ps-name (string (gensym "c_"))) (format pfile "/~a{~%ps_draw_dict begin~%" ps-name) (loop for psn in (reverse ps-name-list) do (format pfile "~&~10T~a" psn)) (format pfile "~%end~%}def~%") (setf ps-name-list NIL) (push ps-name ps-big-name-list)) (when ps-big-name-list (setf ps-name (string (gensym "c_"))) (format pfile "/~a{~%ps_draw_dict begin~%gsave~%" ps-name) (loop for psn in (reverse ps-big-name-list) do (format pfile "~&~10T~a" psn)) (format pfile "~%grestore~%end~%}def~%") (setf ps-big-name-list (list ps-name))) (format pfile "~%{~a} ~A ~A redraw" (first ps-big-name-list) xpixels ypixels) ) ) ;; end loop )))))))) ) (defun concatenate-large-canvas (canvas xpixels ypixels) "This function is used to generate multiple postscript page files for large multiple-page~ canvases." (let* ((abspage 1) (pagefilen) (centering) (page-translate) (canvas-horizontal (- 612 (* 2 (ps-horizontal-margin-of canvas)))) (canvas-vertical (- 792 (* 2 (ps-vertical-margin-of canvas)))) (xpages (compute-ps-x-pages canvas xpixels)) (ypages (compute-ps-y-pages canvas ypixels)) (xcentering (truncate (- (* canvas-horizontal xpages) (ps-width-of canvas)) 2)) (ycentering (truncate (- (* canvas-vertical ypages) (ps-height-of canvas)) 2))) (setf centering (format nil "~a ~a translate~%" xcentering ycentering)) (dotimes (xpage xpages) (dotimes (ypage ypages) (setf pagefilen (format nil "~a~a.ps" (ps-page-full-prefix canvas) abspage)) (setf page-translate (format nil "~a ~a translate" (- (* canvas-horizontal xpage)) (- (* canvas-vertical ypage)))) (with-open-file (pagefile pagefilen :direction :output :if-exists :supersede :if-does-not-exist :create) (format pagefile "%% Postscript Canvas: ~a~%%% Page: ~a~%" (postscript-file-full-pathname canvas) abspage) (format pagefile centering) (format pagefile page-translate)) (incf abspage))))) (defun compute-ps-x-pages (canvas xpixels) "This function computes the number of pages which a large canvas requires in the x direction." (ceiling xpixels (- 612 (* 2 (ps-horizontal-margin-of canvas) )))) (defun compute-ps-y-pages (canvas ypixels) "This function computes the number of pages which a large canvas requires in the y direction." (ceiling ypixels (- 792 (* 2 (ps-vertical-margin-of canvas) )))) (defgeneric concatenate-page (canvas-or-header page &optional body ps-file page-prefix) (:documentation "This function is intended to generate workable postscript files for each~ page of a large canvas. It accepts the following command lines: concatenate-page canvas page concatenate-page postscript-info page concatenate-page header-file body-file postscript-file postscript-page-prefix.")) (defmethod concatenate-page ((canvas postscript-canvas) page &optional body ps-file page-prefix) (declare (ignore body ps-file page-prefix)) (let ((pagefilen (format nil "~a~a.ps" (ps-page-full-prefix canvas) page))) (read-write (header-full-pathname canvas) (postscript-file-full-pathname canvas)) (read-write pagefilen (postscript-file-full-pathname canvas)) (read-write (body-full-pathname canvas) (postscript-file-full-pathname canvas)) )) (defmethod concatenate-page ((info postscript-info) page &optional body ps-file page-prefix) (declare (ignore body ps-file page-prefix)) (let ((pagefilen (format nil "~a~a.ps" (ps-page-full-prefix info) page))) (read-write (header-full-pathname info) (postscript-file-full-pathname info)) (read-write pagefilen (postscript-file-full-pathname info)) (read-write (body-full-pathname info) (postscript-file-full-pathname info)) ) ) (defmethod concatenate-page ((header string) page &optional body ps-file page-prefix) (let ((pagefilen (format nil "~a~a.ps" page-prefix page))) (read-write header ps-file) (read-write pagefilen ps-file) (read-write body ps-file)) ) (defun ps-set-pen-width (canvas width) "This function sets the line width on the postscript canvas." (let ((width (canvas-to-ps-pen-width canvas width))) (write-ps canvas setlinewidth width))) (defun ps-set-pen-color (canvas color) "This function sets the RGB color on the postscript canvas." (let ((red (canvas-to-ps-red canvas (red-of color))) (green (canvas-to-ps-green canvas (green-of color))) (blue (canvas-to-ps-blue canvas (blue-of color)))) (write-ps canvas setrgbcolor red green blue)))
18,526
Common Lisp
.l
354
39.19209
98
0.559312
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0b52512e506de1676519ae81a7c3f87a48ab860a55798d604b69cbdcd5a1a82d
33,573
[ -1 ]
33,574
postscript-canvas.lsp
rwoldford_Quail/source/window-basics/postscript/postscript-canvas.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; postscript-canvas.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :window-basics) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(postscript-info-of))) (defparameter *ps-paper-width* 612 "Device independence parameter. Currently set to 8.5x11 paper only! Width=612/72" ) (defparameter *ps-paper-height* 792 "Device independence parameter. Currently set to 8.5x11 paper only! Height=792/72" ) (defparameter *include-list* (list (cons "e" NIL) (cons "fe" NIL) (cons "r" NIL) (cons "fp" NIL) (cons "a" NIL) (cons "fa" NIL) (cons "t" NIL) (cons "l" NIL) (cons "c" NIL) (cons "i" NIL) ;; (cons "redraw" NIL) (cons "x" NIL) (cons "y" NIL) (cons "vshow" NIL) (cons "Outline Font Generation Procedures" NIL) (cons "Defaults" NIL)) "This variable contains the list of commands which have command definitions in the~ include files. It also contains the status of these includable commands. 'T'~ indicates that the command definition has been included and 'NIL' indicates that~ the command definition has not been added to the postscript header file." ) (defclass postscript-info () ((directory :initform NIL :accessor write-directory-of :initarg :directory :documentation "This slot contains the directory to which the ~ postscript files will be written upon creation.") (body-file :initform NIL :accessor body-file-of :initarg :file-name :documentation "This slot contains the name of the file which ~ contains the postscript function calls required ~ to recreate the canvas on a postscript page.") (header-file :initform NIL :accessor header-file-of :initarg :header-file :documentation "This slot contains the name of the file which ~ contains the postscript function definitions ~ needed to redisplay the canvas on a postscript ~ page.") (postscript-file :initform NIL :accessor postscript-file-of :initarg :postscript-file :documentation "This slot contains the name of the file ~ which describes the canvas to a postscript ~ device.") (included :initform (copy-tree *include-list*) :accessor included-of :documentation "This slot contains a list of includable functions ~ and whether or not each has been included in the ~ header file.") (ps-x-origin :initform "CENTER" :accessor ps-x-origin-of :documentation "This slot allows the user to explicitly set a new ~ x origin for the postscript page. Everything will ~ be drawn with respect to the new x origin.") (ps-x-scale :initform 1.0 :accessor ps-x-scale-of :documentation "This slot allows the user to explicitly set a new x ~ scale factor for the conversion from screen canvas ~ to postscript canvas.") (ps-y-origin :initform "CENTER" :accessor ps-y-origin-of :documentation "This slot allows the user to explicitly set a new ~ y origin for the postscript page. Everything will ~ be drawn with respect to the new y origin.") (ps-y-scale :initform 1.0 :accessor ps-y-scale-of :documentation "This slot allows the user to explicitly set a new y ~ scale factor for the conversion from screen canvas ~ to postscript canvas.") (ps-horizontal-margin :initform 18 :accessor ps-horizontal-margin-of :documentation "This slot contains the number which ~ corresponds to how much space (in 1/72 ~ inch) is to be left blank at each ~ horizontal edge of the page.") (ps-vertical-margin :initform 9 :accessor ps-vertical-margin-of :documentation "This slot contains the number which ~ corresponds to how much space (in 1/72 ~ inch) is to be left blank at each ~ vertical edge of the page.") (ps-width :initform NIL :accessor ps-width-of :documentation "This slot allows the user to explicitly set a new ~ width for the postscript canvas regardless of its ~ actual width.") (ps-height :initform NIL :accessor ps-height-of :documentation "This slot allows the user to explicitly set a new ~ height for the postscript canvas regardless of its ~ actual height.") (max-procedure-lines :initform 30 :accessor max-procedure-lines-of :documentation "This slot determines the maximum number of lines ~ which are allowed to be written into each procedure ~ of a multiple page postscript file. It is strongly ~ recommended that the user not alter this number ~ unless they wish to spend considerable amounts of ~ time adjusting it for their particular laser printer.") (multiple-pages :initform NIL :accessor multiple-pages-p :documentation "This slot is used to set whether there are multiple ~ Postscript pages (not files) in the Postscript output.") (center-vertical :initform NIL :accessor center-vertical-p :documentation "This slot indicates whether to centre the Postscript~ output vertically") (center-horizontal :initform NIL :accessor center-horizontal-p :documentation "This slot indicates whether to centre the Postscript~ output horizontally.") ) (:documentation "A class containing the file and page property information ~ required to correctly generate a postscript page description ~ for a canvas.")) (defclass postscript-canvas (display-mode-mixin) ((postscript-info :initform (make-instance 'postscript-info) :accessor postscript-info-of :initarg :postscript-info))) (defmethod max-procedure-lines-of ((self postscript-canvas)) (max-procedure-lines-of (postscript-info-of self))) (defmethod (setf max-procedure-lines-of) (new-value (self postscript-canvas)) (setf (max-procedure-lines-of (postscript-info-of self)) new-value)) (defmethod ps-width-of ((self postscript-canvas)) (if (ps-width-of (postscript-info-of self)) (ps-width-of (postscript-info-of self)) (ps-canvas-width self))) (defmethod (setf ps-width-of) (new-value (self postscript-canvas)) (setf (ps-width-of (postscript-info-of self)) new-value)) (defmethod ps-height-of ((self postscript-canvas)) (if (ps-height-of (postscript-info-of self)) (ps-height-of (postscript-info-of self)) (ps-canvas-height self))) (defmethod (setf ps-height-of) (new-value (self postscript-canvas)) (setf (ps-height-of (postscript-info-of self)) new-value)) (defmethod write-directory-of ((self postscript-canvas)) (write-directory-of (postscript-info-of self))) (defmethod (setf write-directory-of) (new-value (self postscript-canvas)) (setf (write-directory-of (postscript-info-of self)) new-value)) (defmethod body-file-of ((self postscript-canvas)) (body-file-of (postscript-info-of self))) (defmethod (setf body-file-of) (new-value (self postscript-canvas)) (setf (body-file-of (postscript-info-of self)) new-value)) (defun body-full-pathname (postscript-info) "Returns the full pathname of the body file of postscript-info." (prepend-write-directory postscript-info (body-file-of postscript-info))) (defmethod header-file-of ((self postscript-canvas)) (header-file-of (postscript-info-of self))) (defmethod (setf header-file-of) (new-value (self postscript-canvas)) (setf (header-file-of (postscript-info-of self)) new-value)) (defun prepend-write-directory (postscript-info file-name) "Prepends the write-directory name of postscript-info to the file-name. ~ Postscript-info can be a canvas." (concatenate 'string (write-directory-of postscript-info) file-name)) (defun header-full-pathname (postscript-info) "Returns the full pathname of the header file of postscript-info." (prepend-write-directory postscript-info (header-file-of postscript-info))) (defmethod postscript-file-of ((self postscript-canvas)) (postscript-file-of (postscript-info-of self))) (defmethod (setf postscript-file-of) (new-value (self postscript-canvas)) (setf (postscript-file-of (postscript-info-of self)) new-value)) (defun postscript-file-full-pathname (postscript-info) "Returns the full pathname of the self-contained ~ postscript-file of postscript-info." (prepend-write-directory postscript-info (postscript-file-of postscript-info))) (defmethod included-of ((self postscript-canvas)) (included-of (postscript-info-of self))) (defmethod (setf included-of) (new-value (self postscript-canvas)) (setf (included-of (postscript-info-of self)) new-value)) (defmethod ps-x-origin-of ((self postscript-canvas)) (ps-x-origin-of (postscript-info-of self))) (defmethod (setf ps-x-origin-of) (new-value (self postscript-canvas)) (setf (ps-x-origin-of (postscript-info-of self)) new-value)) (defmethod ps-y-origin-of ((self postscript-canvas)) (ps-y-origin-of (postscript-info-of self))) (defmethod (setf ps-y-origin-of) (new-value (self postscript-canvas)) (setf (ps-y-origin-of (postscript-info-of self)) new-value)) (defmethod ps-x-scale-of ((self postscript-canvas)) (ps-x-scale-of (postscript-info-of self))) (defmethod (setf ps-x-scale-of) (new-value (self postscript-canvas)) (setf (ps-x-scale-of (postscript-info-of self)) new-value)) (defmethod ps-y-scale-of ((self postscript-canvas)) (ps-y-scale-of (postscript-info-of self))) (defmethod (setf ps-y-scale-of) (new-value (self postscript-canvas)) (setf (ps-y-scale-of (postscript-info-of self)) new-value)) (defmethod ps-horizontal-margin-of ((self postscript-canvas)) (ps-horizontal-margin-of (postscript-info-of self))) (defmethod (setf ps-horizontal-margin-of) (new-value (self postscript-canvas)) (setf (ps-horizontal-margin-of (postscript-info-of self)) new-value)) (defmethod ps-vertical-margin-of ((self postscript-canvas)) (ps-vertical-margin-of (postscript-info-of self))) (defmethod (setf ps-vertical-margin-of) (new-value (self postscript-canvas)) (setf (ps-vertical-margin-of (postscript-info-of self)) new-value)) (defmethod postscript-canvas-p ((pc postscript-canvas)) (eq (display-mode-of pc) :postscript)) (defun canvas-to-ps-x (canvas x) (round (+ (ps-x-origin-of canvas) (* (ps-x-scale-of canvas) x)))) (defun canvas-to-ps-y (canvas y) (round (+ (ps-y-origin-of canvas) (* (ps-y-scale-of canvas) y)))) (defun ps-canvas-height (canvas) (ceiling (* (ps-y-scale-of canvas) (canvas-height canvas)))) (defun ps-canvas-width (canvas) (ceiling (* (ps-x-scale-of canvas) (canvas-width canvas)))) (defmethod multiple-pages-p ((self postscript-canvas)) (multiple-pages-p (postscript-info-of self))) (defmethod (setf multiple-pages-p) (new-value (self postscript-canvas)) (setf (multiple-pages-p (postscript-info-of self)) new-value)) (defmethod center-vertical-p ((self postscript-canvas)) (center-vertical-p (postscript-info-of self))) (defmethod (setf center-vertical-p) (new-value (self postscript-canvas)) (setf (center-vertical-p (postscript-info-of self)) new-value)) (defmethod center-horizontal-p ((self postscript-canvas)) (center-horizontal-p (postscript-info-of self))) (defmethod (setf center-horizontal-p) (new-value (self postscript-canvas)) (setf (center-horizontal-p (postscript-info-of self)) new-value)) (defun canvas-to-ps-pen-width (canvas width) (declare (ignore canvas)) (1- width)) (defun canvas-to-ps-red (canvas red) (declare (ignore canvas) ;;(special *max-color-saturation*) ) (float (/ (truncate (* red 100000)) 100000)) ;;(float (/ (truncate (* (float (/ red *max-color-saturation*)) 100000)) 100000)) ) (defun canvas-to-ps-green (canvas green) (declare (ignore canvas) ;;(special *max-color-saturation*) ) (float (/ (truncate (* green 100000)) 100000)) ;;(float (/ (truncate (* (float (/ green *max-color-saturation*)) 100000)) 100000)) ) (defun canvas-to-ps-blue (canvas blue) (declare (ignore canvas) ;;(special *max-color-saturation*) ) (float (/ (truncate (* blue 100000)) 100000)) ;;(float (/ (truncate (* (float (/ blue *max-color-saturation*)) 100000)) 100000)) )
14,414
Common Lisp
.l
262
44.69084
88
0.620424
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d5b7439236ad6f08c9bea06e763c88a8552963283d4357aac58f7d1e67821748
33,574
[ -1 ]
33,575
ps-strings.lsp
rwoldford_Quail/source/window-basics/postscript/ps-strings.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ps-strings.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '())) (defun ps-canvas-princ-character (canvas character) "This function types a character in the current font and color~ onto the postscript canvas" (write-ps canvas show (concatenate 'string "(" (string character) ")"))) (defun ps-canvas-princ-string (canvas str) "This function types a string in the current font and color~ onto the postscript canvas" (write-ps canvas show (concatenate 'string "(" (string str) ")"))) (defun ps-canvas-draw-vertical-str (canvas xpos ypos string &key bottom clip?) "This function types a vertical string in the current font and color~ onto the postscript canvas" (declare (ignore xpos)) (let ((str) (char-ht (canvas-font-height (canvas-font canvas)))) (if clip? (loop for i from 0 below (length string) for char = (elt string i) while (> ypos bottom) do (setf str (concatenate 'string str (string char)))) (setf str string)) (write-ps canvas vshow char-ht (concatenate 'string "(" str ")"))))
2,024
Common Lisp
.l
50
34.02
86
0.518424
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
42910dba76b290e16dc8ecaab2d3a74579b4908ba0c201878145aea3ceb0f286
33,575
[ -1 ]
33,578
ps-font-pc.lsp
rwoldford_Quail/source/window-basics/postscript/ps-font-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ps-font-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1992 ;;; R.W. Oldford 1992 ;;; ;;;---------------------------------------------------------------------------------- ;;; LOG April 25, 1996 ;;; This is a direct copy of ps-fonts-clx.lsp for use with the APC version ;;; of Quail (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*canvas-to-ps-font-name*))) (defun get-ps-font-name (canvas canvas-font) "Returns the PostScript font name corresponding to the canvas-font." (declare (special *canvas-to-ps-font-name*)) (when (and (member :outline (canvas-font-style canvas-font)) (not (command-included-p "Outline Font Generation Procedures"))) (toggle-includes canvas "Outline Font Generation Procedures") (read-write (include-file-of "Outline Font Generation Procedures") (header-file-of canvas))) (flet ((sort-style-list (s-l) (sort (copy-list s-l) #'(lambda (x y) (< (position x (canvas-font-styles)) (position y (canvas-font-styles))))))) (let ((result (assoc canvas-font *canvas-to-ps-font-name* :test #'(lambda (cf key) (and (equal (canvas-font-name cf) (canvas-font-name key)) (equal (sort-style-list (canvas-font-style cf)) (sort-style-list (canvas-font-style key)))))))) (if result (cdr result) "Ugly")))) (defun ps-set-canvas-font (canvas font) (with-open-file (ofile (body-full-pathname canvas) :direction :output :if-exists :append :if-does-not-exist :create) (format ofile "~%/~a findfont ~a scalefont setfont~%" (get-ps-font-name canvas font) (* 0.5 (canvas-font-size font) (+ (ps-x-scale-of canvas) (ps-y-scale-of canvas)))))) (defvar *canvas-to-ps-font-name* (list (cons (canvas-make-font :name "Helvetica" :style :plain) "Helvetica") (cons (canvas-make-font :name "Helvetica" :style :bold) "Helvetica-Bold") (cons (canvas-make-font :name "Helvetica" :style :italic) "Helvetica-Oblique") (cons (canvas-make-font :name "Helvetica" :style (list :bold :italic)) "Helvetica-BoldOblique") (cons (canvas-make-font :name "Helvetica" :style :outline) "Helvetica /Helvetica-Outline MakeOutlinePlainFont~ /Helvetica-Outline") (cons (canvas-make-font :name "Helvetica" :style (list :bold :outline)) "Helvetica-Bold /Helvetica-Bold-Outline MakeOutlinePlainFont~ /Helvetica-Bold-Outline") (cons (canvas-make-font :name "Helvetica" :style (list :italic :outline)) "Helvetica-Oblique /Helvetica-Oblique-Outline MakeOutlinePlainFont~ /Helvetica-Oblique-Outline") (cons (canvas-make-font :name "Helvetica" :style (list :bold :italic :outline)) "Helvetica-BoldOblique /Helvetica-BoldOblique-Outline~ MakeOutlinePlainFont~ /Helvetica-BoldOblique-Outline") (cons (canvas-make-font :name "Avant Garde" :style :plain) "AvantGarde-Book") (cons (canvas-make-font :name "Avant Garde" :style :italic) "AvantGarde-BookOblique") (cons (canvas-make-font :name "Avant Garde" :style :bold) "AvantGarde-Demi") (cons (canvas-make-font :name "Avant Garde" :style (list :bold :italic)) "AvantGarde-DemiOblique") (cons (canvas-make-font :name "Avant Garde" :style :outline) "AvantGarde-Book /AvantGarde-Book-Outline MakeOutlinePlainFont~ /AvantGarde-Book-Outline") (cons (canvas-make-font :name "Avant Garde" :style (list :bold :outline)) "AvantGarde-Demi /AvantGarde-Demi-Outline MakeOutlinePlainFont~ /AvantGarde-Demi-Outline") (cons (canvas-make-font :name "Avant Garde" :style (list :italic :outline)) "AvantGarde-BookOblique /AvantGarde-BookOblique-Outline MakeOutlinePlainFont~ /AvantGarde-BookOblique-Outline") (cons (canvas-make-font :name "Avant Garde" :style (list :bold :italic :outline)) "AvantGarde-DemiOblique /AvantGarde-DemiOblique-Outline~ MakeOutlinePlainFont~ /AvantGarde-DemiOblique-Outline") (cons (canvas-make-font :name "Bookman" :style :plain) "Bookman-Light") (cons (canvas-make-font :name "Bookman" :style :italic) "Bookman-LightItalic") (cons (canvas-make-font :name "Bookman" :style :bold) "Bookman-Demi") (cons (canvas-make-font :name "Bookman" :style (list :bold :italic)) "Bookman-DemiItalic") (cons (canvas-make-font :name "Bookman" :style :outline) "Bookman-Light /Bookman-Light-Outline MakeOutlinePlainFont~ /Bookman-Light-Outline") (cons (canvas-make-font :name "Bookman" :style (list :bold :outline)) "Bookman-Demi /Bookman-Demi-Outline MakeOutlinePlainFont~ /Bookman-Demi-Outline") (cons (canvas-make-font :name "Bookman" :style (list :italic :outline)) "Bookman-LightItalic /Bookman-LightItalic-Outline MakeOutlinePlainFont~ /Bookman-LightItalic-Outline") (cons (canvas-make-font :name "Bookman" :style (list :bold :italic :outline)) "Bookman-DemiItalic /Bookman-DemiItalic-Outline~ MakeOutlinePlainFont~ /Bookman-DemiItalic-Outline") (cons (canvas-make-font :name "Courier" :style :plain) "Courier") (cons (canvas-make-font :name "Courier" :style :italic) "Courier-Oblique") (cons (canvas-make-font :name "Courier" :style :bold) "Courier-Bold") (cons (canvas-make-font :name "Courier" :style (list :bold :italic)) "Courier-BoldOblique") (cons (canvas-make-font :name "Courier" :style :outline) "Courier /Courier-Outline MakeOutlinePlainFont~ /Courier-Outline") (cons (canvas-make-font :name "Courier" :style (list :bold :outline)) "Courier-Bold /Courier-Bold-Outline MakeOutlinePlainFont~ /Courier-Bold-Outline") (cons (canvas-make-font :name "Courier" :style (list :italic :outline)) "Courier-Oblique /Courier-Oblique-Outline MakeOutlinePlainFont~ /Courier-Oblique-Outline") (cons (canvas-make-font :name "Courier" :style (list :bold :italic :outline)) "Courier-BoldOblique /Courier-BoldOblique-Outline~ MakeOutlinePlainFont~ /Courier-BoldOblique-Outline") (cons (canvas-make-font :name "Palatino" :style :plain) "Palatino-Roman") (cons (canvas-make-font :name "Palatino" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "Palatino" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "Palatino" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "Palatino" :style :outline) "Palatino-Roman /Palatino-Roman-Outline MakeOutlinePlainFont~ /Palatino-Roman-Outline") (cons (canvas-make-font :name "Palatino" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "Palatino" :style (list :italic :outline)) "Palatino-Italic-Outline /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "Palatino" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Times" :style :plain) "Times-Roman") (cons (canvas-make-font :name "Times" :style :italic) "Times-Italic") (cons (canvas-make-font :name "Times" :style :bold) "Times-Bold") (cons (canvas-make-font :name "Times" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "Times" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "Times" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "Times" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "Times" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") (cons (canvas-make-font :name "Symbol" :style :plain) "Symbol") (cons (canvas-make-font :name "Symbol" :style :italic) "Symbol") (cons (canvas-make-font :name "Symbol" :style :bold) "Symbol") (cons (canvas-make-font :name "Symbol" :style (list :bold :italic)) "Symbol") (cons (canvas-make-font :name "Symbol" :style :outline) "Symbol /Symbol-Outline MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Symbol" :style (list :bold :outline)) "Symbol /Symbol-Outline MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Symbol" :style (list :italic :outline)) "Symbol /Symbol-Outline MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Symbol" :style (list :bold :italic :outline)) "Symbol /Symbol-Outline~ MakeOutlinePlainFont~ /Symbol-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style :plain) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style :italic) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style :bold) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :bold :italic)) "Zapf-Dingbats") (cons (canvas-make-font :name "Zapf Dingbats" :style :outline) "Zapf-Dingbats /Zapf-Dingbats-Outline MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :bold :outline)) "Zapf-Dingbats /Zapf-Dingbats-Outline MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :italic :outline)) "Zapf-Dingbats /Zapf-Dingbats-Outline MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "Zapf Dingbats" :style (list :bold :italic :outline)) "Zapf-Dingbats /Zapf-Dingbats-Outline~ MakeOutlinePlainFont~ /Zapf-Dingbats-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style :plain) "NewCenturySchlbk-Roman") (cons (canvas-make-font :name "New Century Schlbk" :style :italic) "NewCenturySchlbk-Italic") (cons (canvas-make-font :name "New Century Schlbk" :style :bold) "NewCenturySchlbk-Bold") (cons (canvas-make-font :name "New Century Schlbk" :style (list :bold :italic)) "NewCenturySchlbk-BoldItalic") (cons (canvas-make-font :name "New Century Schlbk" :style :outline) "NewCenturySchlbk-Roman /NewCenturySchlbk-Roman-Outline MakeOutlinePlainFont~ /NewCenturySchlbk-Roman-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style (list :bold :outline)) "NewCenturySchlbk-Bold /NewCenturySchlbk-Bold-Outline MakeOutlinePlainFont~ /NewCenturySchlbk-Bold-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style (list :italic :outline)) "NewCenturySchlbk-Italic /NewCenturySchlbk-Italic-Outline MakeOutlinePlainFont~ /NewCenturySchlbk-Italic-Outline") (cons (canvas-make-font :name "New Century Schlbk" :style (list :bold :italic :outline)) "NewCenturySchlbk-BoldItalic /NewCenturySchlbk-BoldItalic-Outline~ MakeOutlinePlainFont~ /NewCenturySchlbk-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond Bold" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond Bold" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond Bold" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond Bold" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond Bold" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond BoldItalic" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond BoldItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond Italic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond Italic" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond Italic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond Italic" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond Italic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond Semibold" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond Semibold" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond Semibold" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond Semibold" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :plain) "Palatino") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "AGaramond SemiboldItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style :plain) "Palatino-Bold") (cons (canvas-make-font :name "B Garamond Bold" :style :italic) "Palatino-BoldItalic") (cons (canvas-make-font :name "B Garamond Bold" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "B Garamond Bold" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "B Garamond Bold" :style :outline) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style (list :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "B Garamond Bold" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :plain) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :italic) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :bold) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style :outline) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :bold :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "BI Garamond BoldItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style :plain) "Palatino-Italic") (cons (canvas-make-font :name "I Garamond LightItalic" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "I Garamond LightItalic" :style :bold) "Palatino-BoldItalic") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "I Garamond LightItalic" :style :outline) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :bold :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "I Garamond LightItalic" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Garamond" :style :plain) "Palatino") (cons (canvas-make-font :name "Garamond" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "Garamond" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "Garamond" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "Garamond" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "Garamond" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "Garamond" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "Garamond" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style :plain) "Palatino") (cons (canvas-make-font :name "Zapf Chancery" :style :italic) "Palatino-Italic") (cons (canvas-make-font :name "Zapf Chancery" :style :bold) "Palatino-Bold") (cons (canvas-make-font :name "Zapf Chancery" :style (list :bold :italic)) "Palatino-BoldItalic") (cons (canvas-make-font :name "Zapf Chancery" :style :outline) "Palatino /Palatino-Outline MakeOutlinePlainFont~ /Palatino-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style (list :bold :outline)) "Palatino-Bold /Palatino-Bold-Outline MakeOutlinePlainFont~ /Palatino-Bold-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style (list :italic :outline)) "Palatino-Italic /Palatino-Italic-Outline MakeOutlinePlainFont~ /Palatino-Italic-Outline") (cons (canvas-make-font :name "Zapf Chancery" :style (list :bold :italic :outline)) "Palatino-BoldItalic /Palatino-BoldItalic-Outline~ MakeOutlinePlainFont~ /Palatino-BoldItalic-Outline") (cons (canvas-make-font :name "Merrion Square" :style :plain) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style :italic) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style :bold) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style (list :bold :italic)) "Ugly") (cons (canvas-make-font :name "Merrion Square" :style :outline) "Ugly /Ugly-Outline MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Merrion Square" :style (list :bold :outline)) "Ugly /Ugly-Outline MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Merrion Square" :style (list :italic :outline)) "Ugly /Ugly-Outline MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Merrion Square" :style (list :bold :italic :outline)) "Ugly /Ugly-Outline~ MakeOutlinePlainFont~ /Ugly-Outline") (cons (canvas-make-font :name "Chicago" :style :plain) "Times-Roman") (cons (canvas-make-font :name "Chicago" :style :italic) "Times-Italic") (cons (canvas-make-font :name "Chicago" :style :bold) "Times-Bold") (cons (canvas-make-font :name "Chicago" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "Chicago" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "Chicago" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "Chicago" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "Chicago" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") (cons (canvas-make-font :name "Geneva" :style :plain) "AvantGarde") (cons (canvas-make-font :name "Geneva" :style :italic) "AvantGarde-Oblique") (cons (canvas-make-font :name "Geneva" :style :bold) "AvantGarde-Demi") (cons (canvas-make-font :name "Geneva" :style (list :bold :italic)) "AvantGarde-DemiOblique") (cons (canvas-make-font :name "Geneva" :style :outline) "AvantGarde /AvantGarde-Outline MakeOutlinePlainFont~ /AvantGarde-Outline") (cons (canvas-make-font :name "Geneva" :style (list :bold :outline)) "AvantGarde-Demi /AvantGarde-Demi-Outline MakeOutlinePlainFont~ /AvantGarde-Demi-Outline") (cons (canvas-make-font :name "Geneva" :style (list :italic :outline)) "AvantGarde-Oblique /AvantGarde-Oblique-Outline MakeOutlinePlainFont~ /AvantGarde-Oblique-Outline") (cons (canvas-make-font :name "Geneva" :style (list :bold :italic :outline)) "AvantGarde-DemiOblique /AvantGarde-DemiOblique-Outline~ MakeOutlinePlainFont~ /AvantGarde-DemiOblique-Outline") (cons (canvas-make-font :name "Monaco" :style :plain) "Times-Roman") (cons (canvas-make-font :name "Monaco" :style :italic) "Times-Italic") (cons (canvas-make-font :name "Monaco" :style :bold) "Times-Bold") (cons (canvas-make-font :name "Monaco" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "Monaco" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "Monaco" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "Monaco" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "Monaco" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style :plain) "Helvetica") (cons (canvas-make-font :name "N Helvetica Narrow" :style :italic) "Helvetica-Oblique") (cons (canvas-make-font :name "N Helvetica Narrow" :style :bold) "Helvetica-Bold") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :bold :italic)) "Helvetica-BoldOblique") (cons (canvas-make-font :name "N Helvetica Narrow" :style :outline) "Helvetica /Helvetica-Outline MakeOutlinePlainFont~ /Helvetica-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :bold :outline)) "Helvetica-Bold /Helvetica-Bold-Outline MakeOutlinePlainFont~ /Helvetica-Bold-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :italic :outline)) "Helvetica-Oblique /Helvetica-Oblique-Outline MakeOutlinePlainFont~ /Helvetica-Oblique-Outline") (cons (canvas-make-font :name "N Helvetica Narrow" :style (list :bold :italic :outline)) "Helvetica-BoldOblique /Helvetica-BoldOblique-Outline~ MakeOutlinePlainFont~ /Helvetica-BoldOblique-Outline") (cons (canvas-make-font :name "New York" :style :plain) "Times-Roman") (cons (canvas-make-font :name "New York" :style :italic) "Times-Italic") (cons (canvas-make-font :name "New York" :style :bold) "Times-Bold") (cons (canvas-make-font :name "New York" :style (list :bold :italic)) "Times-BoldItalic") (cons (canvas-make-font :name "New York" :style :outline) "Times-Roman /Times-Roman-Outline MakeOutlinePlainFont~ /Times-Roman-Outline") (cons (canvas-make-font :name "New York" :style (list :bold :outline)) "Times-Bold /Times-Bold-Outline MakeOutlinePlainFont~ /Times-Bold-Outline") (cons (canvas-make-font :name "New York" :style (list :italic :outline)) "Times-Italic /Times-Italic-Outline MakeOutlinePlainFont~ /Times-Italic-Outline") (cons (canvas-make-font :name "New York" :style (list :bold :italic :outline)) "Times-BoldItalic /Times-BoldItalic-Outline~ MakeOutlinePlainFont~ /Times-BoldItalic-Outline") ) "This variable maps the standard Macintosh fonts to the~ standard Postscript fonts." )
41,543
Common Lisp
.l
816
33.026961
94
0.510916
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
18d3c9b05fff9e0af2d774678ed5f68d02fbd4c8a46f6c638bb7166810fe2a26
33,578
[ -1 ]
33,579
dialog-expts-v7.lsp
rwoldford_Quail/source/window-basics/prompt/dialog-expts-v7.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog-expts-v7.lsp ;;; ;;; Consolidating some things from code-fragment.lsp ;;; in an attempt to sort out dialogs in v7 ;;; I think I need to employ :on-click argument ;;; when making items ;;; ;;; Started 14JAN05 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;14 Jan 05 ;;; collect some definitions (setf displayed 5 scroll-bar-width 25 seq-height 200 seq-width 200 dialog-outer-left 10 min-separator 15 dialog-outer-top 10 prompt-text "Here is a text-dialog" select-text "Select" cancel-text "Cancel" error-text "please choose an item first!" items (list "First" "Second" "Third")) ;; ok[1] (setf temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) ;; ok[2] (setf text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) ;; 19 ok[3] (setf button-height (+ 2 text-height)) ;; 21 ok[4] (setf prompt-box-height (+ 10 (* 1 text-height))) ;; 29 ok[5] (defun text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)))) ;; text-width ok[6] (setf button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) ;; 49 ok[7] (setf prompt-text-width (text-width prompt-text)) ;; 131 ok[8] (setf text-box-width (+ 5 prompt-text-width )) ;; 136 ok[9] (setf text-box-height (+ 10 text-height)) ;; 29 ok[10] (setf max-item-width (first (sort (mapcar #'(lambda (x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) x)))) items) #'>))) ;; 48 ok[11] ;;; And some forms too (defun how-many (char string) "Counts the number of occurrences of char in string" (- (length string) (length (remove-if #'(lambda (x) (eq x char)) string)))) ;; how-many ok[12] (defun list-of-lengths (string) ;; Assume string does *not* start with ~% ;; Gets a list of the stream-string-width of the ;; text bits of string (let ((result '()) (fmat (list #\~ #\% #\Newline)) (alphabet (list #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\Space #\. #\, #\; #\: #\( #\))) ) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) (do ((j 0 (+ j 1)) (n (how-many #\Newline string))) ((= j n)) (setf string (string-left-trim fmat (string-left-trim alphabet string))) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) ) result)) ;; list-of-lengths ok[12] (defun max-text-segment (lengths) " Gets the length of the maximum text segment~ from a collection of cumulative lengths of a piece~ of text assumed to have come from list-of-lengths." (let ((diffs '())) (do ((j 0 (+ j 1)) (n (length lengths))) ((= j (- n 1))) (push (- (elt lengths j) (elt lengths (+ j 1))) diffs)) (cond ((eq 1 (length lengths)) (first lengths)) (T (abs (first (sort diffs #'<)))) ) )) ;; max-text-segment ok[13] ;;; Finally, some dialogs too (setf text-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text 10jan05 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; ok[14] ;;; can I show this now ? (pop-up-modal-dialog text-dialog :stream (screen *system*) :initial-focus NIL :bring-thread-to-front T) ;; error! ;;; I'll use create-multi-dialog with list-of-dialog-items just ;;; this text dialog (setf list-of-dialog-items (list text-dialog)) ;; ok[14] (setf error-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text 10jan05 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text)) ;; ok[16] (setf seq-dialog (make-instance cg::'multi-item-list ;(cg::make-dialog-item :widget cg::'multi-item-list :range items :box (cg::make-box-relative ;(cg::box-left (cg::dialog-item-box text-dialog)) 10jan05 (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T ) ) ;; ok[17] (setf cancel-button (make-instance ; (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ (cg::right (cg::box seq-dialog)) ;(cg::dialog-item-box seq-dialog)) min-separator) (+ (cg::bottom (cg::box seq-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; ok[18] (setf select-button (make-instance ;(cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (cg::left (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button)) (+ (cg::bottom (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not ;(cg::dialog-item-value seq-dialog) (cg::value (cg::dialog-item seq-dialog)) ) (cg::pop-up-message-dialog (cg::dialog-item-window seq-dialog) "You choose ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t))) ) )) ;; ok[19] ;;; That ought to be sufficient to get started! ;;; execute the long setf etc.. (defun create-multi-dialog (items &key (prompt-text "Please choose one or more ... ") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items ;(build-multi-dialog-items items ; :prompt-text prompt-text ; :item-print-function item-print-function ; :action-function action-function ; :select-text select-text ; :cancel-text cancel-text) (list text-dialog error-dialog seq-dialog select-button cancel-button) ) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (scroll-bar-width 25) (min-separator 15) (text-dialog (first list-of-dialog-items)) (select-button (fourth list-of-dialog-items)) (cancel-button (fifth list-of-dialog-items)) (seq-dialog (third list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance ;cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "You choose .." :pop-up-p t ;:font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top (+ min-separator (max (cg::right (cg::box text-dialog) ;(cg::dialog-item-box text-dialog) ) (cg::right (cg::box text-dialog) ;(cg::dialog-item-box select-button) ) (cg::right (cg::box text-dialog) ;(cg::dialog-item-box cancel-button) ))) (+ (* 4 min-separator) (max (cg::bottom (cg::box seq-dialog) ;(cg::dialog-item-box seq-dialog) ) (cg::bottom (cg::box cancel-button) ;(cg::dialog-item-box cancel-button) )))) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog list-of-dialog-items) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; create-multi-dialog ok[15] (setf dialog1 (create-multi-dialog list-of-dialog-items)) ;* Error: Attempt to take the value of the unbound variable `ERROR-DIALOG'. ;* [condition type: UNBOUND-VARIABLE] ;; so I need the other dialogs too (setf the-items (list text-dialog error-dialog seq-dialog select-button cancel-button)) ;; ok[16] (setf dialog1 (create-multi-dialog the-items)) ;; ok[17] (pop-up-modal-dialog dialog1 :stream (screen *system*) :initial-focus NIL :bring-thread-to-front T) ;* barf as before ;; let's get select-button and modify it using :on-click: (setf select-button (make-instance ;(cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (cg::left (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button)) (+ (cg::bottom (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button) min-separator) button-width button-height) :title select-text ;:on-click :set-value-fn #'(lambda (&rest args) (format t ~s "Here is the result from :on-click")) ;:set-value-fn ;; replaced by the line above ;#'(lambda (&rest args) ; (cond ((not ; ;(cg::dialog-item-value seq-dialog) ; (cg::value (cg::dialog-item seq-dialog)) ; ) ; (cg::pop-up-message-dialog (cg::dialog-item-window seq-dialog) ; "You choose ... " error-text cg::warning-icon "OK?") ; ;; Accept the button click but do not return from the ; ;; main dialog yet after popping up the warning ; (values t nil)) ; ;; Return from the main dialog since we noted above that ; ;; a selection was made ; (t (values t t))) ; ) )) ;; done the redefinition and that of list the-items ;; and dialog1 ;* Error: Cannot add (Unnamed) to You choose .. because it is already on You choose ... ;* [1] CG-USER(39): (setf seq-dialog (make-instance cg::'multi-item-list ;(cg::make-dialog-item :widget cg::'multi-item-list :range items :box (cg::make-box-relative ;(cg::box-left (cg::dialog-item-box text-dialog)) 10jan05 (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T :on-click #'(lambda (&rest args) (format t ~s :range)) ) )
15,599
Common Lisp
.l
325
30.935385
115
0.443753
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
409829d1c4375caf193ee668e4dd6d41dfd76c790e2514d65bf71bec6ddc3f1f
33,579
[ -1 ]
33,582
check-items-sblx.lsp
rwoldford_Quail/source/window-basics/prompt/check-items-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; check-items-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W.Bennett 1996-1997, 2020 ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(check-items))) ;;; two functions needed later (defun pos-list (a-list a-sublist) "returns the positions of the elements of a-sublist in a-list" (mapcar #'(lambda (x) (position x a-list :test #'equal)) a-sublist)) (defun copy-result-list (plist1 list2) "returns a copy of list2 with cdrs updated to T at positions plist" (let ((copy-list2 (copy-tree list2))) (dolist (x plist1 (return copy-list2)) (setf (elt copy-list2 x) (cons (car (elt copy-list2 x)) t))) (return-from copy-result-list copy-list2))) ;;; check-items itself (defun check-items (items &key (prompt-text "Check one or more ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "cancel")) "returns a copy of items with cdrs updated to T at positions pos-list obtained from the matching application-frame" (let ((frame (make-application-frame 'check-items :pretty-name prompt-text :items items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text))) (run-frame-top-level frame) (return-from check-items (copy-result-list (pos-list items (reverse (frame-result frame))) items)) )) ;;; The application frame to collect the elements selected (define-application-frame check-items () ((frame-result :initform nil :accessor frame-result) (items :initarg :items :accessor items) (prompt-text :initarg :prompt-text :accessor prompt-text) (item-print-function :initarg :item-print-function :accessor item-print-function) (action-function :initarg :action-function :accessor action-function) (select-text :initarg :select-text :accessor select-text) (cancel-text :initarg :cancel-text :accessor cancel-text) ) (:menu-bar nil) (:panes (prompt-pane (make-pane 'clim-stream-pane :height 30 :scroll-bars nil :display-time t :display-function #'(lambda (frame pane) (draw-text* pane (prompt-text *application-frame*) 10 25 :ink +blue+ :text-size 18)) )) (options (make-pane 'list-pane :mode :nonexclusive :items (items *application-frame*) :name-key #'car ))) (:layouts (default (vertically (:height 300 :width 350) prompt-pane (horizontally () (labelling (:label "Options") (scrolling () options))) (horizontally () +fill+ (make-pane 'push-button :label (string-upcase (select-text *application-frame*)) :activate-callback (lambda (ignore) ignore (setf (frame-result *application-frame*) (gadget-value options)) (frame-exit *application-frame*)) ) (make-pane 'push-button :label (string-upcase (cancel-text *application-frame*)) :activate-callback (lambda (ignore) ignore (frame-exit *application-frame*))) )))))
4,015
Common Lisp
.l
92
35.793478
146
0.578799
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bbf1f5d9b0682a409826d464a1bcac4f2d4029930a51793bd127b431dc06d04b
33,582
[ -1 ]
33,583
collect-input-pc.lsp
rwoldford_Quail/source/window-basics/prompt/collect-input-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; collect-input-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(collect-input))) ;;; collect-input takes (list (cons "a" "a1") (cons "s" "s1") ..) ;;; the elements are open for editing, so using (list (cons "a" "a1") (cons "s" "s1")) ;;; and changing a1 to a11 + select -> (list (cons "a" "a11") (cons "s" "s1")) ;;; since s1 was unedited ;; Build the list of dialog-items (defun build-collect-items (items &key (prompt-text "Please enter responses ...") (select-text "select") (cancel-text "cancel") (columns 1) ) (flet ((text-width (string) (quail-string-width string))) (let* ((response-width 100) ;; width of editable-text boxes (max-item-width (apply #'max (mapcar #'text-width items))) (error-text "please choose an item first!") (error-text-width (text-width error-text)) (prompt-text-width (text-width prompt-text)) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (prompt-box-height (+ 10 *text-box-height*)) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) (n-items (length items)) (col-width (+ 15 max-item-width )) (nrows (ceiling (/ n-items columns))) ;; make the prompt stuff (text-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width prompt-box-height) :value (format nil prompt-text) :name :text-d )) ;; prompt stuff done ;; Now set the top of the first item (first-item-y (+ (cg::bottom (cg::box text-dialog)))) (first-item-x *dialog-outer-left* ) ;; make the error stuff (error-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width *text-box-height*) :border :static :value error-text :name :error-d)) ;; error stuff done ;; collect-dialog should start here ;;; TOP OF CODE FROM -mcl FILE (collect-dialog (loop for item in items with y-start = first-item-y with x-start = first-item-x with row = 0 with col = 0 append (list (make-instance 'cg::static-text ;; Display must be in :value slot ;; (car item) grabs the "prompt-piece" :value (car item) ;item :box (cg::make-box-relative (+ x-start (* col col-width) *min-separator*) (+ y-start (* row *text-box-height*)) (+ *min-separator* max-item-width ) (+ *text-box-height*)) :available-p T ) (make-instance 'cg::editable-text ;; This has implications for the return value. ;; editable-test returns a genuine string ;; lisp-text returns a lisp object ;; (cdr item) grabs the "default value" :value (cdr item) ;NIL :box (cg::make-box-relative (+ x-start (* col col-width) *min-separator* *min-separator* max-item-width) (+ y-start (* row *text-box-height*)) response-width (+ *text-box-height*)) :available-p T )) do (cond ((>= row (1- nrows)) (incf col 1) (setq row 0) (setq x-start (+ x-start response-width *min-separator*))) (T (incf row 1)))) ) ;;; END OF CODE FROM -mcl FILE ;;; Find two values needed for later sizing and positioning (rightmost (cg::right (cg::box (first (last collect-dialog))))) (collect-bottom (apply #'max (mapcar #'cg::bottom (mapcar #'cg::box collect-dialog)))) ;; cancel begins (cancel-button (make-instance 'cg::cancel-button :box (cg::make-box-relative (+ rightmost *min-separator*) (+ (cg::bottom (cg::box text-dialog)) *min-separator*) button-width *button-height*) :title cancel-text :name :cancel-d )) (cancel-bottom (cg::bottom (cg::box cancel-button))) ;; cancel done ;; make select stuff (select-button (make-instance 'cg::button :box (cg::make-box-relative (+ rightmost *min-separator*) (+ (cg::bottom (cg::box cancel-button)) *min-separator*) button-width *button-height*) :title select-text :name :select-d :set-value-fn #'(lambda (&rest args) (values t t)) )) (select-bottom (cg::bottom (cg::box select-button)) ) ;; select done ;; compute overall sizes (overall-width (+ *min-separator* (max (cg::right (cg::box text-dialog)) (cg::right (cg::box select-button)) (cg::right (cg::box cancel-button))))) (overall-height (+ (* 4 *min-separator*) (max collect-bottom cancel-bottom select-bottom))) ) ;; return some sizes and the dialogs (append (list overall-width overall-height text-dialog error-dialog) collect-dialog (list select-button cancel-button)) ) ) ) ;;end of build-collect-items ;; Create the real dialog from the output of build-collect-items (defun create-collect-dialog (items &key (columns 1) (prompt-text "Please enter responses ...") ;(item-print-function NIL) ;(action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) ;(declare (ignore action-function)) (let* ((list-of-dialog-items (build-collect-items items :columns columns :prompt-text prompt-text :select-text select-text :cancel-text cancel-text)) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance 'cg::button :box (cg::make-box 20 20 20 20)) )) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Enter responses ..." :pop-up-p t :font (cg::make-font :roman "times\ new\ roman" 20);(canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative *dialog-outer-left* *dialog-outer-top* overall-width overall-height ) )) ) ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ) ;; end of create-collect-dialog ;; Now deal with the dialog (defun collect-input(items &key (columns 1) (prompt-text "Please enter responses ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (declare (ignore item-print-function action-function)) ;18oct2023 ;; Make the dialog itself (let ((a-dialog (create-collect-dialog items :columns columns :select-text select-text :cancel-text cancel-text :prompt-text prompt-text))) ;; Show the completed dialog (cg::pop-up-modal-dialog a-dialog) ;; Check on what is returned (let* ((d-items (cg::dialog-items a-dialog)) (v-items (mapcar #'cg::value d-items)) (d-length (length d-items)) (cancel-v (cg::value (cg::find-component :cancel-d a-dialog))) ) (if cancel-v items (loop for x from 0 to (- d-length 5) collect (cons (nth (+ x 2) v-items) (nth (+ x 3) v-items) ) do (incf x 1)) )))) ;; end collect-input
12,309
Common Lisp
.l
228
29.921053
128
0.390682
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
78967799a1a63c154c609afc3864fba72970f4c4ebf166c817b7c76ceba901a2
33,583
[ -1 ]
33,584
check-items-expts.lsp
rwoldford_Quail/source/window-basics/prompt/check-items-expts.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; check-items-expts.lsp ;;; ;;; to adapt existing code in check-items-pc.lsp ;;; for acl70beta ;;; ;;; mainly in how dialog items are established ;;; ;;; 19 June 2004 ;;; Greg Bennett ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; Here are the results: ;;;[1] cg::make-dialog-item :widget 'cg::static-text .. ;;;; is replaced by ;;;; (make-instance cg::'static-text ;;;[2] (cg::box-height (cg::dialog-item-box (first check-dialog))) ;;;; is replaced by ;;;; (cg::height (first check-dialog)) ;;;[3] t-items (mapcar #'cg::dialog-item-title d-items)) ;;;; is replaced by ;;;; (t-items (mapcar #'cg::title d-items)) ;; Build the necessary lists of dialog-items (defun build-check-dialog-items (items &key (prompt-text "Check one or more ...") (item-print-function nil) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel") (columns 1) ) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)) )) (set-view-size (a-window) (list (cg::width (cg::exterior a-window)) (cg::height (cg::exterior a-window))))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))) )) (dialog-outer-left 10) (dialog-outer-top 10) ; (scroll-bar-width 25) (min-separator 15) (check-allowance 10) (max-item-width (first (sort (mapcar #'(lambda (x) (if (stringp x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) x) (cg::stream-string-width (cg::screen cg::*system*) (format NIL "~s" x)))))) items) #'>))) (error-text "please choose an item first!") (error-text-width (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) error-text)))) (prompt-text-width (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) prompt-text)))) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-text)) text-height))) (text-box-x 20) (text-box-y 20) (button-height (+ 2 text-height)) (button-width (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (+ 5 (max (cg::stream-string-width (cg::screen cg::*system*) select-text) (cg::stream-string-width (cg::screen cg::*system*) cancel-text)))))) (seq-height 200) (seq-width 200) (n-items (length items)) (col-width (+ 15 max-item-width check-allowance)) (nrows (ceiling (/ n-items columns))) (first-item-y (+ text-box-y text-box-height)) (first-item-x dialog-outer-left ) (button-x (+ 50 first-item-x (* columns col-width))) (view-size-width (max 200 (+ button-x button-width 2) (+ text-box-x text-box-width 2))) (view-size-height (max 100 (+ first-item-y (+ 2 (* (+ nrows 1) text-box-height)) 2) (+ text-box-height button-height 2))) ;; make the prompt stuff (text-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text ;;19june2004 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text ;;19june2004 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text)) ;; error stuff done ;; check-dialog should start here ;;; TOP OF CODE FROM -mcl FILE (check-dialog (loop for item in items with y-start = first-item-y with x-start = first-item-x with row = 0 with col = 0 collect (make-instance cg::'check-box ;(cg::make-dialog-item ;;19june2004 ; :widget cg::'check-box ;;19june2004 :title item :box (cg::make-box-relative (+ x-start (* col col-width) min-separator) (+ y-start (* row text-box-height)) (+ min-separator max-item-width check-allowance) (+ min-separator text-box-height)) :available-p T ) do (cond ((>= row (1- nrows)) (incf col 1) (setq row 0)) (T (incf row 1)))) ) ;;; END OF CODE FROM -mcl FILE (height-item-box (cg::height (first check-dialog))) ;(cg::box-height (cg::dialog-item-box (first check-dialog))) (width-item-box (cg::width (first check-dialog))) ;(cg::box-width (cg::dialog-item-box (first check-dialog)))) (rightmost (cg::right (first check-dialog))) ;(cg::box-right (cg::dialog-item-box (first (last check-dialog))))) ;; cancel begins (cancel-button (make-instance cg::'cancel-button ;(cg::make-dialog-item ;;19june2004 ; :widget cg::'cancel-button ;;19june2004 :box (cg::make-box-relative (+ rightmost min-separator) (+ (cg::bottom text-dialog) min-separator) ;(+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (make-instance cg::'button ;(cg::make-dialog-item ;;19june2004 ; :widget cg::'button ;;19june2004 :box (cg::make-box-relative (+ rightmost min-separator) (+ (cg::bottom cancel-button) min-separator) ;(+ (cg::box-bottom (cg::dialog-item-box cancel-button)) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (values t t)) )) ;; select done (overall-width (+ (* 4 min-separator) (* columns width-item-box) button-width)) (overall-height (+ (* 4 min-separator) (* nrows height-item-box) button-height)) ) ;; end of bindings in let* .. body follows (append (list overall-width overall-height text-dialog error-dialog) check-dialog (list select-button cancel-button)) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;; end of build-check-items (defun create-check-dialog (items &key (columns 1) (prompt-text "Choose one or more ...") (item-print-function NIL) (item-select-function #'(lambda (i) i)) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items (build-check-dialog-items items :columns columns :item-print-function item-print-function :action-function action-function :prompt-text prompt-text :select-text select-text :cancel-text cancel-text)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance cg::'button :box (cg::make-box 20 20 20 20)))) ;(cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Choose One .." :pop-up-p t ;:font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top overall-width overall-height ) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; end of create-check-dialog (defun check-items (items &key (columns 1) (prompt-text "Choose one or more ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) ;; Make the dialog itself (let* ((a-dialog (create-check-dialog items :columns columns :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text :prompt-text prompt-text)) ;; Show the completed dialog (showit (cg::pop-up-modal-dialog a-dialog) ;cg::pop-up-dialog a-dialog) ) ;; Check on what is returned (d-items (cg::dialog-items a-dialog)) (t-items (mapcar #'cg::title d-items)) ;t-items (mapcar #'cg::dialog-item-title d-items)) (v-items (mapcar #'cg::value d-items)) ;v-items (mapcar #'cg::dialog-item-value d-items)) (n-items (length items)) (cancel-v (nth (+ 3 n-items) v-items)) (select-v (nth (+ 4 n-items) v-items))) (if cancel-v items (loop for x from 0 to (- n-items 1) collect (cons (nth (+ x 2) t-items) (nth (+ x 2) v-items))) ) ) ;; end let* ) ;; end of check-items itself
13,820
Common Lisp
.l
271
31.369004
126
0.436632
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5b1ac5f73dd9997f861b507bcc28e77e50a45a76646dd2eb32dea57a34b3d0ce
33,584
[ -1 ]
33,585
dialog-pc.lsp
rwoldford_Quail/source/window-basics/prompt/dialog-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog-pc.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; Authors: ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996 (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialogs in ACL-PC are used.
538
Common Lisp
.l
12
42.833333
81
0.271863
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6d5f3b7b59d967899df6fb7e86c40a157d9225cd9dfe20a2deb31a4b8193d174
33,585
[ -1 ]
33,588
dialog-sblx.lsp
rwoldford_Quail/source/window-basics/prompt/dialog-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog-sblx.lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; Authors: ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996, 2020 (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialogs in SBCL-LINUX are used.
538
Common Lisp
.l
12
43.833333
80
0.290875
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0b2cb5eeb7c7bde8502f667ea6bd8c07fa72e83c9ca3500c15914d4ad8b4bc13
33,588
[ -1 ]
33,590
check-items-pc.lsp
rwoldford_Quail/source/window-basics/prompt/check-items-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; check-items-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W.Bennett 1996-1997 ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(check-items))) ;;; check-items takes (list "a" "b" ..) for items and returns (list "a" ("b".T) ..) if "b" is selected ;;; and so on for other selections. ;; Build the necessary lists of dialog-items (defun build-check-dialog-items (items &key (prompt-text "Check one or more ...") (select-text "select") (cancel-text "cancel") (columns 1) ) (let* ((check-allowance 10) (max-item-width (reduce #'max (mapcar #'(lambda (x) (quail-string-width x)) items))) (error-text "please choose an item first!") (error-text-width (quail-string-width error-text)) (prompt-text-width (quail-string-width prompt-text)) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (prompt-box-height (+ 10 *text-height*)) (text-box-y 20) (button-width (+ 5 (max (quail-string-width select-text) (quail-string-width cancel-text)))) (n-items (length items)) (col-width (+ 15 max-item-width check-allowance)) (nrows (ceiling (/ n-items columns))) (first-item-y (+ text-box-y *text-box-height*)) (first-item-x *dialog-outer-left* ) ;; make the prompt stuff (text-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width *text-box-height*) :border :static :value error-text)) ;; error stuff done ;; check-dialog should start here ;;; TOP OF CODE FROM -mcl FILE (check-dialog (loop for item in items with y-start = first-item-y with x-start = first-item-x with row = 0 with col = 0 collect (make-instance 'cg::check-box :title item :box (cg::make-box-relative (+ x-start (* col col-width) *min-separator*) (+ y-start (* row *text-box-height*)) (+ *min-separator* max-item-width check-allowance) (+ *min-separator* *text-box-height*)) :available-p T ) do (cond ((>= row (1- nrows)) (incf col 1) (setq row 0)) (T (incf row 1)))) ) ;;; END OF CODE FROM -mcl FILE (height-item-box (cg::height (cg::box (first check-dialog)))) (width-item-box (cg::width (cg::box (first check-dialog)))) (rightmost (cg::right (cg::box (first (last check-dialog))))) ;; cancel begins (cancel-button (make-instance 'cg::cancel-button :box (cg::make-box-relative (+ rightmost *min-separator*) (+ (cg::bottom (cg::box text-dialog)) *min-separator*) button-width *button-height*) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (make-instance 'cg::button :box (cg::make-box-relative (+ rightmost *min-separator*) (+ (cg::bottom (cg::box cancel-button)) *min-separator*) button-width *button-height*) :title select-text :set-value-fn #'(lambda (&rest args) (values t t)) )) ;; select done (overall-width (+ (* 4 *min-separator*) (* columns width-item-box) button-width)) (overall-height (+ (* 4 *min-separator*) (* nrows height-item-box) *button-height*)) ) (append (list overall-width overall-height text-dialog error-dialog) check-dialog (list select-button cancel-button)) ) ) ;; end of build-check-items ;; Create the dialog itself from what build produces (defun create-check-dialog (items &key (columns 1) (prompt-text "Choose one or more ...") (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items (build-check-dialog-items items :columns columns :prompt-text prompt-text :select-text select-text :cancel-text cancel-text)) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance 'cg::button :box (cg::make-box 20 20 20 20)) )) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Choose One .." :pop-up-p t :font (cg::make-font :roman "times\ new\ roman" 20);(canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative *dialog-outer-left* *dialog-outer-top* overall-width overall-height ))) ) ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; end of create-check-dialog ;; Now process the whole thing (defun check-items (items &key (columns 1) (prompt-text "Choose one or more ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (declare (ignore item-print-function action-function)) ;; Make the dialog itself (let ((a-dialog (create-check-dialog items :columns columns :select-text select-text :cancel-text cancel-text :prompt-text prompt-text))) (cg::pop-up-modal-dialog a-dialog) (let*( (d-items (cg::dialog-items a-dialog)) (t-items (mapcar #'cg::title d-items)) (v-items (mapcar #'cg::value d-items)) (n-items (length items)) (cancel-v (nth (+ 3 n-items) v-items)))(defun collect-input(items &key (columns 1) (prompt-text "Please enter responses ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (declare (ignore item-print-function action-function)) ;18oct2023 ;; Make the dialog itself (let ((a-dialog (create-collect-dialog items :columns columns :select-text select-text :cancel-text cancel-text :prompt-text prompt-text))) ;; Show the completed dialog (cg::pop-up-modal-dialog a-dialog) ;; Check on what is returned (let* ((d-items (cg::dialog-items a-dialog)) (v-items (mapcar #'cg::value d-items)) (d-length (length d-items)) (cancel-v (cg::value (cg::find-component :cancel-d a-dialog))) ) (if cancel-v items (loop for x from 0 to (- d-length 5) collect (cons (nth (+ x 2) v-items) (nth (+ x 3) v-items) ) do (incf x 1)) )))) (if cancel-v items (loop for x from 0 to (- n-items 1) collect (cons (nth (+ x 2) t-items) (nth (+ x 2) v-items)))))) ) ;; end check-items itself
9,964
Common Lisp
.l
200
32.52
135
0.455887
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e1f6f87bbece6291ccf93a66c51815ef0730211eaa2cc3ce1cabc2bb46355097
33,590
[ -1 ]
33,591
prompt-pc.lsp
rwoldford_Quail/source/window-basics/prompt/prompt-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; prompt-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; Authors: ;;; Greg Anglin 1991 ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; This holds the building, creation, and processing ;;; of multi-item-lists all of which are needed for ;;; prompt-user files. They are here because of the ;;; limitation on ACL/PC's edit buffer!! ;;; ;;; G.W.Bennett January 24 1997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(prompt-user save-value prompt-t-or-f prompt-true-or-false prompt-for-items))) ;; Build the list of dialog-items (defun build-multi-dialog-items (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) ;(declare (ignore item-print-function action-function)) (let* ((max-item-width (reduce #'max (mapcar #'(lambda (x) (quail-string-width x)) items))) (error-text "please choose an item first!") (error-text-width (quail-string-width error-text)) (prompt-text-width (quail-string-width prompt-text)) (text-box-width (+ 5 (max prompt-text-width error-text-width))) ;(text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 *text-height*)) (button-width (+ 5 (max (quail-string-width *select-text*) (quail-string-width cancel-text) ))) ;; make the prompt stuff (text-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width *text-box-height*) :border :static :value error-text)) ;; error stuff done ;; seq-dialog should start here (seq-dialog (make-instance 'cg::multi-item-list :range items :box (cg::make-box-relative (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) *min-separator* ) (+ max-item-width *scroll-bar-width*) (+ *min-separator* (* (min (length items) *displayed*) *text-height*))) :title "Pick one" :available-p T ) ) ;; seq-dialog should end here ;; cancel begins (cancel-button (make-instance 'cg::cancel-button :box (cg::make-box-relative (+ (cg::right (cg::box seq-dialog)) *min-separator*) (+ (cg::bottom (cg::box text-dialog)) *min-separator*) button-width *button-height*) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (make-instance 'cg::button :box (cg::make-box-relative (cg::left (cg::box cancel-button)) (+ (cg::bottom (cg::box cancel-button)) *min-separator*) button-width *button-height*) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not (cg::value seq-dialog) ) (cg::pop-up-message-dialog (cg::window seq-dialog) "You choose ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t)))) )) ;; select done ) (list text-dialog error-dialog seq-dialog select-button cancel-button) )) ;; end of build-multi-dialog-items ;; Create the dialog from what build-.. produces (defun create-multi-dialog (items &key (prompt-text "Please choose one or more ... ") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items (build-multi-dialog-items items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (text-dialog (first list-of-dialog-items)) (select-button (fourth list-of-dialog-items)) (cancel-button (fifth list-of-dialog-items)) (seq-dialog (third list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance 'cg::button :box (cg::make-box 20 20 20 20)) )) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "You choose .." :pop-up-p t :font (cg::make-font :roman "times\ new\ roman" 20);(canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative *dialog-outer-left* *dialog-outer-top* (+ *min-separator* (max (cg::right (cg::box text-dialog)) (cg::right (cg::box select-button)) (cg::right (cg::box cancel-button)))) (+ (* 4 *min-separator*) (max (cg::bottom (cg::box seq-dialog)) (cg::bottom (cg::box cancel-button))))) )) ;; End creation of empty base-dialog here ) ;; add new items (cg::update-dialog base-dialog list-of-dialog-items) base-dialog) ) ;; end of create-multi-dialog ;; Now process it (defun process-multi-dialog (items &key (prompt-text "Please choose one or more .. ") (item-print-function nil) (action-function #'identity) (select-text "select") (cancel-text "cancel")) ;; Make the dialog itself (let ((new-items '())) (cond ((functionp item-print-function) (setf new-items (mapcar item-print-function items))) ((null item-print-function) (setf new-items (mapcar #'(lambda (item) (format NIL "~s" item)) items))) (T items)) ;) (let* ((a-dialog (create-multi-dialog new-items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (error-text "Please choose an item first!") ;; Show the completed dialog (clicked-button (cg::pop-up-modal-dialog a-dialog)) (d-items (mapcar #'cg::value (cg::dialog-items a-dialog)) ) (seq-v (third d-items)) (select-v (fourth d-items)) (cancel-v (fifth d-items))) (cond (cancel-v (abort) ) (t (loop for item in items as new-item in new-items when (member new-item seq-v :test #'string-equal) collect (funcall action-function item)))) ))) ;; end of process-multi-dialog ;;; Code in the mold of other dialogs follows ;;; build-prompt-user -> create-prompt-user -> prompt-user itself (defun build-prompt-user (&key ;(result-type T) ;(read-type :string) ;07aug2023 type->result-type (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "cancel") ) (let* ((response-width 100) (prompt-text-width (quail-string-width prompt-string)) (text-box-width (+ 5 prompt-text-width )) (prompt-box-height (+ 10 *text-height*)) (button-width (+ 5 (max (quail-string-width ok-text) (quail-string-width cancel-text) ))) ;; make the prompt stuff (text-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width prompt-box-height) :value (format nil prompt-string) :name :text-d) ) ;; prompt stuff done ;; Now set the top of the first item (first-item-y (cg::bottom (cg::box text-dialog))) ;;; Make the response-dialog (response-dialog (make-instance 'cg::editable-text :value initial-string :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ first-item-y *min-separator*) (max response-width prompt-text-width) *text-box-height*) :name :resp-d)) ;;; Find two values needed for later sizing and positioning (collect-bottom (cg::bottom (cg::box response-dialog))) ;; cancel begins (cancel-button (make-instance 'cg::cancel-button :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ collect-bottom *min-separator*) button-width *button-height*) :title cancel-text :name :cancel-d :on-click #'(lambda (x y) (declare (ignore x y)) (abort)) )) (cancel-bottom (cg::bottom (cg::box cancel-button))) ;; cancel done ;; make select stuff (select-button (make-instance 'cg::button :box (cg::make-box-relative (+ (cg::right (cg::box cancel-button)) *min-separator*) (+ collect-bottom *min-separator*) button-width *button-height*) :title ok-text :name :select-d :set-value-fn #'(lambda (&rest args) (values t t)) )) ;; select done ;; compute overall sizes (overall-width (+ *min-separator* (max (cg::right (cg::box text-dialog)) (cg::right (cg::box response-dialog)) (cg::right (cg::box select-button)) (cg::right (cg::box cancel-button))))) (overall-height (+ (* 4 *min-separator*) cancel-bottom )) ) ;; return some sizes and the dialogs (list overall-width overall-height text-dialog response-dialog select-button cancel-button) )) ;; 18oct05 to replace just prompt-user itself (defun create-prompt-user (&key ;(result-type T) ;(read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "cancel") ) (let* ((list-of-dialog-items (build-prompt-user ;:result-type result-type ;07aug2023 type -> result-type ;:read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text)) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance 'cg::button :box (cg::make-box 20 20 20 20)) )) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Your input .." :pop-up-p t :font (cg::make-font :roman "times\ new\ roman"20);(canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative *dialog-outer-left* *dialog-outer-top* overall-width overall-height ) )) ) ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog)) (defun prompt-user (&key (result-type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "Cancel") (left 10) (top 10) width (height 100)) (declare (ignore left top width height)) ;17oct2023 ;; Make the dialog itself (let* ((a-dialog (create-prompt-user ;:result-type result-type ;:read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text ))) ;; Show the completed dialog (cg::pop-up-modal-dialog a-dialog) (let ((cancel-v (cg::value (cg::find-component :cancel-d a-dialog) )) (select-v (cg::value (cg::find-component :resp-d a-dialog) )) ) (if cancel-v (abort) (let* ((result select-v)) (setf result (case read-type (:string result) (:eval (eval (read-from-string result :preserve-whitespace t))) (:read (read-from-string result :preserve-whitespace t)) ) ) (if (typep result result-type) result (quail-error "~S is not of type ~s" result result-type))) ))) ) (defun save-value (arg) "Saves the value of arg as the value of a symbol retrieved from a prompt." (eval `(setf ,(prompt-user :read-type :read :result-type 'symbol :prompt-string "Give a symbol to store the value on:") ,arg))) (defun prompt-t-or-f (message &key (true-text "Yes") (false-text "No") (cancel-text "Cancel")) "Prompts the user to choose between two alternatives ~ (true-text and false-text) in response to the information ~ given in message. T is returned if the first letter ~ of the true-text (default the string Yes) is typed by the ~ user; NIL if the first letter of the false-text is typed. ~ If cancel-text is selected, processing stops." (let* ((answer (cg::ask-user-for-choice message true-text false-text cancel-text))) (cond ((eq answer true-text) T) ((eq answer false-text) NIL) ((eq answer cancel-text) NIL)))) (defun prompt-true-or-false (message &key (true-text "Yes") (false-text "No") (cancel-text "Cancel")) "Prompts the user to make a decision between two alternatives (true-text and false-text) ~ in response to the information given in message. T is returned if the ~ true-text (default the string Yes) is typed by the user; NIL is returned if the ~ false-text (default the string No) is typed by the user. ~ If cancelled by the user, processing ends. ~ (:see-also prompt-for-items pick-one prompt-t-or-f)" (prompt-t-or-f message :true-text true-text :false-text false-text :cancel-text cancel-text)) (defun prompt-for-items (list &key (prompt-text "Choose") (item-function NIL) (selection-type :single)) (declare (ignore selection-type)) "Prompts user to select one or more items from the list. ~ Prompt-text is displayed to help the user choose. ~ Selection-type is one of :single (indicating only a single item ~ can be selected), :contiguous (indicating only contiguous items ~ can be selected), and :disjoint (indicating that any subset of the items ~ can be selected). It returns a list of all items selected, NIL if no items ~ were selected. ~ Item-print-function is the function called on each item to display it in ~ selection table. ~ (:see-also pick-one prompt-t-or-f)" (process-multi-dialog list :prompt-text prompt-text :item-print-function item-function ))
22,269
Common Lisp
.l
427
30.192037
129
0.424408
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c85ae46c5b580cf7c9fc4b09f0538d21934f65c6f9b2796961372770e1f264c1
33,591
[ -1 ]
33,592
prompt-sblx.lsp
rwoldford_Quail/source/window-basics/prompt/prompt-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; prompt-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; Authors: ;;; Greg Anglin 1991 ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996-1997, 2020 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; This holds the building, creation, and processing ;;; of multi-item-lists all of which are needed for ;;; prompt-user files. They are here because of the ;;; limitation on ACL/PC's edit buffer!! ;;; ;;; G.W.Bennett January 24 1997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(prompt-user save-value prompt-t-or-f prompt-true-or-false prompt-for-items))) ;;; an application frame to do the prompting (define-application-frame frame-which-accepts-values () ((accepted-value :initform nil :accessor accepted-value) (result-type :initarg :result-type :accessor result-type) (read-type :initarg :read-type :accessor read-type) (prompt-string :initarg :prompt-string :accessor prompt-string) (ok-text :initarg :ok-text :accessor ok-text) (cancel-text :initarg :cancel-text :accessor cancel-text)) (:panes (accept :application :display-function (lambda (frame pane) (terpri pane) (terpri pane) (format pane "Accepted object is is: ~s~%" (accepted-value frame)) (terpri pane) (with-output-as-gadget (pane) (make-pane :push-button :label "Accept object !" :activate-callback (lambda (gadget) (terpri pane) (setf (accepted-value frame) (accepting-values (stream :own-window t :width 300 :height 150 :label "Please enter your selection") (fresh-line stream) (accept (result-type *application-frame*) :prompt "An object " :stream stream))) (terpri pane) (redisplay-frame-pane frame pane) ))) )) (prompt-pane (make-pane 'clim-stream-pane :height 30 :scroll-bars nil :display-time t :display-function #'(lambda (frame pane) (draw-text* pane (prompt-string *application-frame*) 10 25 :ink +blue+ :text-size 18)) )) ) (:layouts (default (vertically (:height 200 :width 250) prompt-pane accept (horizontally () +fill+ (make-pane 'push-button :label (string-upcase (ok-text *application-frame*)) :activate-callback (lambda (ignore) ignore (frame-exit *application-frame*))) (make-pane 'push-button :label (string-upcase (cancel-text *application-frame*)) :activate-callback (lambda (ignore) ignore (frame-exit *application-frame*)))) )))) ;;; prompt-user itself (defun prompt-user (&key (result-type 'string) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "Cancel") left top width (height 100)) "Prompts user for input. ~ (:key ~ (:arg Prompt-string NIL The string used to query the user.) ~ (:arg initial-string \"\" Appears to the user as the default answer.) ~ (:arg ok-text \"OK\" String used to prompt user for confirmation.) ~ (:arg cancel-text \"Cancel\" String used to prompt user for cancellation.) ~ (:arg result-type T Data type of item to be returned by user. Any Common Lisp ~ data-type is acceptable.) ~ (:arg read-type :string How to read the typed input. ~ Legal values are :string :eval or :read.) ~ (:arg left NIL Location of the left of the prompt window.) ~ (:arg top NIL Location of the top of the prompt window.) ~ (:arg width NIL Width of prompt window.) ~ (:arg height 100 Height of prompt window.) ~ )" (let ((frame (make-application-frame 'frame-which-accepts-values :pretty-name "Your input .." :result-type result-type :read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text :left left :top top :width width :height height))) (run-frame-top-level frame) (return-from prompt-user (accepted-value frame)))) ;;; save-vaalue (defun save-value (arg) "Saves the value of arg as the value of a symbol retrieved from a prompt." (eval `(setf ,(prompt-user :read-type :read :result-type 'symbol :prompt-string "Give a symbol to store the value on:") ,arg))) ;;; prompt-t-or-f (defun prompt-t-or-f (message &key (true-text "Yes") (false-text "No") (cancel-text "Cancel")) "Prompts the user to make a decision between two alternatives (true-text and false-text) ~ in response to the information given in message. T is returned on pressing the button with label ~ true-text (default the string Yes) ; NIL is returned on pressing the button with label ~ false-text (default the string No). ~ If cancelled by the user, processing ends. ~ (:see-also prompt-for-items pick-one prompt-true-or-false)" (let ((frame (make-application-frame 'prompt-t-or-f :pretty-name "Please check your response" :message message :true-text true-text :false-text false-text :cancel-text cancel-text))) (run-frame-top-level frame) (return-from prompt-t-or-f (frame-result frame)))) ;;; and its application frame (define-application-frame prompt-t-or-f () ((frame-result :initform nil :accessor frame-result) (message :initarg :message :accessor message) (true-text :initarg :true-text :accessor true-text) (false-text :initarg :false-text :accessor false-text) (cancel-text :initarg :cancel-text :accessor cancel-text)) (:menu-bar nil) (:panes (prompt-pane (make-pane 'clim-stream-pane :height 30 :scroll-bars nil :display-time t :display-function #'(lambda (frame pane) (draw-text* pane (message *application-frame*) 10 25 :ink +blue+ :text-size 18)) ))) (:layouts (default (vertically (:height 100 :width 350) prompt-pane (horizontally () +fill+ (make-pane 'push-button :label (string-upcase (true-text *application-frame*)) :activate-callback (lambda (ignore) ignore (setf (frame-result *application-frame*) T) (frame-exit *application-frame*)) ) (make-pane 'push-button :label (string-upcase (false-text *application-frame*)) :activate-callback (lambda (ignore) ignore (setf (frame-result *application-frame*) NIL) (frame-exit *application-frame*))) (make-pane 'push-button :label (string-upcase (cancel-text *application-frame*)) :activate-callback (lambda (ignore) ignore (frame-exit *application-frame*))) ))))) ;;; prompt-true-or-false (defun prompt-true-or-false (message &key (true-text "Yes") (false-text "No") (cancel-text "Cancel")) "Prompts the user to make a decision between two alternatives (true-text and false-text) ~ in response to the information given in message. T is returned if the ~ true-text (default the string Yes) is typed by the user; NIL is returned if the ~ false-text (default the string No) is typed by the user. ~ If cancelled by the user, processing ends. ~ (:see-also prompt-for-items pick-one prompt-t-or-f)" (prompt-t-or-f message :true-text true-text :false-text false-text :cancel-text cancel-text)) ;;; prompt-for-items (defun prompt-for-items (list &key (prompt-text "Choose") (item-function NIL) (selection-type :single)) "Prompts user to select one or more items from the list. ~ Prompt-text is displayed to help the user choose. ~ Selection-type is one of :single (indicating only a single item ~ can be selected), :contiguous (indicating only contiguous items ~ can be selected), and :disjoint (indicating that any subset of the items ~ can be selected). It returns a list of all items selected, NIL if no items ~ were selected. ~ Item-print-function is the function called on each item to display it in ~ selection table. ~ (:see-also pick-one prompt-t-or-f)" (if (functionp item-function) (cond ((eql selection-type :single) (pick-one list :prompt-text prompt-text)) ((eql selection-type :disjoint) (check-items list :prompt-text prompt-text)) ((eql selection-type :contiguous) (check-items list :prompt-text "For contiguous selection , hold down shift-key")))))
10,131
Common Lisp
.l
228
34.640351
175
0.57524
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
d5d38c7fc24eac567bd59ff63fa32d0ad69ddd42839d6e5d514a7bdc9afdf063
33,592
[ -1 ]
33,594
new-code-fragment.lsp
rwoldford_Quail/source/window-basics/prompt/new-code-fragment.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; new-code-fragment.lsp ;;; ;;; derived from code-fragment.lsp ;;; and some attempts to simplify ;;; the building, creating, processing of dialogs ;;; notable through the separation of values ;;; which structure elements from their building ;;; ;;; Started 18 JAN 2005 GWB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; start with some bits from code-fragment (defun how-many (char string) "Counts the number of occurrences of char in string" (- (length string) (length (remove-if #'(lambda (x) (eq x char)) string)))) (defun list-of-lengths (string) ;; Assume string does *not* start with ~% ;; Gets a list of the stream-string-width of the ;; text bits of string (let ((result '()) (fmat (list #\~ #\% #\Newline)) (alphabet (list #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\Space #\. #\, #\; #\: #\( #\))) ) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) (do ((j 0 (+ j 1)) (n (how-many #\Newline string))) ((= j n)) (setf string (string-left-trim fmat (string-left-trim alphabet string))) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) ) result)) (defun max-text-segment (lengths) " Gets the length of the maximum text segment~ from a collection of cumulative lengths of a piece~ of text assumed to have come from list-of-lengths." (let ((diffs '())) (do ((j 0 (+ j 1)) (n (length lengths))) ((= j (- n 1))) (push (- (elt lengths j) (elt lengths (+ j 1))) diffs)) (cond ((eq 1 (length lengths)) (first lengths)) (T (abs (first (sort diffs #'<)))) ) )) ;;; And now a form to set some of those structural pieces (defun set-dialog-forms () (let* ((displayed 5) (scroll-bar-width 25) (seq-height 200) (seq-width 200) (dialog-outer-left 10) (min-separator 15) (dialog-outer-top 10) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (button-height (+ 2 text-height)) (prompt-box-height (+ 10 (* 1 text-height))) (text-width #'(lambda (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))))) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) ) (list text-width displayed scroll-bar-width seq-height seq-width dialog-outer-left dialog-outer-top min-separator temp-font-info text-height button-height prompt-box-height button-width) )) ;;; I *think* these are all the universal things I can deal with here. ;;; In this syntax I shall have to (funcall (car (set-dialog-forms) string-needing-width)) ;;; If I write (twtmp (defun text-width (string) ktl) ;;; then I can call text-width normally. ;;; Now I can rewrite build-multi-dialog-items
4,052
Common Lisp
.l
96
32.28125
92
0.508736
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ea6d84fc9c48719406ed4a915c646dd02c668d69ce45308a2573c3e5af995f0d
33,594
[ -1 ]
33,597
collect-input-sblx.lsp
rwoldford_Quail/source/window-basics/prompt/collect-input-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; collect-input-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996-1997, 2020 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(collect-input))) ;;; a function needed in collect-input (defun copy-update-list (list1 list2) "returns a copy of list1 with updated cdrs from list2 when the list2 element is not a seimcolon as a string" (let ((copy-list1 (copy-tree list1))) (dolist (x list2) (unless (string-equal x ";") (setf (cdr (elt copy-list1 (position x list2))) x))) (return-from copy-update-list copy-list1))) ;;; The querying function which needs a clim-listener to run ;;; but isn't used 12JAN2021 #| (defun accepting-tag (item &key (stream *query-io*) (ow t)) "item is a cons of two strings" (accepting-values (stream :initially-select-query-identifier 'the-tag :own-window ow) (terpri stream) (terpri stream) (accept 'string :prompt "A string" :stream stream) )) |# ;;; collect-input itself (defun collect-input (items &key (columns 1) (prompt-text "Please enter responses ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel") (stream *query-io*) (ow t)) (declare (ignore columns item-print-function action-function select-text cancel-text)) (let* ((result-list ())) (dolist (x items) (accepting-values (stream :initially-select-query-identifier 'the-tag :own-window ow :label prompt-text :height 250 :width 350) ;(terpri stream) (format stream "~%Asking for ~s , currently ~s " (car x) (cdr x)) (format stream "~%To accept the current value, enter ; ") (terpri stream) (push (accept 'string :prompt (first x) :stream stream) result-list) ) (setf result-list (remove-if #'NULL result-list)) ) (return-from collect-input (copy-update-list items (reverse result-list))) ))
2,714
Common Lisp
.l
58
40.017241
123
0.561251
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bb108ef07f39fb405145a9236a2f30d7e7af85e347519fc0e22f65ff3afc8de7
33,597
[ -1 ]
33,599
prompt-user-expts-log.lsp
rwoldford_Quail/source/window-basics/prompt/prompt-user-expts-log.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; prompt-user-expts-log.lsp ;;; started 18oct2005 ;;; holding a log of the experiments ;;; code for which is in prompt-user-expts.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;[1] package stuff OK ; cut+paste build-prompt-user and execute it - OK fn defined ; cut+paste create-prompt-user and execute it - OK fn defined ; cut+paste prompt-user and execute it - OK fn defined ; create *element4* ;#<MULTI-ITEM-LIST CG.ITEM-LIST:MULTI-ITEM-LIST @ #x20c6034a> - ok ; create *select4* ;#<STATIC-TEXT CG.STATIC-TEXT:STATIC-TEXT @ #x20ccc532> - ok ; use make-window to show this ;#<DIALOG #:G829 in Listener 1 @ #x20bd83b2> - ok ; highlight Second and hit Select ;* Error: #<Interpreted Function (unnamed) @ #x20c86f92> got 2 args, wanted 0 args. ;* [condition type: PROGRAM-ERROR] ; this has to do with on-click - redefined the lambda to have 2 args - why ? ; highlight Second and hit Select ; Results is ("Second") - which is good. Note that there is no difficulty ; in closing the dialog and then re-defining it. ; The dialog does not close automatically at the moment. ; auxilairy functions from prompt-pc.lsp ; HOW-MANY, LIST-OF-LENGTHS, MAX-TEXT-SEGMENT - ok ; execute build-prompt-user ; WB(27): (build-prompt-user) ;* (149 194 #<STATIC-TEXT :TEXT-D @ #x20ce80e2> ;* #<EDITABLE-TEXT :RESP-D @ #x20ce913a> #<BUTTON :SELECT-D @ #x20ce9f4a> ;* #<CANCEL-BUTTON :CANCEL-D @ #x20ce946a>) ; which should match ; (list overall-width overall-height text-dialog response-dialog select-button cancel-button) ; and seems to do so while first -> sixth returns the items :execute create-prompt-user ;WB(41): (create-prompt-user) ;* Error: attempt to call `CANVAS-FONT-TO-HOST-FONT' which is an undefined ;* function. ;* [condition type: UNDEFINED-FUNCTION] ; so we probably need to get all of Quail to try this out since there are just too many ; bits and pieces missing - indeed: this fn is in fonts.lsp and it calls some :h-draw ; stuff. ; Try this (cg::make-window (gensym) :class 'cg::dialog :owner (cg::development-main-window cg::*system*) :title "A Prompt Dialog 1" :visible-box (cg::make-box 0 0 150 200) :widgets (cddr (build-prompt-user))) ; it does produce a dialog ; the buttons don't respond since there are no :on-click functions associated ; with the widgets ; put an on-click in cancel-button to abort if checked ; I now get a reaction but the dialog does not automatically close. ; Comment out create-prompt-user, redefine prompt-user itself ; without the :on-click stuff for now to see whether things are carried through. ; After lunch with DMJ, I think.
2,745
Common Lisp
.l
57
45.578947
94
0.691673
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
bb6fdcf05e51f0cefc5eac9e98c65770680dbf53465a18f84777d99487a14267
33,599
[ -1 ]
33,600
dialog-items-pc.lsp
rwoldford_Quail/source/window-basics/prompt/dialog-items-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog-items-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; Authors: ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996, 2023 (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog items in ACL-PC are used. ;;; But the following form is called in canvas-to-ps.lsp ;;; ACL doesn't need to re-enable the menubars. (defun re-enable-menubars (&rest whatever) (declare (ignore whatever))) ;;; Many characteristics of Quail's acl dialogs are common to all of them, for example: ;;; dialog-outer-left - the position of the left margin of the dialog box on the screen ;;; dialog-outer-top - the position of the top of the dialog box on the screen ;;; They are collected here ;;; Others depend on the structure of the individual dialog ;;; prompt-text-width - depends of the particular prompt ;;; They are defined in the appropriate file (defparameter *dialog-outer-left* 10) ;; left of window-exterior of whole dialog on the screen (defparameter *dialog-outer-top* 10) ;; top of window-exterior of whole dialog on the screen (defparameter *scroll-bar-width* 25) ;; a guess at this (defparameter *min-separator* 15) ;; distance between widgets (H and V) (defparameter *displayed* 5) ;; Number of items visible (defparameter *temp-font-info* (let ((scrn (cg::screen cg::*system*)) (a-font (cg::make-font :roman "times\ new\ roman" 20);(wb::canvas-font-to-host-font wb::*prompt-normal-font*) )) (cg::with-font (scrn a-font) (cg::fontmetrics scrn)))) ;; the various characteristics of *prompt-normal-font* .. ascent, descent, etc.. (defparameter *text-height* (+ (cg::font-ascent *temp-font-info*) (cg::font-descent *temp-font-info*) (cg::font-leading *temp-font-info*))) (defparameter *text-box-height* (+ 10 *text-height*)) (defparameter *button-height* (+ 2 *text-height*)) (defparameter *select-text* "select") (defparameter *cancel-text* "cancel") (defparameter *ok-text* "OK") ;;; new auxiliary form to get string-width (defun quail-string-width (an-input) "Returns string width for *prompt-normal-font* on screen" (let ((scrn (cg::screen cg::*system*)) (coming (if (stringp an-input) an-input (format NIL "~s" an-input)))) (cg::with-font (scrn (cg::make-font :roman "times\ new\ roman" 20);(canvas-font-to-host-font *prompt-normal-font*) ) (cg::stream-string-width scrn coming)) ))
2,845
Common Lisp
.l
52
49.307692
126
0.589734
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b581bd1bdfe9a0c0240a0f3bab8de11ce30b1a209573197c795071cf05308665
33,600
[ -1 ]
33,606
dialogs70.lsp
rwoldford_Quail/source/window-basics/prompt/dialogs70.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialogs70.lsp ;;; with a copy of the example coed from acl62 ;;; 14JAN2005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; START OF ACL62 CODE (defparameter *text-item* (make-instance 'static-text :left 10 :top 50 :width 90 :height 20 :value 0)) (defparameter *scroll-bar1* (make-instance 'horizontal-scroll-bar :left 10 :top 10 :width 90 :height 16 :range '(0 100) :value 0 :on-change 'set-text-item-too ;; :increment is the amount stepped by a click in on ;; of the arrows :increment 10 :delayed nil)) (defparameter *scroll-bar2* (make-instance 'horizontal-scroll-bar :left 10 :top 30 :width 90 :height 16 :value 0 :range '(0 10) :on-change 'set-text-item-too :delayed nil)) (defun set-text-item-too (item new-value old-value) (setf (value *text-item*) (+ (value *scroll-bar1*) (value *scroll-bar2*)))) ;;;; now create the dialog (make-window :example-dialog :class 'dialog :owner (development-main-window *system*) :title "Example" :visible-box (make-box 0 0 110 80) :widgets (list *scroll-bar1* *scroll-bar2* *text-item*)) ;;; END OF ACL62 CODE (defparameter *element4* (make-instance 'multi-item-list :left 10 :top 10 :width 190 :height 160 :range (list "First" "Second" "Third") )) ;; ok (defparameter *select4* (make-instance 'static-text :left 10 :top 200 :width 150 :height 30 :value "Select" :on-click #'(lambda (x y) (format t "Results! ~s" (selected-object *element4*)))) ) ;; ok ;; create this (make-window :example-dialog :class 'dialog :owner (development-main-window *system*) :title "ZOT" :visible-box (make-box 0 0 300 200) :widgets (list *element4* *select4*)) ;; This returns ("Second") when Second is selected and Select is clicked!!
2,003
Common Lisp
.l
59
28.271186
76
0.589757
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f9c680df1788cff6f3b5958e15483ba2951ab1a76e7522ca97794d98093f58d9
33,606
[ -1 ]
33,607
pick-one-sblx.lsp
rwoldford_Quail/source/window-basics/prompt/pick-one-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; pick-one-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996-1997, 2020 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pick-one))) ;;; pipck-one itself (defun pick-one (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "cancel")) "returns a single cons cell from items through the matching application-frame" (let ((frame (make-application-frame 'pick-one :pretty-name prompt-text :prompt-text prompt-text :items items :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text))) (run-frame-top-level frame) (return-from pick-one (frame-result frame)))) ;;; the matching application frame (define-application-frame pick-one () ((frame-result :initform nil :accessor frame-result) (items :initarg :items :accessor items) (prompt-text :initarg :prompt-text :accessor prompt-text) (item-print-function :initarg :item-print-function :accessor item-print-function) (action-function :initarg :action-function :accessor action-function) (select-text :initarg :select-text :accessor select-text) (cancel-text :initarg :cancel-text :accessor cancel-text) ) (:menu-bar nil) (:panes (prompt-pane (make-pane 'clim-stream-pane :height 30 :scroll-bars nil :display-time t :display-function #'(lambda (frame pane) (draw-text* pane (prompt-text *application-frame*) 10 25 :ink +blue+ :text-size 18)) ;'draw-pick-one-prompt-text )) (options (make-pane 'list-pane :items (items *application-frame*) :name-key #'car ))) (:layouts (default (vertically (:height 300 :width 350) prompt-pane (horizontally () (labelling (:label "Options") (scrolling () options))) (horizontally () +fill+ (make-pane 'push-button :label (string-upcase (select-text *application-frame*)) :activate-callback (lambda (ignore) ignore (setf (frame-result *application-frame*) (gadget-value options)) ;(format t " pick-one (gadget-value options) returns ~s ~%" (gadget-value options)) (frame-exit *application-frame*)) ) (make-pane 'push-button :label (string-upcase (cancel-text *application-frame*)) :activate-callback (lambda (ignore) ignore (frame-exit *application-frame*))) )))))
3,461
Common Lisp
.l
80
34.625
143
0.556838
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
6163a13c92cde9a22ffb019882bed430a6a77ae4aa440f76b5bc0a4bbc1c78f1
33,607
[ -1 ]
33,608
prompt-user-expts.lsp
rwoldford_Quail/source/window-basics/prompt/prompt-user-expts.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; prompt-user-expts.lsp ;;; started 18oct2005 ;;; to try to get the prompt-user stuff to function correctly ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; define a temporary version of :wb (defpackage "WINDOW-BASICS" (:use "COMMON-LISP") (:nicknames "WB")) (in-package :wb) ;;;; I need the auxiliary functions at the top of prompt-pc.lsp (defun how-many (char string) "Counts the number of occurrences of char in string" (- (length string) (length (remove-if #'(lambda (x) (eq x char)) string)))) (defun list-of-lengths (string) ;; Assume string does *not* start with ~% ;; Gets a list of the stream-string-width of the ;; text bits of string (let ((result '()) (fmat (list #\~ #\% #\Newline)) (alphabet (list #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\Space #\. #\, #\; #\: #\( #\))) ) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width scrn string))) result) (do ((j 0 (+ j 1)) (n (how-many #\Newline string))) ((= j n)) (setf string (string-left-trim fmat (string-left-trim alphabet string))) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width scrn string))) result) ) result)) (defun max-text-segment (lengths) " Gets the length of the maximum text segment~ from a collection of cumulative lengths of a piece~ of text assumed to have come from list-of-lengths." (let ((diffs '())) (do ((j 0 (+ j 1)) (n (length lengths))) ((= j (- n 1))) (push (- (elt lengths j) (elt lengths (+ j 1))) diffs)) (cond ((eq 1 (length lengths)) (first lengths)) (T (abs (first (sort diffs #'<)))) ) )) ;;;; Here is the code from prompt-pc.lsp ;;;; First build-prompt-user (defun build-prompt-user (&key (type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "cancel") left top width (height 100) ) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width scrn string)))) (set-view-size (a-window) (list (cg::exterior-width a-window) (cg::exterior-height a-window)))) (let* ((scrn (cg::screen cg::*system*)) (view-font ;(let ((scrn (cg::screen cg::*system*))) 17oct05 (cg::with-device-context (hdc scrn) (cg::font scrn))) (dialog-outer-left 10) (dialog-outer-top 10) (min-separator 15) ;; minimum distance between boxes (response-width 100) ;; width of editable-text boxes ;(prompt-text-width (text-width prompt-text)) (prompt-text-width (max-text-segment (list-of-lengths prompt-string))) ;<< (temp-font-info ;(let ((scrn (cg::screen cg::*system*))) 17oct05 (cg::with-device-context (hdc scrn) (cg::fontmetrics scrn))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 prompt-text-width )) (text-box-height (+ 10 text-height)) ;<< (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-string)) text-height))) ;<< (text-box-x 20) (text-box-y 20) (button-height (+ 2 text-height)) (button-width (+ 5 (max (text-width ok-text) (text-width cancel-text)))) (seq-height 200) (seq-width 200) ;; The following are set AFTER text-dialog ;; (first-item-y (+ text-box-y text-box-height )) ;; (first-item-x dialog-outer-left ) ;; (button-x (+ 50 first-item-x (* columns col-width))) ;; (view-size-width (max 200 ;; (+ button-x button-width 2) ;; (+ text-box-x text-box-width 2))) ;; (view-size-height (max 100 ;; (+ first-item-y ;; (+ 2 (* (+ nrows 1) text-box-height)) ;; 2) ;; (+ text-box-height ;; button-height ;; 2))) ;; make the prompt stuff (text-dialog ;(cg::make-dialog-item :widget 'cg::static-text 17oct05 (make-instance 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-string) ;<< :name :text-d) ) ;; prompt stuff done ;; Now set the top of the first item (first-item-y (cg::bottom (cg::box text-dialog))) ;;; Make the response-dialog (response-dialog ;(cg::make-dialog-item :widget cg::'editable-text 17oct05 (make-instance 'cg::editable-text :value initial-string :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ first-item-y min-separator) (max response-width prompt-text-width) text-box-height) :name :resp-d)) ;;; Find two values needed for later sizing and positioning (rightmost (cg::right (cg::box response-dialog))) (collect-bottom (cg::bottom (cg::box response-dialog))) ;; cancel begins (cancel-button ;(cg::make-dialog-item :widget cg::'cancel-button 17oct05 (make-instance 'cg::cancel-button :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ collect-bottom min-separator) button-width button-height) :title cancel-text :name :cancel-d :on-click #'(lambda (x y) ;18oct05 (abort)) ;18oct05 )) (cancel-bottom (cg::bottom (cg::box cancel-button))) ;; cancel done ;; make select stuff (select-button ;(cg::make-dialog-item :widget cg::'button 17oct05 (make-instance 'cg::button :box (cg::make-box-relative (+ (cg::right (cg::box cancel-button)) min-separator) (+ collect-bottom min-separator) button-width button-height) :title ok-text :name :select-d :set-value-fn #'(lambda (&rest args) (values t t)) )) (select-bottom (cg::bottom (cg::box select-button))) ;; select done ;; compute overall sizes (overall-width (+ min-separator (max (cg::right (cg::box text-dialog)) (cg::right (cg::box response-dialog)) (cg::right (cg::box select-button)) (cg::right (cg::box cancel-button))))) (overall-height (+ (* 4 min-separator) cancel-bottom )) ) ;; end of bindings in let* .. body follows ;; return some sizes and the dialogs (list overall-width overall-height text-dialog response-dialog select-button cancel-button) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;;;; .. then create-prompt-user (defun create-prompt-user (&key (type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "cancel") left top width (height 100) ) (let* ((list-of-dialog-items (build-prompt-user :type type :read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text :left left :top top :width width :height height)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font scrn)))) (dialog-outer-left 10) (dialog-outer-top 10) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list ;(cg::make-dialog-item :widget 'cg::button 17oct05 (make-instance 'cg::button :box (cg::make-box 20 20 20 20)) )) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Your input .." :pop-up-p t :font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top overall-width overall-height ) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ;; end of let* .. it returns an actual dialog ) ;;;; .. finally prompt-user itself (defun prompt-user (&key (type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "Cancel") left top width (height 100)) ;; Make the dialog itself (let* ((a-dialog (create-prompt-user :type type :read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text )) ;; Show the completed dialog (showit ;(cg::pop-up-dialog a-dialog) 18oct05 (cg::make-window (gensym) :class 'cg::dialog :owner (cg::development-main-window cg::*system*) :title "Choice Dialog" :visible-box (cg::box a-dialog) :widgets (cg::dialog-items a-dialog) )) (cancel-v (cg::dialog-item-value (cg::widget :cancel-d a-dialog))) (select-v (cg::dialog-item-value (cg::widget :resp-d a-dialog))) ) (if cancel-v (abort) ; was initial-string (let* ((result select-v)) (setf result (case read-type (:string result) (:eval (eval (read-from-string result :preserve-whitespace t))) (:read (read-from-string result :preserve-whitespace t)) ) ) (if (typep result type) result (quail-error "~S is not of type ~s" result type))) ) ) ;; end let* ) ;;;; Some code based on dialogs70.lsp (setf *element4* (make-instance 'cg::multi-item-list :left 10 :top 10 :width 190 :height 100 :range (list "First" "Second" "Third") )) (setf *select4* (make-instance 'cg::static-text :left 10 :top 120 :width 190 :height 30 :value "Select" :on-click #'(lambda (x y) (format t "Results is ~s" (cg::selected-object *element4*))) )) (cg::make-window (gensym) :class 'cg::dialog :owner (cg::development-main-window cg::*system*) :title "DIALOG 1" :visible-box (cg::make-box 0 0 200 160) :widgets (list *element4* *select4*))
15,717
Common Lisp
.l
323
27.674923
99
0.398246
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b572cdd65975cd264e6b8c4fdb39f022e531742e6cab9b4a119fa8cf569cee85
33,608
[ -1 ]
33,611
pick-one-pc.lsp
rwoldford_Quail/source/window-basics/prompt/pick-one-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; pick-one-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- ;;; pick-one expects items to be a list of strings. ;;; it returns the selected string or NIL if Cancel was clicked. (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pick-one))) ;; Build the list of dialog-items (defun build-single-dialog-items (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "cancel")) (declare (ignore action-function)) (flet ((text-width (string) (quail-string-width string)) ) (let* (;(*scroll-bar-width* 25) ;; a guess at this ;(*min-separator* 15) ;; distance between widgets H and V ;(*displayed* 5) ;; Number of items visible (max-item-width (reduce #'max (mapcar #'(lambda (x) (quail-string-width x)) items))) (error-text "please choose an item first!") (error-text-width (text-width error-text)) (prompt-text-width (text-width prompt-text)) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (*text-box-height* (+ 10 *text-height*)) (prompt-box-height (+ 10 *text-box-height*)) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) ;; make the prompt stuff (text-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (make-instance 'cg::static-text :box (cg::make-box-relative (+ *dialog-outer-left* *min-separator*) (+ *dialog-outer-top* *min-separator*) text-box-width *text-box-height*) :border :static :value error-text)) ;; error stuff done ;; seq-dialog should start here (seq-dialog (if (functionp item-print-function) (make-instance 'cg::single-item-list :range items :box (cg::make-box-relative (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) *min-separator* ) (+ max-item-width *scroll-bar-width*) (+ *min-separator* (* (min (length items) *displayed*) *text-height*))) :title "Pick one" :available-p T ) (make-instance 'cg::single-item-list :range items :box (cg::make-box-relative (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) *min-separator* ) (+ max-item-width *scroll-bar-width*) (+ *min-separator* (* (min (length items) *displayed*) *text-height*))) :title "Pick one" :available-p T ))) ;; seq-dialog should end here ;; cancel begins (cancel-button (make-instance 'cg::cancel-button :box (cg::make-box-relative (+ (cg::right (cg::box seq-dialog)) *min-separator*) (+ (cg::bottom (cg::box text-dialog)) *min-separator*) button-width *button-height*) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (make-instance 'cg::button :box (cg::make-box-relative (cg::left (cg::box cancel-button)) (+ (cg::bottom (cg::box cancel-button)) *min-separator*) button-width *button-height*) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not (cg::value seq-dialog) ) (cg::pop-up-message-dialog (cg::window seq-dialog) "Choose one ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t))) ) )) ) (list text-dialog error-dialog seq-dialog select-button cancel-button) ) ) ) ;; end of build-single-dialog-items ;; Now create the actual dialog from what build-.. produces (defun create-single-dialog (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "Cancel")) (let* ((list-of-dialog-items (build-single-dialog-items items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (text-dialog (first list-of-dialog-items)) (select-button (fourth list-of-dialog-items)) (cancel-button (fifth list-of-dialog-items)) (seq-dialog (third list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance 'cg::button :box (cg::make-box 20 20 20 20)) )) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Choose One .." :pop-up-p t :font (cg::make-font :roman "times\ new\ roman" 20);(canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative *dialog-outer-left* *dialog-outer-top* (+ (* 3 *min-separator*) (max (cg::right (cg::box text-dialog)) (cg::right (cg::box select-button)) (cg::right (cg::box cancel-button)))) (+ (* 3 *min-separator*) (max (cg::bottom (cg::box seq-dialog)) (cg::bottom (cg::box cancel-button))))) )) ;; End creation of empty base-dialog here ) ;; add new items (cg::update-dialog base-dialog list-of-dialog-items) base-dialog) ) ;; end of create-single-dialog ;; Now deal with the dialog (defun pick-one (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "Cancel")) ;; Make the dialog itself (let* ((a-dialog (create-single-dialog items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) ;(error-text "Please choose an item first!") ;; Show the completed dialog ;; Simply (cg::pop- ) does not work (clicked-button (cg::pop-up-modal-dialog a-dialog)) (d-items (mapcar #'cg::value (cg::dialog-items a-dialog))) (seq-v (third d-items)) ;(select-v (fourth d-items)) (cancel-v (fifth d-items))) (cond (cancel-v (abort)) (t seq-v)) )) ;; end process-single-dialog itself
11,541
Common Lisp
.l
202
30.90099
128
0.380284
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9893a6368f7f13dcaeb23f9e383976c430026fb8e795e0e5c781d67da9f85a00
33,611
[ -1 ]
33,612
prompt-utility-pc.lsp
rwoldford_Quail/source/window-basics/prompt/prompt-utility-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; prompt-utility-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- ;;; Two functions to deal with the layout of multi-line ;;; prompt-strings. (in-package :wb) (defun how-many (char string) "Counts the number of occurrences of char in string" (1+ (- (length string) (length (remove-if #'(lambda (x) (eq x char)) string))))) (defun list-of-lengths (string) ;; Assume string does *not* start with ~% ;; Gets a list of the stream-string-width of the ;; text bits of string (let ((result '()) (fmat (list #\~ #\% #\Newline)) (alphabet (list #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\Space #\. #\, #\; #\: #\( #\))) ) (push (cg::stream-string-width cg::*screen* string) result) (do ((j 0 (+ j 1)) (n (how-many #\Newline string))) ((= j n)) (setf string (string-left-trim fmat (string-left-trim alphabet string))) (push (cg::stream-string-width cg::*screen* string) result) ) result)) (defun max-text-segment (lengths) " Gets the length of the maximum text segment~ from a collection of cumulative lengths of a piece~ of text assumed to have come from list-of-lengths." (let ((diffs '())) (do ((j 0 (+ j 1)) (n (length lengths))) ((= j (- n 1))) (push (- (elt lengths j) (elt lengths (+ j 1))) diffs)) (cond ((eq 1 (length lengths)) (first lengths)) (T (abs (first (sort diffs #'<)))) ) ))
2,457
Common Lisp
.l
60
32.466667
86
0.452301
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ac54f37421ce10b8ffe7b0abbacbdb4b90da3913ebb41392be8f28fd1e393802
33,612
[ -1 ]
33,613
dialog-items-sblx.lsp
rwoldford_Quail/source/window-basics/prompt/dialog-items-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog-items-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; Authors: ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996, 2020 (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog items in ACL-PC are used. ;;; But the following form is called in canvas-to-ps.lsp ;;; ACL doesn't need to re-enable the menubars. (defun re-enable-menubars (&rest whatever) (declare (ignore whatever)))
722
Common Lisp
.l
16
44.0625
80
0.405941
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
13dcd428c166dc3b43c8c7e8e28f1f8a89cd167b31b07ec75dd32edf8df82504
33,613
[ -1 ]
33,615
code-fragment.lsp
rwoldford_Quail/source/window-basics/prompt/code-fragment.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; code-fragment.lsp ;;; holding ;;; code fragment which needs fixing ;;; it's from prompt-pc.lsp ;;; specifically, how do I talk about the offset ;;; originally computed by (cg::dialog-item-box of some item) ?? ;;; I think I shal try to build the stuff from prompt-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; This seems OK as a way to carry about functions too (defun one (x y) (let ((z (+ x y)) (w #'(lambda (w) (* w 3)))) (list z w))) (defun two (x y q) (list (funcall (second (one x y)) q) x y)) ;*CG-USER(81): (two 1 2 3) ;*(9 1 2) ;;;; ;;; We begin with some functions: (defun how-many (char string) "Counts the number of occurrences of char in string" (- (length string) (length (remove-if #'(lambda (x) (eq x char)) string)))) ;;OK[1] (defun list-of-lengths (string) ;; Assume string does *not* start with ~% ;; Gets a list of the stream-string-width of the ;; text bits of string (let ((result '()) (fmat (list #\~ #\% #\Newline)) (alphabet (list #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\Space #\. #\, #\; #\: #\( #\))) ) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) (do ((j 0 (+ j 1)) (n (how-many #\Newline string))) ((= j n)) (setf string (string-left-trim fmat (string-left-trim alphabet string))) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) ) result)) ;;OK[2] (defun max-text-segment (lengths) " Gets the length of the maximum text segment~ from a collection of cumulative lengths of a piece~ of text assumed to have come from list-of-lengths." (let ((diffs '())) (do ((j 0 (+ j 1)) (n (length lengths))) ((= j (- n 1))) (push (- (elt lengths j) (elt lengths (+ j 1))) diffs)) (cond ((eq 1 (length lengths)) (first lengths)) (T (abs (first (sort diffs #'<)))) ) )) ;;OK[3] ;;; here are some dialogs (setf seq-dialog (make-instance cg::'multi-item-list ;(cg::make-dialog-item :widget cg::'multi-item-list :range items :box (cg::make-box-relative ;(cg::box-left (cg::dialog-item-box text-dialog)) 10jan05 (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T ) ) ;; ok[27] ;; bit which found text-dialog too (setf text-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text 10jan05 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; ok[24] (setf error-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text 10jan05 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text));; ok[27] (setf cancel-button (make-instance ; (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ (cg::right (cg::box seq-dialog)) ;(cg::dialog-item-box seq-dialog)) min-separator) (+ (cg::bottom (cg::box seq-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; ok[28] (setf select-button (make-instance ;(cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (cg::left (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button)) (+ (cg::bottom (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not ;(cg::dialog-item-value seq-dialog) (cg::value (cg::dialog-item seq-dialog)) ) (cg::pop-up-message-dialog (cg::dialog-item-window seq-dialog) "You choose ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t))) ) )) ;; ok[29] ;; some things I need (setf displayed 5);; OK[4] (setf scroll-bar-width 25) ;; OK[5] (setf seq-height 200) ;; ok[6] (setf seq-width 200);; ok[7] (setf dialog-outer-left 10);; ok[8] (setf min-separator 15);; ok[9] (setf dialog-outer-top 10);; ok[10] (setf prompt-text "Here is a text-dialog");; ok[11] (setf select-text "Select");; ok[12] (setf cancel-text "Cancel");; ok[13] (setf error-text "please choose an item first!");; ok[14] (setf temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*)))));; ok[15] (setf text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) ;; 19 ok[16] (setf button-height (+ 2 text-height));; 21 ok[17] (setf prompt-box-height (+ 10 (* 1 text-height)));; 29 ok[18] (defun text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)))) ;; ok[19] (setf button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) ;; 49 ok[20] (setf prompt-text-width (text-width prompt-text));; 131 ok[21] (setf text-box-width (+ 5 prompt-text-width ));; 136 ok[22] ;; result from (setf text-dialog etc) from above ;; text-dialog is, then: ;#<STATIC-TEXT STATIC-TEXT @ #x20ccc752> ;(dialog-item-p text-dialog) ;;(window text-dialog) (box text-dialog) ;(setf text-dialog-box (box text-dialog)) ;(left text-dialog-box) ;; Sooo, dialogs do have boxes obtained by (box dialog) ;; and then I can ask for left, etc.. ;;;; 11jan05 more things needed to get values correct (setf items (list "First" "Second" "Third"));; ok[23] ;; make the dialogs: text-dialog ;; ok[24 above] ;; need this for error-dialog (setf text-box-height (+ 10 text-height));; 29 ok[25] ;; error-dialog ;; ok[26 above] ;; need this for seq-dialog -- NOTE it uses items defined in [23] (setf max-item-width (first (sort (mapcar #'(lambda (x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) x)))) items) #'>)));; 48 ok[26] ;; seq-dialog ;; ok[27above] ;; cancel-button ;; ok[28above] ;; select-button ;; ok[29above] ;; what are its items ? (dialog-items seq-dialog) ;* = Error: No methods applicable for generic function ;* #<STANDARD-GENERIC-FUNCTION DIALOG-ITEMS> with args ;* (#<MULTI-ITEM-LIST MULTI-ITEM-LIST @ #x20b2918a>) of classes ;* (MULTI-ITEM-LIST) ;*[condition type: PROGRAM-ERROR] ;; so what does seq-dialog have ? (inspect seq-dialog) ;; ok ;* the list, which is items, is its range (range seq-dialog) ; ok ("First" "Second" "Third") ;* and the question is now: how do I get the returned value from a dialog ? ;* do I need the on-click funtion which works on a dialog-item ;;; Here is the form to build a multi-dialog (defun build-multi-dialog-items (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)))) (set-view-size (a-window) (list (cg::exterior-width a-window) (cg::exterior-height a-window)))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) ;; left of window-exterior of whole dialog (dialog-outer-top 10) ;; top of window-exterior of whole dialog (scroll-bar-width 25) ;; a guess at this (min-separator 15) ;; distance between widgets H and V (displayed 5) ;; Number of items visible (max-item-width (first (sort (mapcar #'(lambda (x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) x)))) items) #'>))) (error-text "please choose an item first!") (error-text-width (text-width error-text)) (prompt-text-width (text-width prompt-text)) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-text)) text-height))) (button-height (+ 2 text-height)) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) (seq-height 200) (seq-width 200) ;; make the prompt stuff (text-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text 10jan05 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (make-instance cg::'static-text ;(cg::make-dialog-item :widget 'cg::static-text 10jan05 :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text)) ;; error stuff done ;; seq-dialog should start here (seq-dialog (make-instance ;(cg::make-dialog-item :widget cg::'multi-item-list :range items :box (cg::make-box-relative ;(cg::box-left (cg::dialog-item-box text-dialog)) 10jan05 (cg::left (cg::box text-dialog)) (+ (cg::bottom (cg::box text-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T ) ) ;; seq-dialog should end here ;; cancel begins (cancel-button (make-instance ; (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ (cg::right (cg::box seq-dialog)) ;(cg::dialog-item-box seq-dialog)) min-separator) (+ (cg::bottom (cg::box seq-dialog)) ;(cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (make-instance ;(cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (cg::left (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button)) (+ (cg::bottom (cg::box cancel-button)) ;(cg::dialog-item-box cancel-button) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not ;(cg::dialog-item-value seq-dialog) (cg::value (cg::dialog-item seq-dialog)) ) (cg::pop-up-message-dialog (cg::dialog-item-window seq-dialog) "You choose ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t))) ) )) ;; select done ) ;; end of bindings in let* .. body follows (list text-dialog error-dialog seq-dialog select-button cancel-button) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;; end of build-multi-dilaog-items ;;; Here is the form to create a multi-dialog (defun create-multi-dialog (items &key (prompt-text "Please choose one or more ... ") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items ;(build-multi-dialog-items items ; :prompt-text prompt-text ; :item-print-function item-print-function ; :action-function action-function ; :select-text select-text ; :cancel-text cancel-text) (list text-dialog error-dialog seq-dialog select-button cancel-button) ) ;(view-font ; (let ((scrn (cg::screen cg::*system*))) ; (cg::with-device-context (hdc scrn) ; (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (scroll-bar-width 25) (min-separator 15) (text-dialog (first list-of-dialog-items)) (select-button (fourth list-of-dialog-items)) (cancel-button (fifth list-of-dialog-items)) (seq-dialog (third list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (make-instance ;cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "You choose .." :pop-up-p t ;:font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top (+ min-separator (max (cg::right (cg::box text-dialog) ;(cg::dialog-item-box text-dialog) ) (cg::right (cg::box select-button) ;(cg::dialog-item-box select-button) ) (cg::right cancel-button) ;(cg::dialog-item-box cancel-button) ))) (+ (* 4 min-separator) (max (cg::bottom (cg::box seq-dialog) ;(cg::dialog-item-box seq-dialog) ) (cg::bottom (cg::box cancel-button) ;(cg::dialog-item-box cancel-button) )))) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog list-of-dialog-items) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; ok[30] ;* I should setf something to this (setf dialog1 (create-multi-dialog items)) ;; ok[31] NOTE I have ;'d out the font stuff (dialogp dialog1);; T ok[31] (dialog-items dialog1) ; lots of stuff ;*(#<STATIC-TEXT STATIC-TEXT @ #x20a1ee5a> #<STATIC-TEXT STATIC-TEXT @ #x20a210d2> ;* #<MULTI-ITEM-LIST MULTI-ITEM-LIST @ #x20a207a2> #<BUTTON BUTTON @ #x20a2c05a> ;* #<CANCEL-BUTTON CANCEL-BUTTON @ #x20a208a2>) ;* Here is where I think I need to sort out the value bit ;; code to display this dialog (setf clicked-button (cg::pop-up-modal-dialog dialog1 :stream (cg::screen cg::*system*) :initial-focus NIL :bring-thread-to-front T));; ok[32] ;; there it is .. but when I select First and click Select I get: ;*Error: No methods applicable for generic function #<STANDARD-GENERIC-FUNCTION VALUE> ;*with args (NIL) of classes (NULL) ;*[condition type: PROGRAM-ERROR] ;* Clicking Cancel returns nil which is OK (fourth (dialog-items dialog1)); #<BUTTON BUTTON @ #x20a2c05a> (name (fourth (dialog-items dialog1))) ;NIL (first (dialog-items dialog1)); #<STATIC-TEXT STATIC-TEXT @ #x20a1ee5a> (name (first (dialog-items dialog1))) ;nil ;; here is process modified to swallow dialog1 (defun process-multi-dialog (items &key (prompt-text "Please choose one or more .. ") (item-print-function nil) (action-function #'identity) (select-text "select") (cancel-text "cancel")) ;; Make the dialog itself (let* ((new-items (cond ((functionp item-print-function) (setf new-items (mapcar item-print-function items))) ((null item-print-function) (setf new-items (mapcar #'(lambda (item) (format NIL "~s" item)) items))) (T items)) ) (a-dialog dialog1) (error-text "Please choose an item first!") ;; Show the completed dialog ;(clicked-button (cg::pop-up-dialog a-dialog)) 11jan05 (clicked-button (cg::pop-up-modal-dialog a-dialog :stream (cg::screen cg::*system*) :initial-focus NIL :bring-thread-to-front T)) ;;11jan05 (d-items (mapcar ;#'cg::dialog-item-value #'cg::value (cg::dialog-items a-dialog))) (seq-v (third d-items)) (select-v (fourth d-items)) (cancel-v (fifth d-items))) (cond (cancel-v (abort) ) (t (loop for item in items as new-item in new-items when (member new-item seq-v :test #'string-equal) collect (funcall action-function item)))) ) ;; end let* );; OK[33] (process-multi-dialog items) ;*Error: No methods applicable for generic function ;* #<STANDARD-GENERIC-FUNCTION VALUE> with args (NIL) of classes ;* (NULL) ;*[condition type: PROGRAM-ERROR] ;** I'm stuck - the dialog displays and Select kills things.
24,367
Common Lisp
.l
500
31.61
113
0.458725
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
f4f4b3acaa72ed70f6810ad1fb7ca163b9993255c15eec41600789728261e791
33,615
[ -1 ]
33,616
orig-check-items-pc.lsp
rwoldford_Quail/source/window-basics/prompt/orig2005/orig-check-items-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; check-items-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W.Bennett 1996-1997 ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(check-items))) ;; Build the necessary lists of dialog-items (defun build-check-dialog-items (items &key (prompt-text "Check one or more ...") (item-print-function nil) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel") (columns 1) ) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)) )) (set-view-size (a-window) (list (cg::width (cg::exterior a-window)) (cg::height (cg::exterior a-window))))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))) )) (dialog-outer-left 10) (dialog-outer-top 10) ; (scroll-bar-width 25) (min-separator 15) (check-allowance 10) (max-item-width (first (sort (mapcar #'(lambda (x) (if (stringp x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) x) (cg::stream-string-width (cg::screen cg::*system*) (format NIL "~s" x)))))) items) #'>))) (error-text "please choose an item first!") (error-text-width (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) error-text)))) (prompt-text-width (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) prompt-text)))) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-text)) text-height))) (text-box-x 20) (text-box-y 20) (button-height (+ 2 text-height)) (button-width (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (+ 5 (max (cg::stream-string-width (cg::screen cg::*system*) select-text) (cg::stream-string-width (cg::screen cg::*system*) cancel-text)))))) (seq-height 200) (seq-width 200) (n-items (length items)) (col-width (+ 15 max-item-width check-allowance)) (nrows (ceiling (/ n-items columns))) (first-item-y (+ text-box-y text-box-height)) (first-item-x dialog-outer-left ) (button-x (+ 50 first-item-x (* columns col-width))) (view-size-width (max 200 (+ button-x button-width 2) (+ text-box-x text-box-width 2))) (view-size-height (max 100 (+ first-item-y (+ 2 (* (+ nrows 1) text-box-height)) 2) (+ text-box-height button-height 2))) ;; make the prompt stuff (text-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text)) ;; error stuff done ;; check-dialog should start here ;;; TOP OF CODE FROM -mcl FILE (check-dialog (loop for item in items with y-start = first-item-y with x-start = first-item-x with row = 0 with col = 0 collect (cg::make-dialog-item :widget cg::'check-box :title item :box (cg::make-box-relative (+ x-start (* col col-width) min-separator) (+ y-start (* row text-box-height)) (+ min-separator max-item-width check-allowance) (+ min-separator text-box-height)) :available-p T ) do (cond ((>= row (1- nrows)) (incf col 1) (setq row 0)) (T (incf row 1)))) ) ;;; END OF CODE FROM -mcl FILE (height-item-box (cg::box-height (cg::dialog-item-box (first check-dialog)))) (width-item-box (cg::box-width (cg::dialog-item-box (first check-dialog)))) (rightmost (cg::box-right (cg::dialog-item-box (first (last check-dialog))))) ;; cancel begins (cancel-button (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ rightmost min-separator) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (+ rightmost min-separator) (+ (cg::box-bottom (cg::dialog-item-box cancel-button)) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (values t t)) )) ;; select done (overall-width (+ (* 4 min-separator) (* columns width-item-box) button-width)) (overall-height (+ (* 4 min-separator) (* nrows height-item-box) button-height)) ) ;; end of bindings in let* .. body follows (append (list overall-width overall-height text-dialog error-dialog) check-dialog (list select-button cancel-button)) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;; end of build-check-items ;; Create the dialog itself from what build produces (defun create-check-dialog (items &key (columns 1) (prompt-text "Choose one or more ...") (item-print-function NIL) (item-select-function #'(lambda (i) i)) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items (build-check-dialog-items items :columns columns :prompt-text :item-print-function item-print-function :action-function action-function prompt-text :select-text select-text :cancel-text cancel-text)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Choose One .." :pop-up-p t :font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top overall-width overall-height ) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; end of create-check-dialog ;; Now process the whole thing (defun check-items (items &key (columns 1) (prompt-text "Choose one or more ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) ;; Make the dialog itself (let* ((a-dialog (create-check-dialog items :columns columns :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text :prompt-text prompt-text)) ;; Show the completed dialog (showit (cg::pop-up-dialog a-dialog)) ;; Check on what is returned (d-items (cg::dialog-items a-dialog)) (t-items (mapcar #'cg::dialog-item-title d-items)) (v-items (mapcar #'cg::dialog-item-value d-items)) (n-items (length items)) (cancel-v (nth (+ 3 n-items) v-items)) (select-v (nth (+ 4 n-items) v-items))) (if cancel-v items (loop for x from 0 to (- n-items 1) collect (cons (nth (+ x 2) t-items) (nth (+ x 2) v-items))) ) ) ;; end let* ) ;; end check-items itself
13,280
Common Lisp
.l
247
32.493927
131
0.422814
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
c96248a4090e8a6bd6b8bafae229583f94b1567135c2bcba7f2844026dc172dc
33,616
[ -1 ]
33,617
orig-pick-one-pc.lsp
rwoldford_Quail/source/window-basics/prompt/orig2005/orig-pick-one-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; pick-one-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pick-one))) ;; Build the list of dialog-items (defun build-single-dialog-items (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)))) (set-view-size (a-window) (list (cg::width (cg::exterior a-window)) (cg::height (cg::exterior a-window))))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) ;; left of window-exterior of whole dialog (dialog-outer-top 10) ;; top of window-exterior of whole dialog (scroll-bar-width 25) ;; a guess at this (min-separator 15) ;; distance between widgets H and V (displayed 5) ;; Number of items visible (max-item-width (first (sort (mapcar #'(lambda (x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (if (stringp x) (cg::stream-string-width (cg::screen cg::*system*) x) (cg::stream-string-width (cg::screen cg::*system*) (format NIL "~s" x)))))) items) #'>))) (error-text "please choose an item first!") (error-text-width (text-width error-text)) (prompt-text-width (text-width prompt-text)) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-text)) text-box-height))) (button-height (+ 2 text-height)) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) (seq-height 200) (seq-width 200) ;; make the prompt stuff (text-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text)) ;; error stuff done ;; seq-dialog should start here (seq-dialog (if (functionp item-print-function) (cg::make-dialog-item :widget cg::'single-item-list :range items :box (cg::make-box-relative (cg::box-left (cg::dialog-item-box text-dialog)) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T ) (cg::make-dialog-item :widget cg::'single-item-list :range items :box (cg::make-box-relative (cg::box-left (cg::dialog-item-box text-dialog)) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T ))) ;; seq-dialog should end here ;; cancel begins (cancel-button (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ (cg::box-right (cg::dialog-item-box seq-dialog)) min-separator) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (cg::box-left (cg::dialog-item-box cancel-button)) (+ (cg::box-bottom (cg::dialog-item-box cancel-button)) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not (cg::dialog-item-value seq-dialog)) (cg::pop-up-message-dialog (cg::dialog-item-window seq-dialog) "Choose one ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t))) ) )) ;; select done ) ;; end of bindings in let* .. body follows (list text-dialog error-dialog seq-dialog select-button cancel-button) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;; end of build-single-dialog-items ;; Now create the actual dialog from what build-.. produces (defun create-single-dialog (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "Cancel")) (let* ((list-of-dialog-items (build-single-dialog-items items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (scroll-bar-width 25) (min-separator 15) (text-dialog (first list-of-dialog-items)) (select-button (fourth list-of-dialog-items)) (cancel-button (fifth list-of-dialog-items)) (seq-dialog (third list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Choose One .." :pop-up-p t :font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top (+ (* 3 min-separator) (max (cg::box-right (cg::dialog-item-box text-dialog)) (cg::box-right (cg::dialog-item-box select-button)) (cg::box-right (cg::dialog-item-box cancel-button)))) (+ (* 3 min-separator) (max (cg::box-bottom (cg::dialog-item-box seq-dialog)) (cg::box-bottom (cg::dialog-item-box cancel-button))))) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog list-of-dialog-items) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; end of create-single-dialog ;; Now deal with the dialog (defun pick-one (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "Select") (cancel-text "Cancel")) ;; Make the dialog itself (let* ((a-dialog (create-single-dialog items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (error-text "Please choose an item first!") ;; Show the completed dialog (clicked-button (cg::pop-up-dialog a-dialog)) (d-items (mapcar #'cg::dialog-item-value (cg::dialog-items a-dialog))) (seq-v (third d-items)) (select-v (fourth d-items)) (cancel-v (fifth d-items))) (cond (cancel-v (abort)) (t seq-v)) ; ) ;; end of let* ) ;; end let* ) ;; end process-single-dialog itself
13,259
Common Lisp
.l
229
34.056769
118
0.414466
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
35b8d25e20094caf9dd369d9db125872e211365fce3d60d2067896dbf554f54c
33,617
[ -1 ]
33,618
orig-dialog-items-pc.lsp
rwoldford_Quail/source/window-basics/prompt/orig2005/orig-dialog-items-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog-items-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; Authors: ;;; R.W. Oldford 1994 ;;; G.W. Bennett 1996 (in-package :wb) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; dialog items in ACL-PC are used. ;;; But the following form is called in canvas-to-ps.lsp ;;; ACL doesn't need to re-enable the menubars. (defun re-enable-menubars (&rest whatever) (declare (ignore whatever)))
729
Common Lisp
.l
16
43.5625
81
0.393557
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9d2d27c1ad3396fc20f964cd1771864b2e8d49ee30ca76a5037eaecd0a6b0f58
33,618
[ -1 ]
33,619
orig-prompt-pc.lsp
rwoldford_Quail/source/window-basics/prompt/orig2005/orig-prompt-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; prompt-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; Authors: ;;; Greg Anglin 1991 ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- ;;; ;;; This holds the building, creation, and processing ;;; of multi-item-lists all of which are needed for ;;; prompt-user files. They are here because of the ;;; limitation on ACL/PC's edit buffer!! ;;; ;;; G.W.Bennett January 24 1997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(prompt-user save-value prompt-t-or-f prompt-true-or-false prompt-for-items))) (defun how-many (char string) "Counts the number of occurrences of char in string" (- (length string) (length (remove-if #'(lambda (x) (eq x char)) string)))) (defun list-of-lengths (string) ;; Assume string does *not* start with ~% ;; Gets a list of the stream-string-width of the ;; text bits of string (let ((result '()) (fmat (list #\~ #\% #\Newline)) (alphabet (list #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\Space #\. #\, #\; #\: #\( #\))) ) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) (do ((j 0 (+ j 1)) (n (how-many #\Newline string))) ((= j n)) (setf string (string-left-trim fmat (string-left-trim alphabet string))) (push (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string))) result) ) result)) (defun max-text-segment (lengths) " Gets the length of the maximum text segment~ from a collection of cumulative lengths of a piece~ of text assumed to have come from list-of-lengths." (let ((diffs '())) (do ((j 0 (+ j 1)) (n (length lengths))) ((= j (- n 1))) (push (- (elt lengths j) (elt lengths (+ j 1))) diffs)) (cond ((eq 1 (length lengths)) (first lengths)) (T (abs (first (sort diffs #'<)))) ) )) ;; Build the list of dialog-items (defun build-multi-dialog-items (items &key (prompt-text "Pick one of the following") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)))) (set-view-size (a-window) (list (cg::exterior-width a-window) (cg::exterior-height a-window)))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) ;; left of window-exterior of whole dialog (dialog-outer-top 10) ;; top of window-exterior of whole dialog (scroll-bar-width 25) ;; a guess at this (min-separator 15) ;; distance between widgets H and V (displayed 5) ;; Number of items visible (max-item-width (first (sort (mapcar #'(lambda (x) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) x)))) items) #'>))) (error-text "please choose an item first!") (error-text-width (text-width error-text)) (prompt-text-width (text-width prompt-text)) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-text)) text-height))) (button-height (+ 2 text-height)) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) (seq-height 200) (seq-width 200) ;; make the prompt stuff (text-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text))) ;; prompt stuff done ;; make the error stuff (error-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text)) ;; error stuff done ;; seq-dialog should start here (seq-dialog (cg::make-dialog-item :widget cg::'multi-item-list :range items :box (cg::make-box-relative (cg::box-left (cg::dialog-item-box text-dialog)) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator ) ;+ max-item-width (+ max-item-width scroll-bar-width) (+ min-separator (* (min (length items) displayed) text-height))) :title "Pick one" :available-p T ) ) ;; seq-dialog should end here ;; cancel begins (cancel-button (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ (cg::box-right (cg::dialog-item-box seq-dialog)) min-separator) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text )) ;; cancel done ;; make select stuff (select-button (cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (cg::box-left (cg::dialog-item-box cancel-button)) (+ (cg::box-bottom (cg::dialog-item-box cancel-button)) min-separator) button-width button-height) :title select-text :set-value-fn #'(lambda (&rest args) (cond ((not (cg::dialog-item-value seq-dialog)) (cg::pop-up-message-dialog (cg::dialog-item-window seq-dialog) "You choose ... " error-text cg::warning-icon "OK?") ;; Accept the button click but do not return from the ;; main dialog yet after popping up the warning (values t nil)) ;; Return from the main dialog since we noted above that ;; a selection was made (t (values t t))) ) )) ;; select done ) ;; end of bindings in let* .. body follows (list text-dialog error-dialog seq-dialog select-button cancel-button) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;; end of build-multi-dialog-items ;; Create the dialog from what build-.. produces (defun create-multi-dialog (items &key (prompt-text "Please choose one or more ... ") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items (build-multi-dialog-items items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (scroll-bar-width 25) (min-separator 15) (text-dialog (first list-of-dialog-items)) (select-button (fourth list-of-dialog-items)) (cancel-button (fifth list-of-dialog-items)) (seq-dialog (third list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "You choose .." :pop-up-p t :font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top (+ min-separator (max (cg::box-right (cg::dialog-item-box text-dialog)) (cg::box-right (cg::dialog-item-box select-button)) (cg::box-right (cg::dialog-item-box cancel-button)))) (+ (* 4 min-separator) (max (cg::box-bottom (cg::dialog-item-box seq-dialog)) (cg::box-bottom (cg::dialog-item-box cancel-button))))) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog list-of-dialog-items) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; end of create-multi-dialog ;; Now process it (defun process-multi-dialog (items &key (prompt-text "Please choose one or more .. ") (item-print-function nil) (action-function #'identity) (select-text "select") (cancel-text "cancel")) ;; Make the dialog itself (let* ((new-items (cond ((functionp item-print-function) (setf new-items (mapcar item-print-function items))) ((null item-print-function) (setf new-items (mapcar #'(lambda (item) (format NIL "~s" item)) items))) (T items)) ) (a-dialog (create-multi-dialog new-items :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (error-text "Please choose an item first!") ;; Show the completed dialog (clicked-button (cg::pop-up-dialog a-dialog)) (d-items (mapcar #'cg::dialog-item-value (cg::dialog-items a-dialog))) (seq-v (third d-items)) (select-v (fourth d-items)) (cancel-v (fifth d-items))) (cond (cancel-v (abort) ) (t (loop for item in items as new-item in new-items when (member new-item seq-v :test #'string-equal) collect (funcall action-function item)))) ) ;; end let* ) ;; end of process-multi-dialog ;;; Code in the mold of other dialogs follows ;;; build-prompt-user -> create-prompt-user -> prompt-user itself (defun build-prompt-user (&key (type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "cancel") left top width (height 100) ) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::stream-string-width (cg::screen cg::*system*) string)))) (set-view-size (a-window) (list (cg::exterior-width a-window) (cg::exterior-height a-window)))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (min-separator 15) ;; minimum distance between boxes (response-width 100) ;; width of editable-text boxes ;(prompt-text-width (text-width prompt-text)) (prompt-text-width (max-text-segment (list-of-lengths prompt-string))) ;<< (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 prompt-text-width )) (text-box-height (+ 10 text-height)) ;<< (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-string)) text-height))) ;<< (text-box-x 20) (text-box-y 20) (button-height (+ 2 text-height)) (button-width (+ 5 (max (text-width ok-text) (text-width cancel-text)))) (seq-height 200) (seq-width 200) ;; The following are set AFTER text-dialog ;; (first-item-y (+ text-box-y text-box-height )) ;; (first-item-x dialog-outer-left ) ;; (button-x (+ 50 first-item-x (* columns col-width))) ;; (view-size-width (max 200 ;; (+ button-x button-width 2) ;; (+ text-box-x text-box-width 2))) ;; (view-size-height (max 100 ;; (+ first-item-y ;; (+ 2 (* (+ nrows 1) text-box-height)) ;; 2) ;; (+ text-box-height ;; button-height ;; 2))) ;; make the prompt stuff (text-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-string) ;<< :name :text-d) ) ;; prompt stuff done ;; Now set the top of the first item (first-item-y (cg::box-bottom (cg::dialog-item-box text-dialog))) ;;; Make the response-dialog (response-dialog (cg::make-dialog-item :widget cg::'editable-text :value initial-string :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ first-item-y min-separator) (max response-width prompt-text-width) text-box-height) :name :resp-d)) ;;; Find two values needed for later sizing and positioning (rightmost (cg::box-right (cg::dialog-item-box response-dialog))) (collect-bottom (cg::box-bottom (cg::dialog-item-box response-dialog))) ;; cancel begins (cancel-button (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ collect-bottom min-separator) button-width button-height) :title cancel-text :name :cancel-d )) (cancel-bottom (cg::box-bottom (cg::dialog-item-box cancel-button))) ;; cancel done ;; make select stuff (select-button (cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (+ (cg::box-right (cg::dialog-item-box cancel-button)) min-separator) (+ collect-bottom min-separator) button-width button-height) :title ok-text :name :select-d :set-value-fn #'(lambda (&rest args) (values t t)) )) (select-bottom (cg::box-bottom (cg::dialog-item-box select-button))) ;; select done ;; compute overall sizes (overall-width (+ min-separator (max (cg::box-right (cg::dialog-item-box text-dialog)) (cg::box-right (cg::dialog-item-box response-dialog)) (cg::box-right (cg::dialog-item-box select-button)) (cg::box-right (cg::dialog-item-box cancel-button))))) (overall-height (+ (* 4 min-separator) cancel-bottom )) ) ;; end of bindings in let* .. body follows ;; return some sizes and the dialogs (list overall-width overall-height text-dialog response-dialog select-button cancel-button) ) ;; end of let* .. it returns a list ) ;; end of flet ) (defun create-prompt-user (&key (type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "cancel") left top width (height 100) ) (let* ((list-of-dialog-items (build-prompt-user :type type :read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text :left left :top top :width width :height height)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Your input .." :pop-up-p t :font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top overall-width overall-height ) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ;; end of let* .. it returns an actual dialog ) (defun prompt-user (&key (type T) (read-type :string) (prompt-string "") (initial-string "") (ok-text "OK") (cancel-text "Cancel") left top width (height 100)) ;; Make the dialog itself (let* ((a-dialog (create-prompt-user :type type :read-type read-type :prompt-string prompt-string :initial-string initial-string :ok-text ok-text :cancel-text cancel-text )) ;; Show the completed dialog (showit (cg::pop-up-dialog a-dialog)) (cancel-v (cg::dialog-item-value (cg::widget :cancel-d a-dialog))) (select-v (cg::dialog-item-value (cg::widget :resp-d a-dialog))) ) (if cancel-v (abort) ; was initial-string (let* ((result select-v)) (setf result (case read-type (:string result) (:eval (eval (read-from-string result :preserve-whitespace t))) (:read (read-from-string result :preserve-whitespace t)) ) ) (if (typep result type) result (quail-error "~S is not of type ~s" result type))) ) ) ;; end let* ) (defun save-value (arg) "Saves the value of arg as the value of a symbol retrieved from a prompt." (eval `(setf ,(prompt-user :read-type :read :type 'symbol :prompt-string "Give a symbol to store the value on:") ,arg))) (defun prompt-t-or-f (message &key (true-text "Yes") (false-text "No") (cancel-text "Cancel")) "Prompts the user to choose between two alternatives ~ (true-text and false-text) in response to the information ~ given in message. T is returned if the first letter ~ of the true-text (default the string Yes) is typed by the ~ user; NIL if the first letter of the false-text is typed. ~ If cancel-text is selected, processing stops." (let* ((answer (cg::ask-user-for-choice message true-text false-text cancel-text))) (cond ((eq answer true-text) T) ((eq answer false-text) NIL) ((eq answer cancel-text) NIL)))) (defun prompt-true-or-false (message &key (true-text "Yes") (false-text "No") (cancel-text "Cancel")) "Prompts the user to make a decision between two alternatives (true-text and false-text) ~ in response to the information given in message. T is returned if the ~ true-text (default the string Yes) is typed by the user; NIL is returned if the ~ false-text (default the string No) is typed by the user. ~ If cancelled by the user, processing ends. ~ (:see-also prompt-for-items pick-one prompt-t-or-f)" (prompt-t-or-f message :true-text true-text :false-text false-text :cancel-text cancel-text)) (defun prompt-for-items (list &key (prompt-text "Choose") (item-function NIL) (selection-type :single)) "Prompts user to select one or more items from the list. ~ Prompt-text is displayed to help the user choose. ~ Selection-type is one of :single (indicating only a single item ~ can be selected), :contiguous (indicating only contiguous items ~ can be selected), and :disjoint (indicating that any subset of the items ~ can be selected). It returns a list of all items selected, NIL if no items ~ were selected. ~ Item-print-function is the function called on each item to display it in ~ selection table. ~ (:see-also pick-one prompt-t-or-f)" ;(if (functionp item-function) (process-multi-dialog list :prompt-text prompt-text :item-print-function item-function ) ; (process-multi-dialog list :prompt-text prompt-text) )
28,978
Common Lisp
.l
565
31.895575
124
0.444762
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
46eef2c1f9433b988f2a620861ab38db65a61b82250da75f200f4db2e463bab2
33,619
[ -1 ]
33,621
orig-collect-input-pc.lsp
rwoldford_Quail/source/window-basics/prompt/orig2005/orig-collect-input-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; collect-input-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; G.W. Bennett 1996-1997 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(collect-input))) ;; Build the list of dialog-items (defun build-collect-items (items &key (prompt-text "Please enter responses ...") (item-print-function nil) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel") (columns 1) ) (flet ((text-width (string) (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (if (stringp string) (cg::stream-string-width (cg::screen cg::*system*) string) (cg::stream-string-width (cg::screen cg::*system*) (format NIL "~s" string)))) )) (set-view-size (a-window) (list (cg::width (cg::exterior a-window)) (cg::height (cg::exterior a-window))))) (let* ((view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (min-separator 15) ;; minimum distance between boxes (response-width 100) ;; width of editable-text boxes (max-item-width (apply #'max (mapcar #'text-width items))) (error-text "please choose an item first!") (error-text-width (text-width error-text)) (prompt-text-width (text-width prompt-text)) (temp-font-info (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::fontmetrics (cg::screen cg::*system*))))) (text-height (+ (cg::font-ascent temp-font-info) (cg::font-descent temp-font-info) (cg::font-leading temp-font-info))) (text-box-width (+ 5 (max prompt-text-width error-text-width))) (text-box-height (+ 10 text-height)) (prompt-box-height (+ 10 (* (+ 1 (how-many #\Newline prompt-text)) text-box-height))) (text-box-x 20) (text-box-y 20) (button-height (+ 2 text-height)) (button-width (+ 5 (max (text-width select-text) (text-width cancel-text)))) (seq-height 200) (seq-width 200) (n-items (length items)) (col-width (+ 15 max-item-width )) (nrows (ceiling (/ n-items columns))) ;; The following are set AFTER text-dialog ;; (first-item-y (+ text-box-y text-box-height )) ;; (first-item-x dialog-outer-left ) ;; (button-x (+ 50 first-item-x (* columns col-width))) ;; (view-size-width (max 200 ;; (+ button-x button-width 2) ;; (+ text-box-x text-box-width 2))) ;; (view-size-height (max 100 ;; (+ first-item-y ;; (+ 2 (* (+ nrows 1) text-box-height)) ;; 2) ;; (+ text-box-height ;; button-height ;; 2))) ;; make the prompt stuff (text-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width prompt-box-height) :value (format nil prompt-text) :name :text-d )) ;; prompt stuff done ;; Now set the top of the first item (first-item-y (+ (cg::box-bottom (cg::dialog-item-box text-dialog)))) (first-item-x dialog-outer-left ) (button-x (+ 50 first-item-x (* columns col-width))) (view-size-width (max 200 (+ button-x button-width 2) (+ text-box-x text-box-width 2))) (view-size-height (max 100 (+ first-item-y (+ 2 (* (+ nrows 1) text-box-height)) 2) (+ text-box-height button-height 2))) ;; make the error stuff (error-dialog (cg::make-dialog-item :widget 'cg::static-text :box (cg::make-box-relative (+ dialog-outer-left min-separator) (+ dialog-outer-top min-separator) text-box-width text-box-height) :border :static :value error-text :name :error-d)) ;; error stuff done ;; collect-dialog should start here ;;; TOP OF CODE FROM -mcl FILE (collect-dialog (loop for item in items with y-start = first-item-y with x-start = first-item-x with row = 0 with col = 0 append (list (cg::make-dialog-item :widget cg::'static-text ;; Display must be in :value slot ;; (car item) grabs the "prompt-piece" :value (car item) ;item :box (cg::make-box-relative (+ x-start (* col col-width) min-separator) (+ y-start (* row text-box-height)) (+ min-separator max-item-width ) (+ text-box-height)) :available-p T ) (cg::make-dialog-item ;; This has implications for the return value. ;; editable-test returns a genuine string ;; lisp-text returns a lisp object :widget cg::'editable-text;cg::'lisp-text ;; (cdr item) grabs the "default value" :value (cdr item) ;NIL :box (cg::make-box-relative (+ x-start (* col col-width) min-separator min-separator max-item-width) (+ y-start (* row text-box-height)) response-width (+ text-box-height)) :available-p T )) do (cond ((>= row (1- nrows)) (incf col 1) (setq row 0) (setq x-start (+ x-start response-width min-separator))) (T (incf row 1)))) ) ;;; END OF CODE FROM -mcl FILE ;;; Find two values needed for later sizing and positioning (rightmost (cg::box-right (cg::dialog-item-box (first (last collect-dialog))))) (collect-bottom (apply #'max (mapcar #'cg::box-bottom (mapcar #'cg::dialog-item-box collect-dialog)))) ;; cancel begins (cancel-button (cg::make-dialog-item :widget cg::'cancel-button :box (cg::make-box-relative (+ rightmost min-separator) (+ (cg::box-bottom (cg::dialog-item-box text-dialog)) min-separator) button-width button-height) :title cancel-text :name :cancel-d )) (cancel-bottom (cg::box-bottom (cg::dialog-item-box cancel-button))) ;; cancel done ;; make select stuff (select-button (cg::make-dialog-item :widget cg::'button :box (cg::make-box-relative (+ rightmost min-separator) (+ (cg::box-bottom (cg::dialog-item-box cancel-button)) min-separator) button-width button-height) :title select-text :name :select-d :set-value-fn #'(lambda (&rest args) (values t t)) )) (select-bottom (cg::box-bottom (cg::dialog-item-box select-button))) ;; select done ;; compute overall sizes (overall-width (+ min-separator (max (cg::box-right (cg::dialog-item-box text-dialog)) (cg::box-right (cg::dialog-item-box select-button)) (cg::box-right (cg::dialog-item-box cancel-button))))) (overall-height (+ (* 4 min-separator) (max collect-bottom cancel-bottom select-bottom))) ) ;; end of bindings in let* .. body follows ;; return some sizes and the dialogs (append (list overall-width overall-height text-dialog error-dialog) collect-dialog (list select-button cancel-button)) ) ;; end of let* .. it returns a list ) ;; end of flet ) ;;end of build-collect-items ;; Create the real dialog from the output of build-collect-items (defun create-collect-dialog (items &key (columns 1) (prompt-text "Please enter responses ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) (let* ((list-of-dialog-items (build-collect-items items :columns columns :prompt-text prompt-text :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text)) (view-font (let ((scrn (cg::screen cg::*system*))) (cg::with-device-context (hdc scrn) (cg::font (cg::screen cg::*system*))))) (dialog-outer-left 10) (dialog-outer-top 10) (overall-width (first list-of-dialog-items)) (overall-height (second list-of-dialog-items)) ;; Start creation of base-dialog here ;; make an empty dialog-item (base-item (list (cg::make-dialog-item :widget 'cg::button :box (cg::make-box 20 20 20 20)))) ;; make an empty dialog from this item (base-dialog (cg::open-dialog base-item 'cg::dialog (cg::screen cg::*system*) :title "Enter responses ..." :pop-up-p t :font (canvas-font-to-host-font *prompt-normal-font*) :window-exterior (cg::make-box-relative dialog-outer-left dialog-outer-top overall-width overall-height ) )) ;; End creation of empty base-dialog here ) ;end of list of let* .. body is next ;; add new items (cg::update-dialog base-dialog (cddr list-of-dialog-items)) base-dialog) ;; end of let* .. it returns an actual dialog ) ;; end of create-collect-dialog ;; Now deal with the dialog (defun collect-input(items &key (columns 1) (prompt-text "Please enter responses ...") (item-print-function NIL) (action-function #'(lambda (i) i)) (select-text "select") (cancel-text "cancel")) ;; Make the dialog itself (let* ((a-dialog (create-collect-dialog items :columns columns :item-print-function item-print-function :action-function action-function :select-text select-text :cancel-text cancel-text :prompt-text prompt-text)) ;; Show the completed dialog (showit (cg::pop-up-dialog a-dialog)) ;; Check on what is returned (d-items (cg::dialog-items a-dialog)) (t-items (mapcar #'cg::dialog-item-title d-items)) (v-items (mapcar #'cg::dialog-item-value d-items)) (n-items (length items)) (d-length (length d-items)) (cancel-v (cg::dialog-item-value (cg::widget :cancel-d a-dialog))) (select-v (cg::dialog-item-value (cg::widget :select-d a-dialog))) ) (if cancel-v items (loop for x from 0 to (- d-length 5) collect (cons (nth (+ x 2) v-items) (nth (+ x 3) v-items) ) do (incf x 1)) ) ) ;; end let* ) ;; end process-check-geometry itself
14,875
Common Lisp
.l
291
32.52921
130
0.431893
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
43edce4bf1e9f4f14037ad213f7f3a54139a1eb30690dfa64d4529ff78ccf663
33,621
[ -1 ]
33,622
new-pick-one.lsp
rwoldford_Quail/source/window-basics/prompt/new2015/new-pick-one.lsp
;;; This is new-pick-one.lsp ;;; Started 23Feb22015 gwb ;; From examples/cg/menus-and-help.cl (in-package :cg-user) (defclass my-main-window (frame-window)()) (defclass my-single-item-list (single-item-list)()) (defun my-on-change (widget new-value old-value) "Called when the value of WIDGET has changed." (window-message (parent widget) "Widget ~s goes from ~s to ~s." (name widget) old-value new-value) t) ;; setup quail-dialog-font (defvar quail-dialog-font NIL) (defun set-quail-dialog-font (&optional font ) ;"Sets quail-dialog-font with default (make-font-ex nil "MS Sans Serif" 13 nil)~ ; intput must be a cg::font, result is one too." (setf quail-dialog-font (or font (make-font-ex nil "MS Sans Serif" 13 nil))) quail-dialog-font) (defvar quail-dialog-window-left NIL) (defun set-quail-dialog-window-left (&optional (left 10)) "Sets the value of quail-dialog-window-left~ Defaults to 10" (setf quail-dialog-window-left left) quail-dialog-window-left) (defvar quail-dialog-window-top NIL) (defun set-quail-dialog-window-top (&optional (top 10)) "Sets the value of quail-dialog-window-top~ Defaults to 10" (setf quail-dialog-window-top top) quail-dialog-window-top) (defvar quail-dialog-box-left NIL) (defun set-quail-dialog-box-left (&optional (left 10)) "Sets the value of quail-dialog-box-left~ Defaults to 10" (setf quail-dialog-box-left left) quail-dialog-box-left) (defvar quail-dialog-box-top NIL) (defun set-quail-dialog-box-top (&optional (top 10)) "Sets the value of quail-dialog-box-top~ Defaults to 10" (setf quail-dialog-box-top top) quail-dialog-box-top) (defvar quail-dialog-separator NIL) (defun set-quail-dialog-separator (&optional (separator 15)) "Sets the value of quail-dialog-separator~ the vertical or horizontal amount between elements~ Deafults to 15" (setf quail-dialog-separator separator) quail-dialog-separator) (defvar quail-dialog-displayed NIL) (defun set-quail-dialog-displayed (&optional (displayed 5)) "Sets the quail-dialog-displayed, the number of items~ shown in a dialog list. Defaults to 5" (setf quail-dialog-displayed displayed) displayed) (defvar quail-dialog-scrollbar-width NIL) (defun set-quail-dialog-scrollbar-width (&optional (width 30)) "Sets the width allowance for a scrollbar in quail dialogs~ Defaults to 30." (setf quail-dialog-scrollbar-width width) quail-dialog-scrollbar-width) ;; I need something to deal with the stringish sizes (defun quail-dialog-string-sizes (items) "Collects the maximum width of the strings in items~ and the width of the Cancel and Select strings." (let*((zot (open-stream 'bitmap-stream nil nil)) (font-zot (font zot) quail-dialog-font) (its-metrics (fontmetrics zot)) (max-item-width (first (sort (mapcar #'(lambda (x) ;; to allow for scrollbar width (if (stringp x) (cg::stream-string-width zot x) (cg::stream-string-width zot (format NIL "~s" x)))) items) #'>))) (item-height (font-height its-metrics)) (zcb (make-instance 'cancel-button :font (make-font-ex nil "MS Sans Serif" 13 nil) :name :cancel-button-1 :title "Cancel")) (cancel-width (width zcb)) (cancel-height (height zcb)) ) (list :max-width max-width :item-height item-height :cancel-width cancel-width :cancel-height cancel-height) )) (defun make-quail-dialog-box (items ) "Sets the box which holds the items in a quail-dialog" (let* ((left (set-quail-dialog-box-left)) (top (set-quail-dialog-box-top)) (width (+ (getf (quail-dialog-string-sizes items) :max-width) (set-quail-dialog-scrollbar-width))) (height (* (set-quail-dialog-displayed) (getf (quail-dialog-string-sizes items) :item-height))) ) (make-box left top (+ left width) (+ top height)) )) ;; That's all very well, but what I really want is to set the font and then get stringish things ;; with respect to that font. This is complicated because I have to associate the font with ;; a stream since that's what stream-string-width works on. ;; Try the following let*. If OK then work it into other things. (let* ((zot (open-stream 'bitmap-stream nil nil)) (font-zot (font zot) quail-dialog-font) (its-metrics (fontmetrics zot)) ) (format t "~%Font height is ~d " (font-height its-metrics)) (format t "~%Stream-string-width is ~d " (stream-string-width zot "Stream-String-width")) ) ;; It did function as expected. Note to self a canel-button's width comes from just (width .. (defun the-pick-one (items) (setf pick-one-window (make-window :my-main-window :class 'my-main-window :owner (screen *system*) :title "Menus and Help Options" :exterior (make-box (quail-dialog-window-left) (quail-dialog-window-top) (+ (quail-dialog-window-left) ;:exterior (make-box 400 200 900 500) :scrollbars nil :dialog-items (list (make-instance 'my-single-item-list :font quail-dialog-font :name :list :range items ;'(one two three) :value '(first items);'one ;:tooltip "The first three." :help-string "Pick a number. Any number." :on-mouse-in 'show-the-help-string :on-mouse-out 'clear-the-status-bar :on-change 'my-on-change :left 20 :top 60 :width (first (string-sizes items)) :height 80) (make-instance 'cancel-button :font (make-font-ex nil "MS Sans Serif" 13 nil) :left 300 :name :cancel-button-1 :title "Cancel" :top 60) (make-instance 'cancel-button :font (make-font-ex nil "MS Sans Serif" 13 nil) :left 300 :name :select-button-1 :title "Select" :top 110) ) ) )) ;; From V/S-V/numerical-label.lsp (setf format-types '("Lisp format directive" "Fixed-format floating point" "Exponential floating point" "Dollars floating point" "General floating point" "Decimal" "Binary" "Octal" "Hexadecimal" "Radix" )) ;; From permuted index on cancel button class (make-instance 'cancel-button :font (make-font-ex nil "MS Sans Serif" 13 nil) :left 189 :name :cancel-button-1 :title "Cancel" :top 146)
7,951
Common Lisp
.l
169
32.715976
111
0.542603
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7af288dbb2bb144a06b0c391d942740851e2706e43ee33163b9e4ec6b68d1a1c
33,622
[ -1 ]
33,623
pen.lsp
rwoldford_Quail/source/window-basics/pen/pen.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; pen.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; R.W. Oldford 1989-1992 ;;; ;;; ;;; ;;; (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pen pen-width-of pen-color-of pen-operation-of pen-texture-of with-pen-values with-pen-width with-pen-operation with-pen-color with-pen-values-restored))) (defclass pen () ((pen-width :initarg :pen-width :initform NIL :reader pen-width-of :documentation "Current width of the pen used to draw in this canvas.") (pen-point :initarg :pen-point :initform NIL :reader pen-point-of :documentation "Current point of the pen used to draw in this canvas.") (pen-operation :initarg :pen-operation :initform NIL :reader pen-operation-of :documentation "Current operation of the pen used to draw in this canvas.") (pen-color :initarg :pen-color :initform NIL :reader pen-color-of :documentation "Current color of the pen used to draw in this canvas.") (pen-texture :initarg :pen-texture :initform NIL :reader pen-texture-of :documentation "Current texture of the pen used to draw in this canvas.")) (:documentation "A pen to be used to draw in a canvas.")) ;#-:sbcl-linux (defmacro with-pen-width (canvas width &body forms) "Performs the forms with the pen width of canvas temporarily reset to ~ the value given. If width is NIL, width is ignored." (let ((old-width (gensym "with-pen-width"))) `(let (,old-width) (declare (ignorable ,old-width)) (cond ((not (null ,width)) (setf ,old-width (pen-width-of ,canvas)) (set-pen-width ,canvas ,width) ,@forms (set-pen-width ,canvas ,old-width)) (T ,@forms))))) #| #+:sbcl-linux (defmacro with-pen-width (canvas width &body forms) "Performs the forms with the pen width of canvas temporarily reset ot ~ the value given. If width is NIL, width is ignored." `(let ((drawing-pane (get-frame-pane ,canvas 'host-pane))) (cond ((not (null ,width)) (with-drawing-options (drawing-pane :line-thickness ,width) ,@forms)) (T ,@forms)))) |# ;#-:sbcl-linux (defmacro with-pen-color (canvas color &body forms) "Performs the forms with the pen color of canvas temporarily reset to ~ the value given. If color is NIL, color is ignored." (let ((old-color (gensym "with-pen-color"))) `(let (,old-color) (declare (ignorable ,old-color)) (cond ((not (null ,color)) (setf ,old-color (pen-color-of ,canvas)) (set-pen-color ,canvas ,color) ,@forms (set-pen-color ,canvas ,old-color)) (T ,@forms))))) #| #+:sbcl-linux (defmacro with-pen-color (canvas color &body forms) "Performs the forms with the pen color of canvas temporarily reset to ~ the value given. If color is NIL, color is ignored." `(let ((drawing-pane (get-frame-pane ,canvas 'host-pane))) (cond ((not (null ,color)) (with-drawing-options (drawing-pane :ink ,color) ,@forms)) (T ,@forms))) ) |# ;#-:sbcl-linux (defmacro with-pen-operation (canvas operation &body forms) "Performs the forms with the pen operation of canvas temporarily reset to ~ the value given. If operation is NIL, operation is ignored." (let ((old-operation (gensym "with-pen-operation"))) `(let (,old-operation) (declare (ignorable ,old-operation)) (cond ((not (null ,operation)) (setf ,old-operation (pen-operation-of ,canvas)) (set-pen-operation ,canvas ,operation) ,@forms (set-pen-operation ,canvas ,old-operation)) (T ,@forms))))) #| #+:sbcl-linux (defmacro with-pen-operation (canvas operation &body forms) "Performs the forms with the pen operation of canvas temporarily reset to ~ the value given. If operation is NIL, operation is ignored." (declare (ignore operation)) `(,@forms) ) |# #| (defmacro with-pen-values (canvas color width operation &body forms) "Executes the forms with the pen values of canvas temporarily reset to ~ the values of color width and operation. Null values are ignored." `(with-pen-width ,canvas ,width (with-pen-color ,canvas ,color (with-pen-operation ,canvas ,operation ,@forms)))) |# ;;; new version 08AUG2023 (defmacro with-pen-values (canvas color width operation &body forms) (let ((old-color (gensym "with-color")) (old-width (gensym "with-width")) (old-operation (gensym "with-operation"))) `(let ((,old-color) (,old-width) (,old-operation)) (declare (ignorable ,old-color ,old-width ,old-operation)) (setf ,old-color (pen-color-of ,canvas)) (setf ,old-width (pen-width-of ,canvas)) (setf ,old-operation (pen-operation-of ,canvas)) (cond ((not (null ,color)) (set-pen-color ,canvas ,color) )) (cond ((not (null ,width)) (set-pen-width ,canvas ,width) )) (cond ((not (null ,operation)) (set-pen-operation ,canvas ,operation) ,@forms ) (T ,@forms )) (set-pen-color ,canvas ,old-color) (set-pen-width ,canvas ,old-width) (set-pen-operation ,canvas ,old-operation) ))) (defmacro with-pen-values-restored (canvas &body forms) "Saves the pen values of canvas, performs the forms, then ~ resets the pen values to their original values." (let ((old-width (gensym "with-pen-values-restored")) (old-op (gensym "with-pen-values-restored")) (old-col (gensym "with-pen-values-restored"))) `(let ((,old-width (pen-width-of ,canvas)) (,old-col (pen-color-of ,canvas)) (,old-op (pen-operation-of ,canvas))) ,@forms (set-pen-width ,canvas ,old-width) (set-pen-color ,canvas ,old-col) (set-pen-operation ,canvas ,old-op))))
6,783
Common Lisp
.l
170
32.635294
96
0.594562
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
b785a2e7bfd0f9cc9f622458432d1483c7f8f6a14b89a8128a1d277cce5cd251
33,623
[ -1 ]
33,624
pen-mixin.lsp
rwoldford_Quail/source/window-basics/pen/pen-mixin.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; pen-mixin.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(pen-mixin pen-width-of pen-operation-of pen-texture-of pen-color-of set-pen-operation set-pen-width set-pen-color canvas-set-pen pen-default-color ))) (defclass pen-mixin () ((pen :initarg :pen :initform NIL :reader pen-of :documentation "Current pen used to draw in this canvas.") ) (:documentation "Mixin to give a pen to an object.")) #| START out 05MAR2021 (defmethod initialize-instance :after ((self pen-mixin) &rest initargs &key pen-color pen-width pen-operation) (declare (ignore initargs)) (sleep 10) ;; 05MAR2021 (format t "~%i-i input pen-color is ~s " pen-color) (format t "~%i-i input pen-width is ~s " pen-width) (format t "~%i-i input pen-operation is ~s " pen-operation) (format t "~%i-i input self is ~s " self) (format t "~%i-i is self a frame ~s , a colored-canvas ~s " (clim:application-frame-p self) (colored-canvas-p self)) (format t "~%i-i does it have a host-pane ~s " (clim:get-frame-pane self 'host-pane)) (unless (pen-of self) (setf (slot-value self 'pen) (make-instance 'pen))) (canvas-set-pen self :width pen-width :operation pen-operation :color pen-color) ) |# ;END out 05MAR2021 ;;;-------------------------------------------------------------------------------------- ;;; ;;; setting pen attributes ;;; (defun set-pen-operation (canvas operation) "Sets the operation of the pen." ;(format t "~%Just inside set-pen-operation") ;(format t "~%input operation is ~s " operation) (unless (eq operation (pen-operation-of canvas)) (let ((pen (pen-of canvas))) (setf (slot-value pen 'pen-operation) operation) (h-draw:set-pen-mode canvas (boole-to-op operation)) ;(format t "~%out going operation is ~s " (slot-value pen 'pen-operation)))) ))) ;;; Here is fix-pen-size, a copy of h-draw:set-pen-size but in :wb #+:sbcl-linux(defun fix-pen-size (canvas h &optional v) #-:sbcl(declare (inline h-draw::point-x h-draw::point-y)) ;(format t "~%Just inside set-pen-size") ;(format t "~%f-p-s h is ~s " h) ;(format t "~%f-p-s v is ~s " v) ;(format t "~%f-p-s canvas is ~s " canvas) ;(format t "~%f-p-s is it a frame ? ~s " (clim:application-frame-p canvas)) ;(format t "~%f-p-s its host-pane pane is ~s " (clim:get-frame-pane canvas 'host-pane)) (let* ((its-pane (clim::get-frame-pane canvas 'host-pane)) ;,_ from 'wb::host-pane 09FE21 (its-line-style (clim:medium-line-style its-pane)) (its-unit (clim:line-style-unit its-line-style)) (its-dashes (clim:line-style-dashes its-line-style)) (its-joint-shape (clim:line-style-joint-shape its-line-style)) (its-cap-shape (clim:line-style-cap-shape its-line-style)) (new-thickness (if v (floor (+ h v) 2) (floor (+ (h-draw::point-x h) (h-draw::point-y h)) 2))) (new-style (clim:make-line-style :unit its-unit :thickness new-thickness :dashes its-dashes :joint-shape its-joint-shape :cap-shape its-cap-shape)) ) ;(format t "~%f-p-s In set-pen-size after defvar new-thickness check current values BEFORE make-line-style") ;(format t "~%f-p-s input canvas is ~s " canvas) ;(format t "~%f-p-s is canvas a frame ? ~s " (clim:application-frame-p canvas)) ;(format t "~%f-p-s input h is ~s " h) ;(format t "~%f-p-s input v is ~s " v) ;(format t "~%f-p-s its-pane is ~s " its-pane) ;(format t "~%f-p-s its-line-style is ~s " its-line-style) ;(format t "~%f-p-s its-unit is ~s " its-unit) ;(format t "~%f-p-s its-dashes is ~s " its-dashes) ;(format t "~%f-p-s its-joint-shape is ~s " its-joint-shape) ;(format t "~%f-p-s its-cap-shape is ~s " its-cap-shape) ;(format t "~%f-p-s new-thickness is ~s " new-thickness) ;(format t "~%f-p-s new-style is ~s " new-style) (setf (clim:medium-line-style its-pane) new-style) ) ) ;;; #-:sbcl-linux(defun set-pen-width (canvas width) "Set the width of canvas's pen to be width units." ;(format t "~%Just inside set-pen-width") ;(format t "~%s-p-w input width is ~s " width) ;(format t "~%s-p-w canvas is ~s " canvas) ;(format t "~%s-p-w is canvas a frame ? ~s " (clim:application-frame-p canvas)) ;(format t "~%s-p-w does canvas have a host-pane ? ~s " (clim:get-frame-pane canvas 'host-pane)) ;(format t "~%s-p-w pen-of canvas is ~s " (pen-of canvas)) ;(format t "~%s-p-w pen-width-of pen-of canvas is ~s " (pen-width-of (pen-of canvas))) ;(format t "~%s-p-w pen-width-of canvas is ~s " (pen-width-of canvas)) (unless (and (pen-width-of canvas) (= width (pen-width-of canvas))) (with-display-mode canvas (display-mode-of canvas) (set-pen-width canvas width) (let ((pen (pen-of canvas))) ;(format t "~%s-p-w pen is ~s " pen) (setf (slot-value pen 'pen-width) width) ;(format t "~%s-p-w slot-value pen 'pen-width is ~s " (slot-value pen 'pen-width)) (setf (slot-value pen 'pen-point) (h-draw:make-point width width)) ;(format t "~%s-p-w slot-value pen 'pen-point is ~s " (slot-value pen 'pen-point)) ;(fix-pen-size canvas (pen-point-of pen)) (h-draw:set-pen-size canvas (pen-point-of pen)) ;(format t "~%out going width is ~s " (slot-value pen 'pen-width)) ))) ) #+:sbcl-linux(defun set-pen-width (canvas width) "Set the width of canvas's pen to be width units." ;(format t "~%Just inside set-pen-width") ;(format t "~%s-p-w input width is ~s " width) ;(format t "~%s-p-w canvas is ~s " canvas) ;(format t "~%s-p-w is canvas a frame ? ~s " (clim:application-frame-p canvas)) ;(format t "~%s-p-w does canvas have a host-pane ? ~s " (clim:get-frame-pane canvas 'host-pane)) ;(format t "~%s-p-w pen-of canvas is ~s " (pen-of canvas)) ;(format t "~%s-p-w pen-width-of pen-of canvas is ~s " (pen-width-of (pen-of canvas))) ;(format t "~%s-p-w pen-width-of canvas is ~s " (pen-width-of canvas)) (unless (and (pen-width-of canvas) (= width (pen-width-of canvas))) (with-display-mode canvas (display-mode-of canvas) (set-pen-width canvas width) (let ((pen (pen-of canvas))) ;(format t "~%s-p-w pen is ~s " pen) (setf (slot-value pen 'pen-width) width) ;(format t "~%s-p-w slot-value pen 'pen-width is ~s " (slot-value pen 'pen-width)) (setf (slot-value pen 'pen-point) (h-draw:make-point width width)) ;(format t "~%s-p-w slot-value pen 'pen-point is ~s " (slot-value pen 'pen-point)) (fix-pen-size canvas (pen-point-of pen)) ;(h-draw:set-pen-size canvas (pen-point-of pen)) ;(format t "~%out going width is ~s " (slot-value pen 'pen-width)) ))) ) ;;; Here is fix-pen-color, a copy of h-draw:set-pen-color but here in :wb #+:sbcl-linux(defun fix-pen-color (canvas new-color) "Sets the drawing color of canvas to (Q)new-color" (let ((mp (clim::get-frame-pane canvas 'wb::host-pane))) ;(format t "~% Just inside h-draw:set-pen-color") ;(format t "~%s-p-c new-color is ~s " new-color) ;(format t "~%s-p-c canvas is ~s " canvas) ;(format t "~%s-p-c is canvas a frame ? ~s " (clim:application-frame-p canvas)) ;(format t "~%s-p-c does canvas have a host-pane ~s " (clim:get-frame-pane canvas 'host-pane)) (setf (clim:medium-foreground mp) new-color))) ;;; (defun set-pen-color (canvas color) "Set the color of canvas's pen to be color." ;(format t "~%Just inside set-pen-color") ;(format t "~%s-p-c input color is ~s " color) (unless (eq-colors color (pen-color-of canvas)) (with-display-mode canvas (display-mode-of canvas) (set-pen-color canvas color) (let ((pen (pen-of canvas))) ;(format t "~%s-p-c just in let pen is ~s " pen) (setf (slot-value pen 'pen-color) color) (cond ((colored-canvas-p canvas) (unless (colorp color) (setq color (shade-to-color color))) #-:sbcl-linux(h-draw:set-pen-color canvas color) #+:sbcl-linux(fix-pen-color canvas color) ;; copy of h-draw:set-pen-color but in :wb ;(format t "~%s-p-c just after fix-pen-color") ) (t (when (colorp color) (setq color (color-to-shade color))) (h-draw::set-pen-pattern canvas color))) ;(format t "~%s-p-c just out of cond") ;(format t "~%out going color is ~s " (slot-value pen 'pen-color)) ))) ) (defmethod (setf pen-of) ((new-pen pen) (self pen-mixin)) (setf (slot-value self 'pen) new-pen) (canvas-set-pen self :width (pen-width-of new-pen) :operation (pen-operation-of new-pen) :color (pen-color-of new-pen))) (defun canvas-set-pen (canvas &key (width nil) (operation nil) (color nil)) "Sets up the pen characteristics." ;(format t "~%Just inside canvas-set-pen") ;(format t "~%c-s-p input width is ~s " width) ;(format t "~%c-s-p input operation is ~s " operation) ;(format t "~%c-s-p input color is ~s " color) (unless width (setf width 1)) (unless operation (setf operation :default)) (unless color (setf color (pen-default-color canvas))) ;(format t "~%c-s-p after unlesses width is ~s " width) ;(format t "~%c-s-p after unlesses operation is ~s " operation) ;(format t "~%c-s-p after unlesses color is ~s " color) (set-pen-width canvas width) ;(format t "~%c-s-p After set-pen-width") ;(format t "~%c-s-p pen-width-of pen-of canvas is ~s " (pen-width-of (pen-of canvas))) ;(format t "~%c-s-p pen-with-of canvas is ~s " (pen-width-of canvas)) (cond ((colored-canvas-p canvas) (unless (colorp color) (setq color (shade-to-color color))) (set-pen-color canvas color)) (t (when (colorp color) (setq color (color-to-shade color))) (with-focused-canvas canvas (h-draw:set-pen-pattern canvas color)))) ;(format t "~%c-s-p After cond for color") ;(format t "~%c-s-p pen-color-of pen-of canvas is ~s " (pen-color-of (pen-of canvas))) (set-pen-operation canvas operation) ;(format t "~%c-s-p Finally, for pen-operation") ;(format t "~%c-s-p pen-operation-of pen-of canvas is ~s " (pen-operation-of (pen-of canvas))) ) (defmethod pen-width-of ((c pen-mixin)) (pen-width-of (pen-of c))) (defmethod pen-operation-of ((c pen-mixin)) (pen-operation-of (pen-of c))) (defmethod pen-texture-of ((c pen-mixin)) (pen-texture-of (pen-of c))) (defmethod pen-color-of ((c pen-mixin)) (pen-color-of (pen-of c))) (defun pen-default-color (canvas) (canvas-default-draw-color canvas))
11,982
Common Lisp
.l
249
41.313253
119
0.581521
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
e17a56bd2a9b12f38ab804b8168fd398c67937df0c40d1b70138822cc1d2a7b9
33,624
[ -1 ]
33,626
pen-sblx.lsp
rwoldford_Quail/source/window-basics/pen/pen-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; pen-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; R.W. Oldford 1989-1992 ;;; G.W. Bennett 1996 ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*pen-operations*))) (defconstant *pen-operations* (list :boole-1 :boole-2 :boole-andc1 :boole-andc2 :boole-and :boole-c1 :boole-c2 :boole-clr :boole-eqv :boole-ior :boole-nand :boole-nor :boole-orc1 :boole-orc2 :boole-set :boole-xor) "List of legal pen operations.")
1,156
Common Lisp
.l
34
29.941176
90
0.473684
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
468349198767d5a0a764b3d50147e0966fb644f008358c72a6ff99423b1b26c8
33,626
[ -1 ]
33,627
pen-pc.lsp
rwoldford_Quail/source/window-basics/pen/pen-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; pen-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; R.W. Oldford 1989-1992 ;;; G.W. Bennett 1996 ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(*pen-operations*))) (defconstant *pen-operations* (list :boole-1 :boole-2 :boole-andc1 :boole-andc2 :boole-and :boole-c1 :boole-c2 :boole-clr :boole-eqv :boole-ior :boole-nand :boole-nor :boole-orc1 :boole-orc2 :boole-set :boole-xor) "List of legal pen operations.")
1,189
Common Lisp
.l
34
29.882353
91
0.458803
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ce0ba9c0fb1c772de3b9e715c9da51506d63a0ab7d1bb8754cde51d6b4ff6fef
33,627
[ -1 ]
33,628
strings.lsp
rwoldford_Quail/source/window-basics/draw/strings.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; strings.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-string-region canvas-character-region canvas-character-width canvas-draw-string canvas-draw-character canvas-princ-string canvas-princ-character ))) (defun canvas-draw-horizontal-string (canvas string &key left bottom width height clip? justification) "Draw the string horizontally in the given region of the canvas." (unless width (setf width (canvas-string-width canvas string))) (unless height (setf height (canvas-font-height canvas))) (unless left (setf left (canvas-x canvas))) (unless bottom (setf bottom (canvas-y canvas))) (with-focused-canvas canvas (let* ((right (+ left width)) (top (+ bottom height)) (font (canvas-font canvas)) (string-wid (canvas-string-width canvas string :font font)) (vert-just (if (listp justification) (or (find :top justification) (find :bottom justification)) justification)) (horiz-just (if (listp justification) (or (find :left justification) (find :right justification)) justification)) (string-x (case horiz-just (:left left) (:right (max left (- (+ left width ) string-wid))) (t (max left (truncate (- (+ left right ) string-wid) 2))))) (string-y (case vert-just (:bottom (+ bottom (canvas-font-descent font))) (:top (max (+ bottom (canvas-font-descent font)) (- (+ bottom height) (canvas-font-ascent font)))) (t (max (+ bottom (canvas-font-descent font)) (truncate (- (+ bottom top) (+ (canvas-font-ascent font) (canvas-font-descent font)) ) 2)))))) (canvas-move-to canvas string-x string-y) (if clip? (clipped-draw-string canvas string (make-region left bottom width height)) (canvas-princ-string canvas string)) (canvas-move-to canvas (canvas-x canvas) bottom)))) (defun canvas-draw-vertical-string ;; added by C. Hurley (canvas string &key left bottom width height justification clip?) (unless width (setf width (canvas-string-width canvas "W"))) (unless height (setf height (* (length string) (canvas-font-height canvas)))) (unless left (setf left (canvas-x canvas))) (unless bottom (setf bottom (- (canvas-y canvas) height))) (with-focused-canvas canvas (let* ((font (canvas-font canvas)) (char-wid (canvas-string-width canvas "A")) (char-asc (canvas-font-ascent font)) (char-ht (+ char-asc (canvas-font-descent font))) (top (+ bottom height -1)) (vert-just (if (listp justification) (or (find :top justification) (find :bottom justification)) justification)) (horiz-just (if (listp justification) (or (find :left justification) (find :right justification)) justification)) (x-pos (case horiz-just (:left (+ left (truncate char-wid 2))) (:right (+ left (max 1 (- width (truncate char-wid 2))))) (t (+ left (max 1 (truncate (- width char-wid) 2)))))) (y-pos (case vert-just (:top top) (:bottom (- top (max 1 (round (- height (* char-ht (length string))))))) (t (- top (max 1 (round (- height (* char-ht (length string))) 2))))))) (decf y-pos char-asc) (canvas-move-to canvas x-pos y-pos) (with-display-mode canvas (display-mode-of canvas) (canvas-draw-vertical-str canvas x-pos y-pos string :bottom bottom :clip? clip?) (canvas-draw-vertical-str canvas x-pos y-pos string :bottom bottom :clip? clip?) )))) (defun canvas-draw-vertical-str (canvas x-pos y-pos string &key bottom clip?) (let ((char-ht (+ (canvas-font-ascent canvas) (canvas-font-descent canvas)))) (if clip? ; (loop for i from 0 below (length string) ; for char = (elt string i) ; while (> y-pos bottom) ; do (let ((slen (length string))) (do ((i 0 (incf i))) ((or (<= y-pos bottom) (= i slen))) (let ((char (elt string i))) (canvas-move-to canvas (- x-pos (truncate (canvas-string-width canvas (string char)) 2)) y-pos) (canvas-princ-character canvas char) (decf y-pos char-ht) (canvas-move-to canvas x-pos y-pos)))) ; (loop for i from 0 below (length string) ; for char = (elt string i) ; do (let ((slen (length string))) (do ((i 0 (incf i))) ((= i slen)) (let ((char (elt string i))) (canvas-move-to canvas (- x-pos (truncate (canvas-string-width canvas (string char)) 2)) y-pos) (canvas-princ-character canvas char) (decf y-pos char-ht) (canvas-move-to canvas x-pos y-pos))))))) (defun canvas-draw-character (canvas char &key (font NIL) (color NIL)) "Draws the character char on the canvas at the current pen-position ~ using the font font and color color. ~ Default values for font and color are those of the canvas." (with-canvas-font canvas font (with-pen-color canvas color (canvas-princ-character canvas char)))) (defun canvas-string-region (canvas string &key (vertical-p nil) (font (canvas-font canvas))) "Returns a region at the current pen location in the ~ canvas that will contain the given string." (if vertical-p (quail-error "Can't handle vertical text!")) (let ((ascent (canvas-font-ascent font)) (descent (canvas-font-descent font)) (width (canvas-string-width canvas string :font font)) (left (canvas-x canvas)) (bottom (canvas-y canvas))) (make-region left (- bottom descent) width (+ ascent descent) ))) (defun canvas-character-region (canvas char &key (font (canvas-font canvas))) "Returns a region at the current pen location in the ~ canvas that will contain the given character char." (canvas-string-region canvas (string char) :font font)) (defun canvas-character-width (canvas char &key (font (if canvas (canvas-font canvas) *normal-graphics-font*))) "Returns width (in pixels) of the given character char. ~ If canvas is NIL, it determines the ~ width according to the font alone." (declare (special *normal-graphics-font*)) (canvas-string-width canvas (string char) :font font)) (defun canvas-draw-string (canvas string &key (font nil) region left bottom width height (orientation NIL) (justification NIL) (clip? NIL) color) "Draw the string in the canvas. ~ Display the string in the given region (or that determined by left bottom ~ width and height) of canvas. If no region specs are given, the string is ~ drawn at the current pen position.~ Justification can be :left or :right to justify horizontal position, ~ :top or :bottom to justify vertical position, or a list of a vertical and/or ~ horizontal justification to specify both directions. Default justification is ~ :left horizontally and :bottom vertically. ~ If clip? is non-NIL, the string is clipped to the specified region." (unless orientation (setf orientation :horizontal)) (unless justification (setf justification (case orientation (:horizontal '(:bottom :left)) (:vertical '(:top :left))))) (when (not (stringp string)) (if (symbolp string) (setf string (string-capitalize (format NIL "~a" string))) (setq string (princ-to-string string)))) (when region (setf left (region-left region) width (region-width region) bottom (region-bottom region) height (region-height region))) (with-canvas-font canvas font (with-pen-color canvas color (if (eq orientation :horizontal) (canvas-draw-horizontal-string canvas string :left left :bottom bottom :width width :height height :justification justification :clip? clip?) (canvas-draw-vertical-string canvas string :left left :bottom bottom :width width :height height :justification justification :clip? clip?) )))) (defun canvas-draw-center-string (canvas string left bottom width height &key font) "Prints a string in canvas centred in a box of given width and height ~ and bottom left corner using the given font or the default canvas font." (unless (stringp string) (if (symbolp string) (setq string (symbol-name string)) (setq string (format nil "~s" string)))) (prog* ((font-used (or font (canvas-font canvas))) (str-width (canvas-string-width canvas string :font font-used))) (canvas-move-to canvas ; (+ left (floor (+ (- width str-width) 1) 2)) (+ bottom (floor (+ (- height (canvas-font-ascent font-used)) (canvas-font-descent font-used)) 2)) )) (canvas-draw-string canvas string :font font)) (defun canvas-princ-character (canvas char) "Draws the character char on the canvas at the current pen-position ~ using the current values of the canvas for font and color." (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-princ-character canvas char) (h-draw::draw-char canvas char)))) (defun canvas-princ-string (canvas string) "Draws the string on the canvas at the current pen-position ~ using the current values of the canvas for font and color." (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-princ-string canvas string) (h-draw::draw-string canvas string))))
12,266
Common Lisp
.l
278
32.352518
112
0.540945
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
7865aef3c82203f059615bb8a37f67ec12679d1a46489ad13e6f11b74892315b
33,628
[ -1 ]
33,629
draw-pc.lsp
rwoldford_Quail/source/window-basics/draw/draw-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; draw-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1992 ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-highlight-rectangle canvas-highlight-arc))) ;;; Highlight forms exist in cg:: but I need explanation from ;;; Franz about their functioning ;;; They turned out to be stubs to old stuff !! ;;; Thus highlight forms for drawing don't exist (defun canvas-highlight-rectangle (canvas left right bottom top &key color (operation :boole-xor) ) "Highlights a rectangle of canvas using color" (declare (special cg::po-paint cg::po-replace cg::po-invert cg::po-erase)) (if (eql operation :boole-xor) (progn ; for highlight mode on color (with-focused-canvas canvas (let ((old-op (pen-operation-of canvas))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-rectangle canvas left right bottom top :color color )) ; (format "~%[h-d:c-h-rect:1] new-op to go to s-p-mode is ~s " new-op) (h-draw::set-pen-mode canvas (boole-to-op old-op))))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-rectangle canvas left right bottom top :color color :operation operation)))) (defun canvas-highlight-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key color (operation :boole-xor) ) "Highlights an arc of canvas using color" (declare (special cg::po-invert cg::po-erase cg::po-paint cg::po-replace)) (if (eql operation :boole-xor) (progn ; for highlight mode on color (with-focused-canvas canvas (let ((old-op (pen-operation-of canvas))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :color color )) ; (format "~%[h-d:c-h-arc:1] new-op to go to s-p-mode is ~s " new-op) (h-draw::set-pen-mode canvas (boole-to-op old-op))))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :color color :operation operation)) ))
3,789
Common Lisp
.l
75
36
116
0.473287
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
ebe219f788d26499f9dd89eb3c26967cb78ac676856646ed781271efddbb9db7
33,629
[ -1 ]
33,630
draw-sblx.lsp
rwoldford_Quail/source/window-basics/draw/draw-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; draw-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; N.G. Bennett 1992 ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; M.E. Lewis 1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; G.W. Bennett 1996 ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-highlight-rectangle canvas-highlight-arc))) ;;; Highlight forms exist in cg:: but I need explanation from ;;; Franz about their functioning ;;; They turned out to be stubs to old stuff !! ;;; Thus highlight forms for drawing don't exist #| original acl version (defun canvas-highlight-rectangle (canvas left right bottom top &key color (operation :boole-xor) ) "Highlights a rectangle of canvas using color" (declare (special cg::po-paint cg::po-replace cg::po-invert cg::po-erase)) (if (eql operation :boole-xor) (progn ; for highlight mode on color (with-focused-canvas canvas (let ((old-op (pen-operation-of canvas))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-rectangle canvas left right bottom top :color color )) ; (format "~%[h-d:c-h-rect:1] new-op to go to s-p-mode is ~s " new-op) (h-draw::set-pen-mode canvas (boole-to-op old-op))))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-rectangle canvas left right bottom top :color color :operation operation)))) |# (defun canvas-highlight-rectangle (canvas left top right bottom ;top &key color (operation :boole-xor) ) "Highlights a rectangle of canvas using color" ;(let ((pane-of-canvas (get-frame-pane canvas 'host-pane))) (if (eql operation :boole-xor) (canvas-draw-filled-rectangle canvas left top right bottom ;top :color color) (canvas-draw-filled-rectangle canvas left top right bottom ;top :color color :operation operation) ) ;) ) #| original acl version (defun canvas-highlight-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key color (operation :boole-xor) ) "Highlights an arc of canvas using color" (declare (special cg::po-invert cg::po-erase cg::po-paint cg::po-replace)) (if (eql operation :boole-xor) (progn ; for highlight mode on color (with-focused-canvas canvas (let ((old-op (pen-operation-of canvas))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :color color )) ; (format "~%[h-d:c-h-arc:1] new-op to go to s-p-mode is ~s " new-op) (h-draw::set-pen-mode canvas (boole-to-op old-op))))) (cg::with-foreground-color (canvas color) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :color color :operation operation)) )) |# (defun canvas-highlight-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key color (operation :boole-xor) ) "Highlights an arc of canvas using color" (let ((pane-of-canvas (get-frame-pane canvas 'host-pane))) (if (eql operation :boole-xor) (progn ; for highlight mode on color (with-focused-canvas canvas (let ((old-op (pen-operation-of canvas))) (with-drawing-options (pane-of-canvas :ink color) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :color color )) ; (format "~%[h-d:c-h-arc:1] new-op to go to s-p-mode is ~s " new-op) (h-draw::set-pen-mode canvas (boole-to-op old-op))))) (with-drawing-options (pane-of-canvas :ink color) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :color color :operation operation)) )))
5,932
Common Lisp
.l
123
32.341463
115
0.468815
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0de8c067bc0108af634ba5ca89e313ac5fa1fd1210079c3cfe704f21ac75e3c0
33,630
[ -1 ]
33,631
strings-pc.lsp
rwoldford_Quail/source/window-basics/draw/strings-pc.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; strings-pc.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; ;;;------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-string-width))) (defun canvas-string-width (canvas string &key (font (if canvas (canvas-font canvas) *normal-graphics-font*))) "Returns the width of the string displayed in the canvas according to ~ the characteristics of font. If canvas is NIL, it determines the ~ width according to the font alone." (declare (special *normal-graphics-font*)) (cg::font-string-width (canvas-font-to-host-font font) string) )
1,384
Common Lisp
.l
30
39.266667
89
0.510355
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
9ad69105063665c23f31b47a4b1e6dae87b12312e7e90ab8c9cd7fdbdd8bea90
33,631
[ -1 ]
33,632
old-draw.lsp
rwoldford_Quail/source/window-basics/draw/old-draw.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; draw.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1992 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-x set-canvas-x canvas-y set-canvas-y canvas-draw-to canvas-draw-filled-rectangle canvas-draw-inside-rectangle canvas-draw-circle canvas-draw-filled-circle canvas-draw-polygon canvas-draw-filled-polygon canvas-invert canvas-clear canvas-draw-line canvas-draw-rectangle canvas-move-to canvas-draw-region canvas-flash-region draw-rect&corners canvas-draw-arc canvas-draw-filled-arc))) (defun canvas-x (canvas) (h-draw:point-x (h-draw:pen-position canvas))) (defun set-canvas-x (canvas new-x) (let ((current-y (h-draw:point-y (h-draw:pen-position canvas)))) (with-focused-canvas canvas (h-draw:move-to canvas new-x current-y)))) (defun canvas-y (canvas) (host-to-canvas-y canvas (h-draw:point-y (h-draw:pen-position canvas)))) (defun set-canvas-y (canvas new-y) (let ((current-x (h-draw:point-x (h-draw:pen-position canvas)))) (with-focused-canvas canvas (h-draw:move-to canvas current-x (canvas-to-host-y canvas new-y))))) (defun canvas-draw-to (canvas x y &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-to canvas x y) (h-draw:line-to canvas x (canvas-to-host-y canvas y)))))) (defun canvas-draw-filled-rectangle (canvas left right bottom top &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-rectangle canvas left right bottom top) (h-draw:paint-rect canvas left (canvas-to-host-y canvas top) right (canvas-to-host-y canvas bottom)))))) (defun canvas-draw-inside-rectangle (canvas left right bottom top &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-inside-rectangle canvas left right bottom top) (h-draw:frame-rect canvas left (canvas-to-host-y canvas top) right (canvas-to-host-y canvas bottom)))))) (defun canvas-draw-circle (canvas x y radius &key ;;(pattern *black-shade*) (width NIL) (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-circle canvas x y radius) (h-draw:frame-oval canvas (- x radius) (canvas-to-host-y canvas (+ y radius)) (+ x radius) (canvas-to-host-y canvas (- y radius))))))) (defun canvas-draw-filled-circle (canvas x y radius &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-circle canvas x y radius) (h-draw:paint-oval canvas (- x radius) (canvas-to-host-y canvas (+ y radius)) (+ x radius) (canvas-to-host-y canvas (- y radius))))))) (defun canvas-draw-polygon (canvas list-of-points &key (width NIL) (operation NIL) (color NIL) ) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-polygon canvas list-of-points) (canvas-move-to canvas (car (first list-of-points)) (cdr (first list-of-points))) (h-draw:start-polygon canvas) (dolist (point (cdr list-of-points)) (canvas-draw-to canvas (car point) (cdr point))) (canvas-draw-to canvas (car (first list-of-points)) (cdr (first list-of-points))) (let ((poly (h-draw:get-polygon canvas))) (h-draw:frame-polygon canvas poly) (h-draw:kill-polygon poly)))))) (defun canvas-draw-filled-polygon(canvas list-of-points &key (operation NIL) (color NIL) ;;(pattern *black-shade* ) ) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-polygon canvas list-of-points) (canvas-move-to canvas (car (first list-of-points)) (cdr (first list-of-points))) (h-draw:start-polygon canvas) (dolist (point (cdr list-of-points)) (canvas-draw-to canvas (car point) (cdr point))) (canvas-draw-to canvas (car (first list-of-points)) (cdr (first list-of-points))) ;;(h-draw:set-pen-pattern canvas pattern) (let ((poly (h-draw:get-polygon canvas))) (h-draw:paint-polygon canvas poly) (h-draw:kill-polygon poly)))))) (defun canvas-invert (canvas &key ; added by cbh (canvas-left 0) (canvas-bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas)) ) (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-invert canvas canvas-left canvas-bottom width height) (let ((canvas-top (+ -1 canvas-bottom height)) (canvas-right (+ -1 canvas-left width))) (h-draw:invert-rect canvas canvas-left (canvas-to-host-y canvas canvas-top) canvas-right (canvas-to-host-y canvas canvas-bottom)))))) (defun canvas-clear (canvas &key ; modified by cbh to clear a region (canvas-left 0) (canvas-bottom 0) (width (+ 15 (canvas-width canvas))) (height (+ 15 (canvas-height canvas))) ) "Clears specified rectangular areas of the canvas." (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-clear canvas :canvas-left canvas-left :canvas-bottom canvas-bottom :width width :height height) (let ((canvas-top (+ canvas-bottom height)) (canvas-right (+ canvas-left width))) (h-draw:erase-rect canvas canvas-left (canvas-to-host-y canvas canvas-top) canvas-right (canvas-to-host-y canvas canvas-bottom)))))) (defsetf canvas-x (canvas ) (new-x) `(let ((the-canvas ,canvas) (my-new-x ,new-x)) (with-display-mode the-canvas (display-mode-of the-canvas) (set-canvas-x the-canvas my-new-x) (set-canvas-x the-canvas my-new-x)) my-new-x)) (defsetf canvas-y (canvas) (new-y) `(let ((the-canvas ,canvas) (my-new-y ,new-y)) (with-display-mode the-canvas (display-mode-of the-canvas) (set-canvas-y the-canvas my-new-y) (set-canvas-y the-canvas my-new-y)) my-new-y)) (defun canvas-draw-rectangle (canvas x1 x2 y1 y2 &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-rectangle canvas x1 x2 y1 y2) (canvas-move-to canvas x1 y1) (canvas-draw-to canvas x1 y2) (canvas-draw-to canvas x2 y2) (canvas-draw-to canvas x2 y1) (canvas-draw-to canvas x1 y1))))) (defun canvas-draw-line (canvas x1 y1 x2 y2 &key (width NIL) (operation NIL) (color NIL) dashing) "Draw a line from (x1,y1) to (x2,y2) on the canvas. ~ Keywords width, operation, color, and dashing indicate the ~ style of line drawn." (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-line canvas x1 y1 x2 y2) (canvas-move-to canvas x1 y1) (canvas-draw-to canvas x2 y2))))) (defun canvas-move-to (canvas x y) (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-move-to canvas x y) (setf (canvas-x canvas) x) (setf (canvas-y canvas) y)))) (defun canvas-draw-region (canvas region &key (width nil) (operation nil) (color nil) dashing) "Draws a rectangle in canvas around the boundary of the supplied region." (canvas-draw-rectangle canvas (region-left region) (region-right region) (region-bottom region) (region-top region) :width width :operation operation :color color :dashing dashing )) (defun canvas-flash-region (canvas &key ; added by rwo (left 0) (bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas)) (times 2)) (if (< times 1) (quail-error "times must be greater than 0. times = ~S " times)) (do ((i 1 (incf i))) ((> times i)) (canvas-invert canvas :canvas-left left :canvas-bottom bottom :width width :height height) (canvas-invert canvas :canvas-left left :canvas-bottom bottom :width width :height height))) (defun draw-rect&corners (canvas rect &key (corner-width 10) (width NIL) (operation NIL) (color NIL)) "Draw squares of size corner-width in the corners of rect." (let ((d corner-width) vl vb vr vt) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (when (and (> (- vr vl) d) (> (- vt vb) d)) (canvas-draw-rectangle canvas vl (+ vl d) vb (+ vb d) :width width :operation operation :color color) (canvas-draw-rectangle canvas vr (- vr d) vb (+ vb d) :width width :operation operation :color color) (canvas-draw-rectangle canvas vl (+ vl d) vt (- vt d) :width width :operation operation :color color) (canvas-draw-rectangle canvas vr (- vr d) vt (- vt d) :width width :operation operation :color color)) (canvas-draw-rectangle canvas vl vr vb vt :width width :operation operation :color color))) (defun canvas-draw-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key (width NIL) (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius) (h-draw:draw-arc canvas start-angle arc-angle x-centre (canvas-to-host-y canvas y-centre) x-radius y-radius))))) (defun canvas-draw-filled-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius) (h-draw:fill-arc canvas start-angle arc-angle x-centre (canvas-to-host-y canvas y-centre) x-radius y-radius)))))
16,591
Common Lisp
.l
346
29.265896
124
0.459934
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
535599ee60b87d9a49648ecc6007f1af1dfa6a4afd6eb1d66a1cbfaf0ffc69ef
33,632
[ -1 ]
33,635
strings-sblx.lsp
rwoldford_Quail/source/window-basics/draw/strings-sblx.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; strings-sblx.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; Authors: ;;; C.B. Hurley 1989-1991 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; ;;;------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-string-width))) #| acl version (defun canvas-string-width (canvas string &key (font (if canvas (canvas-font canvas) *normal-graphics-font*))) "Returns the width of the string displayed in the canvas according to ~ the characteristics of font. If canvas is NIL, it determines the ~ width according to the font alone." (declare (special *normal-graphics-font*)) (cg::font-string-width (canvas-font-to-host-font font) string) ) |# ;;; NOTE for compatibility with Q, the keyword used is font ;;; although its value is a text-style ;;; gwb 24JAN2021 (defun canvas-string-width (canvas string &key (font *default-text-style*)) "returns the width of string on the pane of canvas ~ with respect to *default-text-style*. ~ There could be an &k argument for text-style." (declare (ignorable font)) ;10MAY20204 (let* ((mp (get-frame-pane canvas 'host-pane))) (stream-string-width mp string))) ;:font font))) mcclim does not support this arg
1,882
Common Lisp
.l
42
40.214286
88
0.580978
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
5da4746f28c837718d0125d796159a7661965d38b0d0d717fa4c4cef38d4e39f
33,635
[ -1 ]
33,637
draw.lsp
rwoldford_Quail/source/window-basics/draw/draw.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; draw.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; C.B. Hurley 1989-1992 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1991 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-x set-canvas-x canvas-y set-canvas-y canvas-draw-to canvas-draw-inside-square canvas-draw-square canvas-draw-filled-square canvas-draw-filled-rectangle canvas-draw-inside-rectangle canvas-draw-circle canvas-draw-filled-circle canvas-draw-polygon canvas-draw-filled-polygon canvas-invert canvas-clear canvas-draw-line canvas-draw-rectangle canvas-move-to canvas-draw-region canvas-flash-region draw-rect&corners canvas-draw-arc canvas-draw-filled-arc))) (defun canvas-x (canvas) (h-draw:point-x (h-draw:pen-position canvas))) (defun set-canvas-x (canvas new-x) (let ((current-y (h-draw:point-y (h-draw:pen-position canvas)))) (with-focused-canvas canvas (h-draw:move-to canvas new-x current-y)))) (defun canvas-y (canvas) (host-to-canvas-y canvas (h-draw:point-y (h-draw:pen-position canvas)))) (defun set-canvas-y (canvas new-y) (let ((current-x (h-draw:point-x (h-draw:pen-position canvas)))) (with-focused-canvas canvas (h-draw:move-to canvas current-x (canvas-to-host-y canvas new-y))))) (defun canvas-draw-to (canvas x y &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-to canvas x y) (h-draw:line-to canvas x (canvas-to-host-y canvas y)))))) (defun canvas-draw-inside-square (canvas x y sq-width &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-inside-square canvas x y sq-width) (h-draw:draw-inside-rectangle canvas x (canvas-to-host-y canvas (+ y sq-width)) (+ x sq-width) (canvas-to-host-y canvas y)))))) ;;; Original code #| (defun canvas-draw-square (canvas x y sq-width &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-square canvas x y sq-width) (h-draw:draw-rectangle canvas x (+ x sq-width) (canvas-to-host-y canvas y) (canvas-to-host-y canvas (+ y sq-width))))))) |# ;;; Original code (defun canvas-draw-filled-square (canvas x y sq-width &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-square canvas x y sq-width) (h-draw:draw-filled-rectangle canvas x (canvas-to-host-y canvas (+ y sq-width)) (+ x sq-width) (canvas-to-host-y canvas y)))))) ;;; Revised code to get h-draw:: call correct (defun canvas-draw-square (canvas x y sq-width &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-square canvas x y sq-width) (h-draw:draw-rectangle canvas x (canvas-to-host-y canvas y) (+ x sq-width) (canvas-to-host-y canvas (+ y sq-width))))))) (defun canvas-draw-inside-rectangle (canvas left right bottom top &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-inside-rectangle canvas left right bottom top) (h-draw:draw-inside-rectangle canvas left (canvas-to-host-y canvas top) right (canvas-to-host-y canvas bottom)))))) ;;; Original code #| (defun canvas-draw-rectangle (canvas x1 x2 y1 y2 &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-rectangle canvas x1 x2 y1 y2) (h-draw:draw-rectangle canvas x1 x2 (canvas-to-host-y canvas y1) (canvas-to-host-y canvas y2)))))) |# ;;; Revised code (defun canvas-draw-rectangle (canvas x1 x2 y1 y2 &key (width NIL) (operation NIL) (color NIL) dashing) (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-rectangle canvas x1 x2 y1 y2) (h-draw:draw-rectangle canvas x1 (canvas-to-host-y canvas y1) x2 (canvas-to-host-y canvas y2)))))) (defun canvas-draw-filled-rectangle (canvas left right bottom top &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-rectangle canvas left right bottom top) (h-draw:draw-filled-rectangle canvas left (canvas-to-host-y canvas top) right (canvas-to-host-y canvas bottom)))))) (defun canvas-draw-circle (canvas x y radius &key ;;(pattern *black-shade*) (width NIL) (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-circle canvas x y radius) (h-draw:draw-ellipse canvas (- x radius) (canvas-to-host-y canvas (+ y radius)) (+ x radius) (canvas-to-host-y canvas (- y radius)) ) )))) (defun canvas-draw-filled-circle (canvas x y radius &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-circle canvas x y radius) (h-draw:draw-filled-ellipse canvas (- x radius) (canvas-to-host-y canvas (+ y radius)) (+ x radius) (canvas-to-host-y canvas (- y radius)) ) )))) (defun canvas-draw-polygon (canvas list-of-points &key (width NIL) (operation NIL) (color NIL) ) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-polygon canvas list-of-points) (h-draw:draw-polygon canvas (mapcar #'(lambda (point) (cons (car point) (canvas-to-host-y canvas (cdr point)))) list-of-points)))))) (defun canvas-draw-filled-polygon (canvas list-of-points &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-polygon canvas list-of-points) (h-draw:draw-filled-polygon canvas (mapcar #'(lambda (point) (cons (car point) (canvas-to-host-y canvas (cdr point)))) list-of-points)))))) (defun canvas-invert (canvas &key ; added by cbh (canvas-left 0) (canvas-bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas)) ) (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-invert canvas canvas-left canvas-bottom width height) (let ((canvas-top (+ -1 canvas-bottom height)) (canvas-right (+ -1 canvas-left width))) (h-draw:invert-rectangle canvas canvas-left (canvas-to-host-y canvas canvas-top) canvas-right (canvas-to-host-y canvas canvas-bottom)))))) (defun canvas-clear (canvas &key ; modified by cbh to clear a region (canvas-left 0) (canvas-bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas)) ) "Clears specified rectangular areas of the canvas." (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-clear canvas :canvas-left canvas-left :canvas-bottom canvas-bottom :width width :height height) (let ((canvas-top (+ canvas-bottom height)) (canvas-right (+ canvas-left width))) (h-draw:erase-rect canvas canvas-left (canvas-to-host-y canvas canvas-top) canvas-right (canvas-to-host-y canvas canvas-bottom)))))) (defsetf canvas-x (canvas ) (new-x) `(let ((the-canvas ,canvas) (my-new-x ,new-x)) (with-display-mode the-canvas (display-mode-of the-canvas) (set-canvas-x the-canvas my-new-x) (set-canvas-x the-canvas my-new-x)) my-new-x)) (defsetf canvas-y (canvas) (new-y) `(let ((the-canvas ,canvas) (my-new-y ,new-y)) (with-display-mode the-canvas (display-mode-of the-canvas) (set-canvas-y the-canvas my-new-y) (set-canvas-y the-canvas my-new-y)) my-new-y)) (defun canvas-draw-line (canvas x1 y1 x2 y2 &key (width NIL) (operation NIL) (color NIL) dashing) "Draw a line from (x1,y1) to (x2,y2) on the canvas. ~ Keywords width, operation, color, and dashing indicate the ~ style of line drawn." (declare (ignore dashing)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-line canvas x1 y1 x2 y2) (h-draw:draw-line canvas x1 (canvas-to-host-y canvas y1) x2 (canvas-to-host-y canvas y2)))))) (defun canvas-move-to (canvas x y) (with-focused-canvas canvas (with-display-mode canvas (display-mode-of canvas) (canvas-move-to canvas x y) (setf (canvas-x canvas) x) (setf (canvas-y canvas) (canvas-to-host-y canvas y))))) (defun canvas-draw-region (canvas region &key (width nil) (operation nil) (color nil) dashing) "Draws a rectangle in canvas around the boundary of the supplied region." (canvas-draw-rectangle canvas (region-left region) (region-right region) (region-bottom region) (region-top region) :width width :operation operation :color color :dashing dashing )) (defun canvas-flash-region (canvas &key ; added by rwo (left 0) (bottom 0) (width (canvas-width canvas)) (height (canvas-height canvas)) (times 2)) (if (< times 1) (quail-error "times must be greater than 0. times = ~S " times)) (loop for i from 1 to times do (canvas-invert canvas :canvas-left left :canvas-bottom bottom :width width :height height) (canvas-invert canvas :canvas-left left :canvas-bottom bottom :width width :height height))) (defun draw-rect&corners (canvas rect &key (corner-width 10) (width NIL) (operation NIL) (color NIL)) "Draw squares of size corner-width in the corners of rect." (let ((d corner-width) vl vb vr vt) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (when (and (> (- vr vl) d) (> (- vt vb) d)) (canvas-draw-rectangle canvas vl (+ vl d) vb (+ vb d) :width width :operation operation :color color) (canvas-draw-rectangle canvas vr (- vr d) vb (+ vb d) :width width :operation operation :color color) (canvas-draw-rectangle canvas vl (+ vl d) vt (- vt d) :width width :operation operation :color color) (canvas-draw-rectangle canvas vr (- vr d) vt (- vt d) :width width :operation operation :color color)) (canvas-draw-rectangle canvas vl vr vb vt :width width :operation operation :color color))) (defun canvas-draw-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key (width NIL) (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color width operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius) (h-draw:draw-arc canvas start-angle arc-angle x-centre (canvas-to-host-y canvas y-centre) x-radius y-radius))))) (defun canvas-draw-filled-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key (operation NIL) (color NIL)) (with-focused-canvas canvas (with-pen-values canvas color NIL operation (with-display-mode canvas (display-mode-of canvas) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius) (h-draw:fill-arc canvas start-angle arc-angle x-centre (canvas-to-host-y canvas y-centre) x-radius y-radius)))))
19,469
Common Lisp
.l
410
28.697561
124
0.458837
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
05898b2225595536f06c56a10c5cc263ee7c62859594202ae6ace3022b2f6b73
33,637
[ -1 ]
33,638
erase.lsp
rwoldford_Quail/source/window-basics/draw/erase.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; erase.lisp ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) Statistical Computing Laboratory ;;; University of Waterloo ;;; Canada. ;;; ;;; This file is part of the Window-Basics package intended to provide a uniform ;;; window environment for Common Lisp programming. ;;; ;;; For copyright information and history, see window-basics-copyright.lisp ;;; ;;; Authors: ;;; H.A. Chipman 1991 ;;; C.B. Hurley 1989-1992 ;;; J.A. McDonald 1988-89 ;;; R.W. Oldford 1989-1992 ;;; J.O. Pedersen 1988-89 ;;; ;;; ;;; ;;;---------------------------------------------------------------------------------- (in-package :wb) (eval-when (:compile-toplevel :load-toplevel :execute) (export '(canvas-erase-to canvas-erase-line canvas-erase-rectangle canvas-erase-filled-rectangle canvas-erase-inside-rectangle canvas-erase-circle canvas-erase-filled-circle canvas-erase-polygon canvas-erase-filled-polygon canvas-erase-string erase-rect&corners canvas-erase-arc canvas-erase-filled-arc))) (defun canvas-erase-to (canvas x y &key width dashing operation) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-to canvas x y :width width :dashing dashing :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-line (canvas x1 y1 x2 y2 &key (width NIL) dashing operation) (with-focused-canvas canvas (canvas-move-to canvas x1 y1) (canvas-erase-to canvas x2 y2 :width width :dashing dashing :operation operation))) (defun canvas-erase-rectangle (canvas x1 x2 y1 y2 &key (width NIL) (operation NIL) dashing) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-rectangle canvas x1 x2 y1 y2 :width width :dashing dashing :operation operation) (set-pen-color canvas pen-color)) )) (defun canvas-erase-filled-rectangle (canvas left right bottom top &key (operation (pen-operation-of canvas)) ;;(pattern *black-shade*) ) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-filled-rectangle canvas left right bottom top :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-inside-rectangle (canvas left right bottom top &key (width NIL) (operation NIL) dashing) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-inside-rectangle canvas left right bottom top :width width :dashing dashing :operation operation) (set-pen-color canvas pen-color)) )) (defun canvas-erase-circle (canvas x y radius &key ;;(pattern *black-shade*) (width NIL) (operation NIL)) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-circle canvas x y radius :width width :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-filled-circle (canvas x y radius &key (operation NIL) ;;(pattern *black-shade*) ) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-filled-circle canvas x y radius :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-polygon (canvas list-of-points &key (width NIL) (operation NIL) ) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-polygon canvas list-of-points :width width :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-filled-polygon (canvas list-of-points &key (operation NIL) ;;(pattern *black-shade* ) ) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-filled-polygon canvas list-of-points :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-string (canvas string &key (font nil) region left bottom width height (orientation NIL) (justification NIL) (clip? NIL) color) "Erases the string in the canvas. ~ Erase the string in the given region (or that determined by left bottom ~ width and height) of canvas. If no region specs are given, the string is ~ erased at the current pen position.~ Justification can be :left or :right to justify horizontal position, ~ :top or :bottom to justify vertical position, or a list of a vertical and/or ~ horizontal justification to specify both directions. Default justification is ~ :left horizontally and :bottom vertically. ~ If clip? is non-NIL, the string is clipped to the specified region." (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-string canvas string :font font :region region :left left :bottom bottom :width width :height height :orientation orientation :justification justification :clip? clip? :color color) (set-pen-color canvas pen-color)))) (defun erase-rect&corners (canvas rect &key (corner-width 10) (width NIL) (operation NIL)) "Erase squares of size corner-width in the corners of rect." (let ((d corner-width) vl vb vr vt) (multiple-value-setq (vl vr vb vt) (region-bounds rect)) (when (and (> (- vr vl) d) (> (- vt vb) d)) (canvas-erase-rectangle canvas vl (+ vl d) vb (+ vb d) :width width :operation operation) (canvas-erase-rectangle canvas vr (- vr d) vb (+ vb d) :width width :operation operation) (canvas-erase-rectangle canvas vl (+ vl d) vt (- vt d) :width width :operation operation) (canvas-erase-rectangle canvas vr (- vr d) vt (- vt d) :width width :operation operation)) (canvas-erase-rectangle canvas vl vr vb vt :width width :operation operation ))) (defun canvas-erase-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key (width NIL) (operation NIL)) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :width width :operation operation) (set-pen-color canvas pen-color)))) (defun canvas-erase-filled-arc (canvas start-angle arc-angle x-centre y-centre x-radius y-radius &key (operation NIL) ;;(pattern *black-shade*) ) (with-focused-canvas canvas (let ((pen-color (pen-color-of canvas))) (set-pen-color canvas (canvas-background-color canvas)) (canvas-draw-filled-arc canvas start-angle arc-angle x-centre y-centre x-radius y-radius :operation operation) (set-pen-color canvas pen-color))))
9,714
Common Lisp
.l
203
32.55665
100
0.514265
rwoldford/Quail
0
1
0
GPL-3.0
9/19/2024, 11:43:28 AM (Europe/Amsterdam)
0d01011d167ae4fa9cb25692cebf02048abc23bb2c8fa5f9e1a3c55c85304e33
33,638
[ -1 ]