Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Apple Event + drawing?

7 views
Skip to first unread message

sun...@cad.strath.ac.uk

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
Hello,
I am trying to draw a free line on a window.
Following codes are obviously doesn't work.

-------------------------------
(require 'quickdraw)

(defparameter *w* (make-instance 'window
:window-title "SketchPad"
:view-nick-name 'sketchpad
:view-size #@(400 300)))

(defun get-mouse-position(x y) (setf (x y) <--------------- this is bad.
How can I get the (%get-ptr (view-mouse-position *w*)))) current
coordinates of mouse position? (defun sketching ()
(with-focused-view *w* (get-mouse-position x y) (when #$mouseDown
<-------------- here problem as well.... (loop is this correct
way to call a mouse (require-trap #_lineto x y) event?
(get-mouse-position next-x next-y) (setf x next-x) (setf y next-y) (if
#$mouseUp (return)))) nil)) --------------------------- Would you give me
some correction please? Thanks,

Sungwoo


Sent via Deja.com http://www.deja.com/
Before you buy.

sun...@cad.strath.ac.uk

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
Sorry about the format. I am trying to draw a free line on window, and
following code doesn't work. My question is (1) how can I get the current
coordinates of mouse position? (2) is this right way to call mouse event?
(sure.. it is not... cos it doesn't work..) how can I call the event..?

Thanks,

Sungwoo
-----------------
;;
;; SketchPad
;;

(require 'quickdraw)

(defparameter *w* (make-instance 'window
:window-title "SketchPad"
:view-nick-name 'sketchpad
:view-size #@(400 300)))

;;
;; (if pencil-radio-button (pen-show *w*) (pen-hide *w*))
;;

(defun get-mouse-position(x y)
(setf (x y)

(%get-ptr (view-mouse-position *w*))))

(defun sketching ()
(with-focused-view *w*
(get-mouse-position x y)
(when #$mouseDown

(loop
(require-trap #_lineto x y)


(get-mouse-position next-x next-y)
(setf x next-x)
(setf y next-y)
(if #$mouseUp (return))))
nil))

Rainer Joswig

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
In article <8t4fe9$dqd$1...@nnrp1.deja.com>, sun...@cad.strath.ac.uk
wrote:

AppleEvents are something different. A method for Interprocess
communication.

> Hello,
> I am trying to draw a free line on a window.
> Following codes are obviously doesn't work.
>
> -------------------------------

> (require 'quickdraw)
>
> (defparameter *w* (make-instance 'window
> :window-title "SketchPad"
> :view-nick-name 'sketchpad
> :view-size #@(400 300)))
>

> (defun get-mouse-position(x y) (setf (x y) <--------------- this is bad.

> How can I get the (%get-ptr (view-mouse-position *w*)))) current
> coordinates of mouse position? (defun sketching ()

> (with-focused-view *w* (get-mouse-position x y) (when #$mouseDown

> <-------------- here problem as well.... (loop is this correct
> way to call a mouse (require-trap #_lineto x y) event?

> (get-mouse-position next-x next-y) (setf x next-x) (setf y next-y) (if

> #$mouseUp (return)))) nil)) --------------------------- Would you give me
> some correction please? Thanks,

Above text is totally distorted.

I really think reading the MCL manual (yes, sometimes I read manuals),
reading a bit about Quickdraw and looking at the example code
in the examples directory might help.

Anyway, here is a simple example:

(require 'quickdraw)

; A simple drawing object:
(defclass simple-drawing-item (dialog-item) ())

; our own click handling routine for this item class
(defmethod dialog-item-action ((view simple-drawing-item))
(let ((where (view-mouse-position view))
position)
(flet ((draw-a-line (from to)
(move-to view from)
(line-to view to)))
(with-pen-saved
(set-pen-mode view :patxor)
(loop while (mouse-down-p)
for last-position = nil then position
do (setf position (view-mouse-position view))
do (unless (eql last-position position)
(if last-position
(progn
(draw-a-line where last-position)
(draw-a-line where position))
(draw-a-line where position)))))
(when position
(draw-a-line where position)))))

(defparameter *w1*

(make-instance 'window
:window-title "SketchPad"
:view-nick-name 'sketchpad
:view-size #@(400 300)

:color-p t
:view-subviews (list
(make-instance 'simple-drawing-item
:view-size #@(400 300)))))

--
Rainer Joswig, Hamburg, Germany
Email: mailto:jos...@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/

sun...@cad.strath.ac.uk

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
Thanks for your help. =)
I changed something to work for real freehand drawing.
(and it works! ^^)
Please take a look follow codes, and give me any comment if you have.
Thanks again. =)
Sungwoo

--------------------------------------
(require 'quickdraw)

(defclass simple-drawing-item (dialog-item) ())

(defmethod dialog-item-action ((view simple-drawing-item))
(let ((where (view-mouse-position view))
position)
(flet ((draw-a-line (from to)
(move-to view from)
(line-to view to))

(add-a-line (to)
(line-to view to)))
(with-pen-saved
(set-pen-mode view :patOr)


(loop while (mouse-down-p)
for last-position = nil then position
do (setf position (view-mouse-position view))
do (unless (eql last-position position)
(if last-position
(progn

(add-a-line last-position)
(add-a-line position))
(draw-a-line where position))))))))

(defparameter *w1*
(make-instance 'window
:window-title "SketchPad"
:view-nick-name 'sketchpad
:view-size #@(400 300)
:color-p t
:view-subviews (list
(make-instance 'simple-drawing-item
:view-size #@(400 300)))))

Rainer Joswig

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
In article <8t4s5v$pit$1...@nnrp1.deja.com>, sun...@cad.strath.ac.uk
wrote:

This should do the same:

(defmethod dialog-item-action ((view simple-drawing-item))
(move-to view (view-mouse-position view))


(with-pen-saved
(set-pen-mode view :patOr)
(loop while (mouse-down-p)

do (line-to view (view-mouse-position view)))))

>
> (defparameter *w1*
> (make-instance 'window
> :window-title "SketchPad"
> :view-nick-name 'sketchpad
> :view-size #@(400 300)
> :color-p t
> :view-subviews (list
> (make-instance 'simple-drawing-item
> :view-size #@(400 300)))))
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

--

sun...@cad.strath.ac.uk

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to

> This should do the same:
>
> (defmethod dialog-item-action ((view simple-drawing-item))
> (move-to view (view-mouse-position view))
> (with-pen-saved
> (set-pen-mode view :patOr)
> (loop while (mouse-down-p)
> do (line-to view (view-mouse-position view)))))
>
> >
> > (defparameter *w1*
> > (make-instance 'window
> > :window-title "SketchPad"
> > :view-nick-name 'sketchpad
> > :view-size #@(400 300)
> > :color-p t
> > :view-subviews (list
> > (make-instance 'simple-drawing-item
> > :view-size #@(400 300)))))
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> --
> Rainer Joswig, Hamburg, Germany
> Email: mailto:jos...@corporate-world.lisp.de
> Web: http://corporate-world.lisp.de/
>

Wow~!! this code is much optimised... =)
Thanks!!

Sungwoo

Erik Naggum

unread,
Oct 24, 2000, 8:22:09 PM10/24/00
to
* sun...@cad.strath.ac.uk
| :view-size #@(400 300)

What does this #@ reader macro expand to?

#:Erik
--
I agree with everything you say, but I would
attack to death your right to say it.
-- Tom Stoppard

Keke Abe

unread,
Oct 24, 2000, 10:41:01 PM10/24/00
to
In article <8t4fs8$eao$1...@nnrp1.deja.com>, sun...@cad.strath.ac.uk wrote:

> I am trying to draw a free line on window, and
> following code doesn't work. My question is (1) how can I get the current
> coordinates of mouse position? (2) is this right way to call mouse event?
> (sure.. it is not... cos it doesn't work..) how can I call the event..?

#1 Use VIEW-MOUSE-POSITION

#2 You don't want to call the mouse event by yourself. Instead, you handle
the event signaled by MCL.

> (defun get-mouse-position(x y)
> (setf (x y)

> (%get-ptr (view-mouse-position *w*))))

This doesn't look like Lisp.

>
> (defun sketching ()
> (with-focused-view *w*
> (get-mouse-position x y)
> (when #$mouseDown

> (loop
> (require-trap #_lineto x y)

> (get-mouse-position next-x next-y)
> (setf x next-x)
> (setf y next-y)
> (if #$mouseUp (return))))
> nil))

* X, Y, NEXT-X and NEXT-Y are all 'undeclared free variables'.
* #$mouseDown and #$mouseUp are constants.
* REQUIRE-TRAP is not necessary.


(defclass my-win (window) ())

(defmethod view-click-event-handler ((win my-win) where)
(with-focused-view win
(#_moveto (point-h where) (point-v where))
(loop while (mouse-down-p)
do
(let ((pos (view-mouse-position win)))
(#_lineto (point-h pos) (point-v pos))))))

#|
(make-instance 'my-win)
|#

regards,
abe

sun...@cad.strath.ac.uk

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
Thanks thanks, =)
It is very clear to me.

Sungwoo


In article <keke-25100...@solg4.keke.org>,

sun...@cad.strath.ac.uk

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to

> | :view-size #@(400 300)
>
> What does this #@ reader macro expand to?
>

According to MCL Reference, the reader macro #@ converts the subsequent list
of two integers into a point. This can be used for clarity in source code.
For example, #@(30 -100) expands into -6553570, an integer that represents
the point with a horizontal coordinate of 30 and a vertical coordinate of
–100. The integer that encodes the x and y coordinates of a point is
automatically converted to a bignum if a fixnum cannot accommodate it. (For
definitions of bignum and fixnum, see Common Lisp: The Language.)

Sungwoo

sun...@cad.strath.ac.uk

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
Based on a couple of feedbacks, I changed the code as below
because I want get the local coordinates of each stroke and
sub-view as well. Is this well optimised or something more can be done?
Thanks,

Sungwoo
---------------------------------------------------------------------------
(defclass simple-drawing-item (dialog-item) ())

(defmethod dialog-item-action ((view simple-drawing-item))
(let ((where (view-mouse-position view)))


(#_moveto (point-h where) (point-v where))

(with-pen-saved
(set-pen-mode view :patOr)
(loop while (mouse-down-p)
do
(let ((pos (view-mouse-position view)))
(#_lineto (point-h pos) (point-v pos)))))))

(defparameter *w1*
(make-instance 'window
:window-title "SketchPad"
:view-nick-name 'sketchpad
:view-size #@(400 300)
:color-p t
:view-subviews (list
(make-instance 'simple-drawing-item
:view-size #@(400 300)))))

Erik Naggum

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
* sun...@cad.strath.ac.uk

| According to MCL Reference, the reader macro #@ converts the
| subsequent list of two integers into a point.

That's nice, but what does it expand to? That is, does the reader
macro function actually return just an integer, or does whatever it
returns _evaluate_ to an integer? Is there a @ reader macro, too?

(If you think you have to talk about bignums and fixnums, you're
missing an important point about Lisp's integer concept.)

sun...@cad.strath.ac.uk

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
In article <31814746...@naggum.net>,

Erik Naggum <er...@naggum.net> wrote:
> * sun...@cad.strath.ac.uk
> | According to MCL Reference, the reader macro #@ converts the
> | subsequent list of two integers into a point.
>
> That's nice, but what does it expand to? That is, does the reader
> macro function actually return just an integer, or does whatever it
> returns _evaluate_ to an integer? Is there a @ reader macro, too?
>
> (If you think you have to talk about bignums and fixnums, you're
> missing an important point about Lisp's integer concept.)
>
> #:Erik
> --
> I agree with everything you say, but I would
> attack to death your right to say it.
> -- Tom Stoppard
>

The reader macro in this case expand the coordinates of pointer, because
points are always returned as a single encoded integer. In this case, the
macro returns actual integer only (I maybe wrong).

I didn't mean that bignums and fixnums are important, I just copied text for
your information. =) Definately, I miss a lot of point of Lisp cos I am a
just newbie of Common Lisp. =) Sungwoo

Keke Abe

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
In article <8t714n$h00$1...@nnrp1.deja.com>,
sun...@cad.strath.ac.uk wrote:

> > | According to MCL Reference, the reader macro #@ converts the
> > | subsequent list of two integers into a point.
> >
> > That's nice, but what does it expand to? That is, does the reader
> > macro function actually return just an integer, or does whatever it
> > returns _evaluate_ to an integer? Is there a @ reader macro, too?
>

> The reader macro in this case expand the coordinates of pointer, because
> points are always returned as a single encoded integer. In this case, the
> macro returns actual integer only (I maybe wrong).

If both h and v can be fit into 16bit signed integer, the macro
function returns an integer. Otherwise #@(h v) expands into
'(ccl::make-big-point h v) whicl, in turn, evaluates to cons (h . v).
The former is handy because MacOS toolbox uses the same format for
points.

regards,
abe

Erik Naggum

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
* sun...@cad.strath.ac.uk

| The reader macro in this case expand the coordinates of pointer,
| because points are always returned as a single encoded integer. In
| this case, the macro returns actual integer only (I maybe wrong).

OK, could you please type (read-from-string "#@(400 300)") into a
listener and post the result?

sun...@cad.strath.ac.uk

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
In article <31814871...@naggum.net>,

Erik Naggum <er...@naggum.net> wrote:
> * sun...@cad.strath.ac.uk
> | The reader macro in this case expand the coordinates of pointer,
> | because points are always returned as a single encoded integer. In
> | this case, the macro returns actual integer only (I maybe wrong).
>
> OK, could you please type (read-from-string "#@(400 300)") into a
> listener and post the result?
>
> #:Erik
> --
> I agree with everything you say, but I would
> attack to death your right to say it.
> -- Tom Stoppard
>

Here is the result. ----------------------------- ? (read-from-string "#@(400
300)") 19661200 11 ----------------------------- Hmm.. it excute something..
What does excuted from that integer? Ok, I was wrong (as you expected). I
took a look the combination of 'shapesign' from Hyperspec 4.0 manual, but
couldn't find #@. Strange.... Dispatch @ is undefined... so how does this
works?

Thomas A. Russ

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
sun...@cad.strath.ac.uk writes:

> I took a look the combination of 'shapesign' from Hyperspec 4.0 manual, but
> couldn't find #@. Strange.... Dispatch @ is undefined... so how does this
> works?

It is an MCL extension to Common Lisp, so you won't find it in the
HyperSpec. It will be in the MCL specific documentation.


--
Thomas A. Russ, USC/Information Sciences Institute t...@isi.edu

Rob Warnock

unread,
Oct 28, 2000, 6:05:12 AM10/28/00
to
<sun...@cad.strath.ac.uk> wrote:
+---------------

| Erik Naggum <er...@naggum.net> wrote:
| > OK, could you please type (read-from-string "#@(400 300)") into a
| > listener and post the result?
|
| Here is the result. ? (read-from-string "#@(400 300)") 19661200 11
| Hmm.. it excute something..
+---------------

I don't know what the second result value "11" is,
but the first one is:

> (+ 400 (* 65536 300))
19661200
>

which is consistent with what someone else said about
small "points" having 16-bit components...


-Rob

-----
Rob Warnock, 31-2-510 rp...@sgi.com
Network Engineering http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043

Mike McDonald

unread,
Oct 29, 2000, 6:51:34 PM10/29/00
to
In article <8te8co$3n0th$1...@fido.engr.sgi.com>,

rp...@rigden.engr.sgi.com (Rob Warnock) writes:
> <sun...@cad.strath.ac.uk> wrote:
> +---------------
>| Erik Naggum <er...@naggum.net> wrote:
>| > OK, could you please type (read-from-string "#@(400 300)") into a
>| > listener and post the result?
>|
>| Here is the result. ? (read-from-string "#@(400 300)") 19661200 11
>| Hmm.. it excute something..
> +---------------
>
> I don't know what the second result value "11" is,

Isn't the "11" the number of characters read?

Mike McDonald
mik...@mikemac.com

Rob Warnock

unread,
Oct 29, 2000, 10:36:27 PM10/29/00
to
Mike McDonald <mik...@mikemac.com> wrote:
+---------------

| rp...@rigden.engr.sgi.com (Rob Warnock) writes:
| > <sun...@cad.strath.ac.uk> wrote:
| > +---------------
| >| Here is the result. ? (read-from-string "#@(400 300)") 19661200 11
| >| Hmm.. it excute something..
| > +---------------
| >
| > I don't know what the second result value "11" is,
|
| Isn't the "11" the number of characters read?
+---------------

Doh! Of course! I was so fixated on the "#@" I didn't think about
the definition of "read-from-string". (Oops!)

Kent M Pitman

unread,
Oct 30, 2000, 2:10:38 AM10/30/00
to
rp...@rigden.engr.sgi.com (Rob Warnock) writes:

>
> Mike McDonald <mik...@mikemac.com> wrote:
> +---------------
> | rp...@rigden.engr.sgi.com (Rob Warnock) writes:
> | > <sun...@cad.strath.ac.uk> wrote:
> | > +---------------
> | >| Here is the result. ? (read-from-string "#@(400 300)") 19661200 11
> | >| Hmm.. it excute something..
> | > +---------------
> | >
> | > I don't know what the second result value "11" is,
> |
> | Isn't the "11" the number of characters read?
> +---------------
>
> Doh! Of course! I was so fixated on the "#@" I didn't think about
> the definition of "read-from-string". (Oops!)

It's the ending position in the string (the position of the first char
not read) ... which in the case of a non-zero :start will be different
than the number of characters read.

Erik Naggum

unread,
Oct 30, 2000, 7:38:39 AM10/30/00
to
* Rob Warnock

| I don't know what the second result value "11" is,
| but the first one is:
|
| > (+ 400 (* 65536 300))
| 19661200
| >
|
| which is consistent with what someone else said about
| small "points" having 16-bit components...

Thanks. Allow me a stylistic comment to this addition and
multiplication approach. If we have 16-bit fields, I would much
prefer something like this:

(dpb 300 (byte 16 16) 400)

But maybe that's the old PDP-10 heritage rearing its elegant head.

#:Erik
--
Does anyone remember where I parked Air Force One?
-- George W. Bush

0 new messages