Graphics_mouse.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Graphics_mouse.cpp
  2. *
  3. * Copyright (C) 1992-2011,2013,2016,2017 Paul Boersma, 2013 Tom Naughton
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "GraphicsP.h"
  19. #include "Gui.h"
  20. /*
  21. * Graphics_mouseStillDown () can only be used in a loop
  22. * if Graphics_getMouseLocation () is called in that same loop.
  23. * This is because the Xwin version requires that.
  24. */
  25. bool structGraphicsScreen :: v_mouseStillDown () {
  26. #if cairo && gtk
  27. Graphics_flushWs (this);
  28. GdkEvent *gevent = gdk_display_get_event (d_display);
  29. if (! gevent) return true;
  30. int gdkEventType = gevent -> type;
  31. gdk_event_free (gevent);
  32. return gdkEventType != GDK_BUTTON_RELEASE;
  33. #elif gdi
  34. return motif_win_mouseStillDown ();
  35. #elif quartz
  36. [[d_macView window] flushWindow];
  37. NSEvent *nsEvent = [[d_macView window]
  38. nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSKeyDownMask
  39. untilDate: [NSDate distantFuture]
  40. inMode: NSEventTrackingRunLoopMode
  41. dequeue: YES
  42. ];
  43. NSUInteger nsEventType = [nsEvent type];
  44. if (nsEventType == NSKeyDown) NSBeep ();
  45. return nsEventType != NSLeftMouseUp;
  46. #else
  47. return false;
  48. #endif
  49. }
  50. bool Graphics_mouseStillDown (Graphics me) {
  51. return my v_mouseStillDown ();
  52. }
  53. void structGraphicsScreen :: v_getMouseLocation (double *p_xWC, double *p_yWC) {
  54. #if cairo && gtk
  55. gint xDC, yDC;
  56. gdk_window_get_pointer (d_window, & xDC, & yDC, nullptr);
  57. Graphics_DCtoWC (this, xDC, yDC, p_xWC, p_yWC);
  58. #elif gdi
  59. POINT pos;
  60. if (! GetCursorPos (& pos)) { Melder_warning (U"Cannot find the location of the mouse."); return; }
  61. ScreenToClient (d_winWindow, & pos);
  62. Graphics_DCtoWC (this, pos. x, pos. y, p_xWC, p_yWC);
  63. #elif quartz
  64. NSPoint mouseLoc = [[d_macView window] mouseLocationOutsideOfEventStream];
  65. mouseLoc = [d_macView convertPoint: mouseLoc fromView: nil];
  66. //mouseLoc. y = d_macView. bounds. size. height - mouseLoc. y;
  67. Graphics_DCtoWC (this, mouseLoc. x, mouseLoc. y, p_xWC, p_yWC);
  68. #endif
  69. }
  70. void Graphics_getMouseLocation (Graphics me, double *p_xWC, double *p_yWC) {
  71. my v_getMouseLocation (p_xWC, p_yWC);
  72. }
  73. void Graphics_waitMouseUp (Graphics me) {
  74. while (Graphics_mouseStillDown (me)) {
  75. double xWC, yWC;
  76. Graphics_getMouseLocation (me, & xWC, & yWC);
  77. }
  78. }
  79. /* End of file Graphics_mouse.cpp */