-------------------------------
(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.
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))
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/
--------------------------------------
(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)))))
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.
--
> 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
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
> 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
> | :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
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)))))
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.)
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
> > | 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
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..
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?
> 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
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
Isn't the "11" the number of characters read?
Mike McDonald
mik...@mikemac.com
Doh! Of course! I was so fixated on the "#@" I didn't think about
the definition of "read-from-string". (Oops!)
>
> 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.
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