{-# 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/KeycapsC.hsc" #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE NamedFieldPuns #-}
module Ui.KeycapsC (create, destroy, update) where
#ifdef STUB_OUT_FLTK
import Ui.KeycapsCStub
#else
import qualified Data.Map as Map
import qualified Util.FFI as FFI
import qualified Util.Rect as Rect
import qualified Ui.Color as Color
import qualified Ui.Fltk as Fltk
import qualified Ui.PtrMap as PtrMap
import Global
import ForeignC
import Ui.KeycapsT
create :: (Int, Int) -> Layout -> Fltk.Fltk ()
create (x, y) layout = Fltk.fltk $ do
destroy_
layoutp <- FFI.new layout
win <- c_create (i x) (i y) (i w) (i h) layoutp
PtrMap.set_keycaps $ Just win
where
(w, h) = lt_size layout
i = FFI.c_int
foreign import ccall "keycaps_create"
c_create :: CInt -> CInt -> CInt -> CInt -> Ptr Layout -> IO (Ptr CWindow)
destroy :: Fltk.Fltk ()
destroy = Fltk.fltk destroy_
destroy_ :: IO ()
destroy_ = whenJustM PtrMap.lookup_keycaps $ \win -> do
c_destroy win
PtrMap.set_keycaps Nothing
foreign import ccall "keycaps_destroy" c_destroy :: Ptr CWindow -> IO ()
update :: RawBindings -> Fltk.Fltk ()
update (RawBindings bindings) = Fltk.fltk $
whenJustM PtrMap.lookup_keycaps $ \win -> do
withArrayLen bindings $ \bindings_len bindingsp ->
c_update win bindingsp (FFI.c_int bindings_len)
foreign import ccall "keycaps_update"
c_update :: Ptr CWindow -> Ptr RawBinding -> CInt -> IO ()
instance CStorable Layout where
sizeOf _ = (64)
{-# LINE 87 "Ui/KeycapsC.hsc" #-}
alignment _ = alignment nullPtr
poke p (Layout
{ lt_bg_color, lt_keycap_color, lt_highlight_color
, lt_label_color, lt_binding_color
, lt_labels
}) = do
let rects = Map.elems lt_labels
labels = Map.keys lt_labels
points =
[ (x + fst label_offset, y + snd label_offset)
| (x, y) <- map Rect.upper_left rects
]
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p lt_bg_color
{-# LINE 100 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) p lt_keycap_color
{-# LINE 101 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p lt_highlight_color
{-# LINE 102 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) p lt_label_color
{-# LINE 103 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p lt_binding_color
{-# LINE 104 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) p =<< newArray rects
{-# LINE 105 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) p $ FFI.c_int (Map.size lt_labels)
{-# LINE 106 "Ui/KeycapsC.hsc" #-}
labelps <- mapM FFI.newCStringNull0 labels
((\hsc_ptr -> pokeByteOff hsc_ptr 40)) p =<< newArray points
{-# LINE 108 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 48)) p =<< newArray labelps
{-# LINE 109 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 56)) p $ FFI.c_int (length lt_labels)
{-# LINE 110 "Ui/KeycapsC.hsc" #-}
label_offset :: (Int, Int)
label_offset = (1, 8)
instance CStorable RawBinding where
sizeOf _ = (32)
{-# LINE 127 "Ui/KeycapsC.hsc" #-}
alignment _ = alignment nullPtr
poke p (RawBinding point (Binding { b_text, b_doc, b_color })) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p point
{-# LINE 130 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p =<< FFI.newCStringNull0 b_text
{-# LINE 131 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p =<< FFI.newCStringNull0 b_doc
{-# LINE 132 "Ui/KeycapsC.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) p $ fromMaybe Color.black b_color
{-# LINE 133 "Ui/KeycapsC.hsc" #-}
#endif