| 1 |
{-# OPTIONS_HADDOCK hide #-} |
| 2 |
-------------------------------------------------------------------------------- |
| 3 |
-- | |
| 4 |
-- Module : Graphics.UI.GLUT.Types |
| 5 |
-- Copyright : (c) Sven Panne 2002-2018 |
| 6 |
-- License : BSD3 |
| 7 |
-- |
| 8 |
-- Maintainer : Sven Panne <[email protected]> |
| 9 |
-- Stability : stable |
| 10 |
-- Portability : portable |
| 11 |
-- |
| 12 |
-- This is a purely internal module with miscellaneous types which don\'t really |
| 13 |
-- have a good place elsewhere. |
| 14 |
-- |
| 15 |
-------------------------------------------------------------------------------- |
| 16 |
|
| 17 |
module Graphics.UI.GLUT.Types ( |
| 18 |
Window(..), -- constructor used only internally |
| 19 |
Relation(..), |
| 20 |
relationToString, -- used only internally |
| 21 |
MouseButton(..), |
| 22 |
marshalMouseButton, unmarshalMouseButton -- used only internally |
| 23 |
) where |
| 24 |
|
| 25 |
import Foreign.C.Types |
| 26 |
import Graphics.UI.GLUT.Raw |
| 27 |
|
| 28 |
-------------------------------------------------------------------------------- |
| 29 |
|
| 30 |
-- | An opaque identifier for a top-level window or a subwindow. |
| 31 |
|
| 32 |
newtype Window = Window CInt |
| 33 |
deriving ( Eq, Ord, Show ) |
| 34 |
|
| 35 |
-------------------------------------------------------------------------------- |
| 36 |
|
| 37 |
-- | A relation between a 'Graphics.UI.GLUT.Initialization.DisplayCapability' |
| 38 |
-- and a numeric value. |
| 39 |
|
| 40 |
data Relation |
| 41 |
= IsEqualTo -- ^ Equal. |
| 42 |
| IsNotEqualTo -- ^ Not equal. |
| 43 |
| IsLessThan -- ^ Less than and preferring larger difference (the least |
| 44 |
-- is best). |
| 45 |
| IsNotGreaterThan -- ^ Less than or equal and preferring larger difference |
| 46 |
-- (the least is best). |
| 47 |
| IsGreaterThan -- ^ Greater than and preferring larger differences (the |
| 48 |
-- most is best). |
| 49 |
| IsAtLeast -- ^ Greater than or equal and preferring more instead of |
| 50 |
-- less. This relation is useful for allocating |
| 51 |
-- resources like color precision or depth buffer |
| 52 |
-- precision where the maximum precision is generally |
| 53 |
-- preferred. Contrast with 'IsNotLessThan' relation. |
| 54 |
| IsNotLessThan -- ^ Greater than or equal but preferring less instead of |
| 55 |
-- more. This relation is useful for allocating |
| 56 |
-- resources such as stencil bits or auxillary color |
| 57 |
-- buffers where you would rather not over-allocate. |
| 58 |
deriving ( Eq, Ord, Show ) |
| 59 |
|
| 60 |
relationToString :: Relation -> String |
| 61 |
relationToString IsEqualTo = "=" |
| 62 |
relationToString IsNotEqualTo = "!=" |
| 63 |
relationToString IsLessThan = "<" |
| 64 |
relationToString IsNotGreaterThan = "<=" |
| 65 |
relationToString IsGreaterThan = ">" |
| 66 |
relationToString IsAtLeast = ">=" |
| 67 |
relationToString IsNotLessThan = "~" |
| 68 |
|
| 69 |
-------------------------------------------------------------------------------- |
| 70 |
|
| 71 |
-- | Mouse buttons, including a wheel |
| 72 |
|
| 73 |
data MouseButton |
| 74 |
= LeftButton |
| 75 |
| MiddleButton |
| 76 |
| RightButton |
| 77 |
| WheelUp |
| 78 |
| WheelDown |
| 79 |
| AdditionalButton Int |
| 80 |
deriving ( Eq, Ord, Show ) |
| 81 |
|
| 82 |
marshalMouseButton :: MouseButton -> CInt |
| 83 |
marshalMouseButton x = case x of |
| 84 |
LeftButton -> glut_LEFT_BUTTON |
| 85 |
MiddleButton -> glut_MIDDLE_BUTTON |
| 86 |
RightButton -> glut_RIGHT_BUTTON |
| 87 |
WheelUp -> glut_WHEEL_UP |
| 88 |
WheelDown -> glut_WHEEL_DOWN |
| 89 |
AdditionalButton b -> fromIntegral b |
| 90 |
|
| 91 |
unmarshalMouseButton :: CInt -> MouseButton |
| 92 |
unmarshalMouseButton x |
| 93 |
| x == glut_LEFT_BUTTON = LeftButton |
| 94 |
| x == glut_MIDDLE_BUTTON = MiddleButton |
| 95 |
| x == glut_RIGHT_BUTTON = RightButton |
| 96 |
| x == glut_WHEEL_UP = WheelUp |
| 97 |
| x == glut_WHEEL_DOWN = WheelDown |
| 98 |
| otherwise = AdditionalButton (fromIntegral x) |
| 99 |
|
| 100 |
glut_WHEEL_UP :: CInt |
| 101 |
glut_WHEEL_UP = 3 |
| 102 |
|
| 103 |
glut_WHEEL_DOWN :: CInt |
| 104 |
glut_WHEEL_DOWN = 4 |