(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,
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..?
> (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)))))
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
> 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
In article <8t4fs8$ea...@nnrp1.deja.com>, sung...@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.
> In article <8t4fs8$ea...@nnrp1.deja.com>, sung...@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.
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.)
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,
* sung...@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
> * sung...@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
sung...@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.
* sung...@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
In article <3181487131446...@naggum.net>, Erik Naggum <e...@naggum.net> wrote:
> * sung...@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?
sung...@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
+--------------- | Erik Naggum <e...@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 r...@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 <8te8co$3n0t...@fido.engr.sgi.com>, r...@rigden.engr.sgi.com (Rob Warnock) writes:
> <sung...@cad.strath.ac.uk> wrote: > +--------------- >| Erik Naggum <e...@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,
| > +--------------- | >| 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 r...@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 <mike...@mikemac.com> wrote: > +--------------- > | r...@rigden.engr.sgi.com (Rob Warnock) writes: > | > <sung...@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.
* 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