{-# OPTIONS_GHC -optc-D_LARGEFILE_SOURCE #-}
{-# OPTIONS_GHC -optc-D_LARGEFILE64_SOURCE #-}
{-# OPTIONS_GHC -optc-D_THREAD_SAFE #-}
{-# OPTIONS_GHC -optc-D_REENTRANT #-}
{-# OPTIONS_GHC -optc-DBUILD_DIR="build/debug" #-}
{-# OPTIONS_GHC -optc-DGHC_VERSION=90205 #-}
{-# OPTIONS_GHC -optc-D__APPLE__ #-}
{-# LINE 1 "Ui/Zoom.hsc" #-}
module Ui.Zoom (Zoom(..), to_pixels, to_time) where
import ForeignC
import qualified Util.FFI as FFI
import qualified Util.Num as Num
import qualified Ui.ScoreTime as ScoreTime
import Ui.ScoreTime (TrackTime)
import Global
data Zoom = Zoom {
offset :: !TrackTime
, factor :: !Double
} deriving (Eq, Ord, Show, Read)
instance Pretty Zoom where
pretty (Zoom offset factor) =
"+" <> pretty offset <> "*" <> Num.showFloat 1 factor
instance CStorable Zoom where
sizeOf _ = (16)
{-# LINE 31 "Ui/Zoom.hsc" #-}
alignment _ = alignment (0 :: CDouble)
peek zoomp = do
offset <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) zoomp
{-# LINE 34 "Ui/Zoom.hsc" #-}
factor <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) zoomp :: IO CDouble
{-# LINE 35 "Ui/Zoom.hsc" #-}
return $ Zoom offset (FFI.hs_double factor)
poke zoomp (Zoom offset factor) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) zoomp offset
{-# LINE 38 "Ui/Zoom.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) zoomp (FFI.c_double factor)
{-# LINE 39 "Ui/Zoom.hsc" #-}
to_pixels :: Zoom -> TrackTime -> Int
to_pixels zoom pos = Num.d2i $ ScoreTime.to_double pos * factor zoom
to_time :: Zoom -> Int -> TrackTime
to_time zoom pixels = ScoreTime.from_double (fromIntegral pixels / factor zoom)