The ClickLoc

Date:    Sun, 16 Jul 1995 14:39:18 EDT
From:    John Dowdell <71333.42@COMPUSERVE.COM>
Subject: Re: The ClickLoc (and more, longish)

Ted Therriault writes on July 14, "What is the simplest way of extracting the horizontal and vertical point values from 'the clickloc.'"

The "clickLoc" function returns a point -- the position on the screen of the last mouse click. The "point" and "rect" datatypes are similar to lists in a number of ways.

Points have internal "locH" and "locV" properties, and rects have internal "left", "top", "right", and "bottom" properties. For instance, in the case you're hunting down:

  if the locH of the clickLoc > 320 then put "right side!"

You could also do either of the following:

  put getAt (the clickLoc, 1)
  put getaProp (the clickLoc, #locH)
but I prefer the first example, myself, 'cause the syntax is more natural. I don't think this is explicitly mentioned in the manuals... I found it by accident myself soon after release... but from what I understand from John Thompson this is stable and intrinsic to the structure of these datatypes.

For rects you can do things like:

  set theRect = the rect of sprite (the clickOn)
  set width = the right of theRect - the left of theRect
A related topic is operations upon lists, points, and rects. Scalars, matrix operations, and comparisons work too... many permutations. Some stuff from the Message Window:
  set ptA = point(100, 100)
  set ptB = point(150, 150)

  --  Scalar operations:
  put ptA + 75
  -- point(175, 175)
  put ptB/2
  -- point(75, 75)

  --  Point-to-point comparisons:
  put ptB > ptA
  -- 1

  --  Point-to-point operations:
  put ptB - ptA
  -- point(50, 50)

  --  Point-to-list operations (performed to
  --  number of elements in smaller list):
  put ptA + [30]
  -- [130]
  put ptA + [30, 45]
  -- point(130, 145)
  put ptA + [30, 45, 60]
  -- point(130, 145)

  set rectA = rect(0, 20, 200, 320)
  put rectA * 2
  -- rect(0, 40, 400, 640)

  --  Rect-to-point work is also performed
  --  to number of elements in smaller list:
  put ptA > rectA
  -- 1
  put ptA + rectA
  -- point(100, 120)

  set listA = [5, 10]
  set listB = [9, 12]
  put listB - listA
  -- [4, 2]
  set listC = [1, 2, 3]
  put listA * listC
  -- [5, 20]

  --  Property lists are a bit different:
  set propA = [#alpha: 5, #beta: 10]
  set propB = [#alpha: 9, #beta: 12]
  set propC = [#moe: 1, #larry: 2, #shemp: 3]
  put propA + propB
  -- [#alpha: 14, #beta: 22]
  put propA * propB
  -- [#alpha: 45, #beta: 120]
  put propA + propC
  -- [#alpha: 6, #beta: 12]
  put propA * propC
  -- [#alpha: 5, #beta: 20]
  put propA < propB
  -- 1
Apologies if the above is too lengthy! Sometimes "point" and "rect" work allows for some very graceful solutions, with scripts that are much clearer than previous handlings. I don't think any of us have explored them fully yet, but there's some neat stuff in there.