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.
From: ·······@cad.strath.ac.uk
Subject: Oops!! sorry about the format...
Date:
Message-ID: <8t4fs8$eao$1@nnrp1.deja.com>
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))
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <············@nnrp1.deja.com>, ·······@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
From: ·······@cad.strath.ac.uk
Subject: Re: Oops!! sorry about the format...
Date:
Message-ID: <8t6488$pih$1@nnrp1.deja.com>
Thanks thanks, =)
It is very clear to me.
Sungwoo
In article <·····················@solg4.keke.org>,
····@mac.com (Keke Abe) wrote:
> In article <············@nnrp1.deja.com>, ·······@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
>
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <············@nnrp1.deja.com>, ·······@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: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: ·······@cad.strath.ac.uk
Subject: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <8t4s5v$pit$1@nnrp1.deja.com>
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)))))
Sent via Deja.com http://www.deja.com/
Before you buy.
> 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: ·············@corporate-world.lisp.de
> Web: http://corporate-world.lisp.de/
>
Wow~!! this code is much optimised... =)
Thanks!!
Sungwoo
Sent via Deja.com http://www.deja.com/
Before you buy.
From: Erik Naggum
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <3181422129028271@naggum.net>
* ·······@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
From: ·······@cad.strath.ac.uk
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <8t64u0$q0d$1@nnrp1.deja.com>
> | :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
Sent via Deja.com http://www.deja.com/
Before you buy.
From: Erik Naggum
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <3181474687540902@naggum.net>
* ·······@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
From: ·······@cad.strath.ac.uk
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <8t714n$h00$1@nnrp1.deja.com>
In article <················@naggum.net>,
Erik Naggum <····@naggum.net> wrote:
> * ·······@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
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <············@nnrp1.deja.com>,
·······@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
From: Erik Naggum
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <3181487131446059@naggum.net>
* ·······@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
From: ·······@cad.strath.ac.uk
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <8t7b5r$qdg$1@nnrp1.deja.com>
In article <················@naggum.net>,
Erik Naggum <····@naggum.net> wrote:
> * ·······@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?
Sungwoo
Sent via Deja.com http://www.deja.com/
Before you buy.
From: Thomas A. Russ
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <ymiitqg30o2.fsf@sevak.isi.edu>
·······@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 ···@isi.edu
<·······@cad.strath.ac.uk> wrote:
+---------------
| Erik Naggum <····@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 ····@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
In article <··············@fido.engr.sgi.com>,
····@rigden.engr.sgi.com (Rob Warnock) writes:
> <·······@cad.strath.ac.uk> wrote:
> +---------------
>| Erik Naggum <····@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
·······@mikemac.com
Mike McDonald <·······@mikemac.com> wrote:
+---------------
| ····@rigden.engr.sgi.com (Rob Warnock) writes:
| > <·······@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!)
-Rob
-----
Rob Warnock, 31-2-510 ····@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
From: Kent M Pitman
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <sfwsnpevm6p.fsf@world.std.com>
····@rigden.engr.sgi.com (Rob Warnock) writes:
>
> Mike McDonald <·······@mikemac.com> wrote:
> +---------------
> | ····@rigden.engr.sgi.com (Rob Warnock) writes:
> | > <·······@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.
From: Erik Naggum
Subject: Re: Now I got perfect freehand drawing function ^^
Date:
Message-ID: <3181898319429682@naggum.net>
* 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
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)))))
Sent via Deja.com http://www.deja.com/
Before you buy.