diff options
Diffstat (limited to 'GLX.hs')
-rw-r--r-- | GLX.hs | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -70,7 +70,7 @@ instance Driver GLX where rootwindow <- rootWindow disp (fromIntegral $ viScreen visualinfo) cmap <- createColormap disp rootwindow (viVisual visualinfo) allocNone - let swa = nullSetWindowAttributes {swaColormap = cmap, swaEventMask = structureNotifyMask .|. keyPressMask .|. keyReleaseMask .|. pointerMotionMask} + let swa = nullSetWindowAttributes {swaColormap = cmap, swaEventMask = structureNotifyMask .|. keyPressMask .|. keyReleaseMask .|. pointerMotionMask .|. buttonPressMask} wnd <- with swa $ \swaptr -> createWindow disp rootwindow 0 0 800 600 0 (fromIntegral $ viDepth visualinfo) inputOutput (viVisual visualinfo) (cWBorderPixel.|.cWColormap.|.cWEventMask) swaptr @@ -162,18 +162,29 @@ handleEvent glx xevent = do else return (glx, Nothing) | evtype == motionNotify -> do + (x, y) <- windowToGameCoords glx (ev_x event) (ev_y event) wa <- getWindowAttributes (glxDisplay glx) (glxWindow glx) - let x = fromIntegral . ev_x $ event - y = fromIntegral . ev_y $ event - w = fromIntegral . wa_width $ wa - h = fromIntegral . wa_height $ wa - s = fromRational . glxScale $ glx - lw = fromIntegral . glxLevelWidth $ glx - lh = fromIntegral . glxLevelHeight $ glx - return (glx, Just $ SomeEvent $ MouseMotionEvent ((-w/2+x)/s + lw/2) ((h/2-y)/s + lh/2)) + return (glx, Just $ SomeEvent $ MouseMotionEvent x y) + | evtype == buttonPress -> do + (x, y) <- windowToGameCoords glx (ev_x event) (ev_y event) + wa <- getWindowAttributes (glxDisplay glx) (glxWindow glx) + return (glx, Just $ SomeEvent $ MousePressEvent x y) + | otherwise -> return (glx, Nothing) +windowToGameCoords :: Integral a => GLX -> a -> a -> IO (Float, Float) +windowToGameCoords glx x y = getWindowAttributes (glxDisplay glx) (glxWindow glx) >>= \wa -> + let w = fromIntegral . wa_width $ wa + h = fromIntegral . wa_height $ wa + in return (((-w/2 + wx)/s + lw/2), ((h/2 - wy)/s + lh/2)) + where s = fromRational . glxScale $ glx + lw = fromIntegral . glxLevelWidth $ glx + lh = fromIntegral . glxLevelHeight $ glx + wx = fromIntegral x + wy = fromIntegral y + + resize :: Int -> Int -> Int -> Int -> IO Rational resize lw lh w h = do let aspect = (fromIntegral w)%(fromIntegral h) @@ -201,5 +212,3 @@ waitForMapNotify disp wnd = allocaXEvent waitForMapNotify' eventType <- get_EventType event unless (window == wnd && eventType == mapNotify) $ waitForMapNotify' event - -
\ No newline at end of file |