home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 20972 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.1 KB

  1. Path: sparky!uunet!gatech!darwin.sura.net!zaphod.mps.ohio-state.edu!malgudi.oar.net!hyperion!desire.wright.edu!jmatthews
  2. From: jmatthews@desire.wright.edu
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Detecting double click?
  5. Message-ID: <1993Jan8.002831.6471@desire.wright.edu>
  6. Date: 8 Jan 93 00:28:31 EST
  7. Organization:  Wright State University 
  8. Lines: 52
  9.  
  10. Recently I suggested the following way to check for double clicks:
  11.  
  12.  var gLastMouseUp: EventRecord;
  13.  
  14.  procedure SaveLastMouseUp(event: EventRecord);
  15.  begin
  16.    gLastMouseUp := event
  17.  end;
  18.  
  19.  function CheckDoubleClick (event: EventRecord): Boolean;
  20.    var slop: Rect;
  21.  begin
  22.    with gLastMouseUp.where do
  23.      SetRect(slop, h - 2, v - 2, h + 2, v + 2);
  24.    CheckDoubleClick:= ((event.when - gLastMouseUp.when) <=
  25.      GetDblTime) and (PtInRect(event.where, slop))
  26.  end;
  27.  
  28. In the main event loop, call SaveLastMouseUp in response to mouseUp
  29. events, and call CheckDoubleClick in response to mouseDown events. The
  30. latter returns true when a double click (as defined in IM vol.I,
  31. p.260) occurs.
  32.  
  33. This definition of a double click can lead to some confusion in
  34. subsequent calls to StillDown or WaitMouseUp. An alternative is to
  35. measure time between mouseDown events as follows:
  36.  
  37.  var gLastMouseDown: EventRecord;
  38.  {should initialize gLastMouseDown.when to 0}
  39.  
  40.  function CheckDoubleClick (event: EventRecord): Boolean;
  41.    var
  42.      slop: Rect;
  43.      test: Boolean;
  44.  begin
  45.    with gLastMouseDown.where do
  46.      SetRect(slop, h - 2, v - 2, h + 2, v + 2);
  47.    test := ((event.when - gLastMouseDown.when) <= GetDblTime) and
  48.             (PtInRect(event.where, slop));
  49.    if test then
  50.      gLastMouseDown.when := 0 {prevent multiple clicks}
  51.    else
  52.      gLastMouseDown := event; {save this one for future testing}
  53.    CheckDoubleClick := test
  54.  end;
  55.  
  56. How are others doing it?
  57.  
  58. o----------------------------------------------------------------------------o
  59. | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
  60. |      "Whom the gods would destroy, they first invite to program in C"      |
  61. o----------------------------------------------------------------------------o
  62.