83488

Purescript MouseEvent to get x y of mouse

Question:

I am new to purescript and was trying to make a 3d cube rotate on mouse events. But I cannot get x and y coordinates of mouse pointer on mouse move event. I am attaching my code below which have a event listener. Can somebody help me in getting x and y coordinates of mouse or can tell me better way to write event listener for mouse.

node <- querySelector "#canvas" for_ node $ addEventListener "mousedown" $ void do modifyRef drag \d -> true xz <- getPageX log (show xz) x <- liftEff $ Window.screenX =<< window y <- liftEff $ Window.screenX =<< window modifyRef old_x \ox -> toNumber x modifyRef old_y \oy -> toNumber y log (show y) for_ node $ addEventListener "mouseup" $ void do modifyRef drag \d -> false for_ node $ addEventListener "mouseout" $ void do modifyRef drag \d -> false for_ node $ addEventListener "mousemove" $ void do --log "Mouse Moved!" x <- liftEff $ Window.screenX =<< window y <- liftEff $ Window.screenX =<< window ox <- readRef old_x oy <- readRef old_y modifyRef dX \dx -> (toNumber x - ox) * 2.0 * pi / 600.0 modifyRef dY \dy -> (toNumber y - oy) * 2.0 * pi / 650.0 dx <- readRef dX dy <- readRef dY dg <- readRef drag if dg == true then do modifyRef alpha \al -> al + dx modifyRef beta \bt -> bt + dy modifyRef old_x \ox -> toNumber x modifyRef old_y \oy -> toNumber y --modifyRef gamma \ga -> ga + 3.0 * pi/180.0 else pure unit

Answer1:

You are using window.screenX and window.screenY, which <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/screenX" rel="nofollow">is not what you want</a>. You need to use <a href="https://pursuit.purescript.org/packages/purescript-dom/4.15.0/docs/DOM.Event.MouseEvent#v:screenX" rel="nofollow">screenX and screenY</a> from the MouseEvent type instead.

Recommend

  • Binding color property from xaml to c#
  • Is Lambda code repeated with dynamically created controls?
  • JQuery UI selectable plugin - Multiple mouse drag selection and unselect option
  • display a overlay when input is clicked in react
  • Change color of row programmatically in WatchKit
  • Can't CTRL+Drag NSButton to custom NSView header
  • avoid automatic jump to bottom on page with iframe video
  • jquery draggable stop event
  • How to control Trigger state (Pause, Play) using code (not just buttons)
  • Can a variable be stored within an image or div tag?
  • button in popup.html not working
  • Javascript focus remove text highlight
  • Get the pasted content on document on paste event
  • Java making confirming exit
  • Dynamically load css stylesheet and wait for it to load
  • Drawing a Path in XAML (with binding) vs. C#. One works, one doesn't
  • passing a default argument to a browserify module
  • Aptana 3 remove bundle (jquery)
  • How to save a record and immediately use its GUID
  • How can I run DataNucleus Bytecode Enhancer from SBT?
  • Why am I getting a “405 Method not allowed” error on “Put” operations through a WCF Resful service?
  • quiver not drawing arrows just lots of blue, matlab
  • AppleScript : find open tab in safari by name and open it
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • Alert pop up with LWUIT
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • AngularJs get employee from factory
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • sending mail using smtp is too slow
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • How can I use threading to 'tick' a timer to be accessed by other threads?