module Graphics.X11.Xlib.Color(
lookupColor,
allocNamedColor,
allocColor,
parseColor,
freeColors,
storeColor,
queryColor,
queryColors,
installColormap,
uninstallColormap,
copyColormapAndFree,
createColormap,
freeColormap,
) where
import Graphics.X11.Types
import Graphics.X11.Xlib.Types
import Foreign
import Foreign.C
lookupColor :: Display -> Colormap -> String -> IO (Color, Color)
lookupColor :: Display -> Pixel -> String -> IO (Color, Color)
lookupColor Display
display Pixel
colormap String
color_name =
forall a. String -> (CString -> IO a) -> IO a
withCString String
color_name forall a b. (a -> b) -> a -> b
$ \CString
c_color_name ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr Color
exact_def_return ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr Color
screen_def_return -> do
String -> IO CInt -> IO ()
throwIfZero String
"lookupColor" forall a b. (a -> b) -> a -> b
$
Display -> Pixel -> CString -> Ptr Color -> Ptr Color -> IO CInt
xLookupColor Display
display Pixel
colormap CString
c_color_name
Ptr Color
exact_def_return Ptr Color
screen_def_return
Color
exact_def <- forall a. Storable a => Ptr a -> IO a
peek Ptr Color
exact_def_return
Color
screen_def <- forall a. Storable a => Ptr a -> IO a
peek Ptr Color
screen_def_return
forall (m :: * -> *) a. Monad m => a -> m a
return (Color
exact_def, Color
screen_def)
foreign import ccall unsafe "HsXlib.h XLookupColor"
xLookupColor :: Display -> Colormap -> CString ->
Ptr Color -> Ptr Color -> IO Status
allocNamedColor :: Display -> Colormap -> String -> IO (Color, Color)
allocNamedColor :: Display -> Pixel -> String -> IO (Color, Color)
allocNamedColor Display
display Pixel
colormap String
color_name =
forall a. String -> (CString -> IO a) -> IO a
withCString String
color_name forall a b. (a -> b) -> a -> b
$ \CString
c_color_name ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr Color
exact_def_return ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr Color
screen_def_return -> do
String -> IO CInt -> IO ()
throwIfZero String
"allocNamedColor" forall a b. (a -> b) -> a -> b
$
Display -> Pixel -> CString -> Ptr Color -> Ptr Color -> IO CInt
xAllocNamedColor Display
display Pixel
colormap CString
c_color_name
Ptr Color
exact_def_return Ptr Color
screen_def_return
Color
exact_def <- forall a. Storable a => Ptr a -> IO a
peek Ptr Color
exact_def_return
Color
screen_def <- forall a. Storable a => Ptr a -> IO a
peek Ptr Color
screen_def_return
forall (m :: * -> *) a. Monad m => a -> m a
return (Color
exact_def, Color
screen_def)
foreign import ccall unsafe "HsXlib.h XAllocNamedColor"
xAllocNamedColor :: Display -> Colormap -> CString ->
Ptr Color -> Ptr Color -> IO Status
allocColor :: Display -> Colormap -> Color -> IO Color
allocColor :: Display -> Pixel -> Color -> IO Color
allocColor Display
display Pixel
colormap Color
color =
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
color forall a b. (a -> b) -> a -> b
$ \ Ptr Color
color_ptr -> do
String -> IO CInt -> IO ()
throwIfZero String
"allocColor" forall a b. (a -> b) -> a -> b
$
Display -> Pixel -> Ptr Color -> IO CInt
xAllocColor Display
display Pixel
colormap Ptr Color
color_ptr
forall a. Storable a => Ptr a -> IO a
peek Ptr Color
color_ptr
foreign import ccall unsafe "HsXlib.h XAllocColor"
xAllocColor :: Display -> Colormap -> Ptr Color -> IO Status
parseColor :: Display -> Colormap -> String -> IO Color
parseColor :: Display -> Pixel -> String -> IO Color
parseColor Display
display Pixel
colormap String
color_spec =
forall a. String -> (CString -> IO a) -> IO a
withCString String
color_spec forall a b. (a -> b) -> a -> b
$ \ CString
spec ->
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \ Ptr Color
exact_def_return -> do
String -> IO CInt -> IO ()
throwIfZero String
"parseColor" forall a b. (a -> b) -> a -> b
$
Display -> Pixel -> CString -> Ptr Color -> IO CInt
xParseColor Display
display Pixel
colormap CString
spec Ptr Color
exact_def_return
forall a. Storable a => Ptr a -> IO a
peek Ptr Color
exact_def_return
foreign import ccall unsafe "HsXlib.h XParseColor"
xParseColor :: Display -> Colormap -> CString -> Ptr Color -> IO Status
freeColors :: Display -> Colormap -> [Pixel] -> Pixel -> IO ()
freeColors :: Display -> Pixel -> [Pixel] -> Pixel -> IO ()
freeColors Display
display Pixel
colormap [Pixel]
pixels Pixel
planes =
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray [Pixel]
pixels forall a b. (a -> b) -> a -> b
$ \ Ptr Pixel
pixel_array ->
Display -> Pixel -> Ptr Pixel -> CInt -> Pixel -> IO ()
xFreeColors Display
display Pixel
colormap Ptr Pixel
pixel_array (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Pixel]
pixels)) Pixel
planes
foreign import ccall unsafe "HsXlib.h XFreeColors"
xFreeColors :: Display -> Colormap -> Ptr Pixel -> CInt -> Pixel -> IO ()
storeColor :: Display -> Colormap -> Color -> IO ()
storeColor :: Display -> Pixel -> Color -> IO ()
storeColor Display
display Pixel
colormap Color
color =
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
color forall a b. (a -> b) -> a -> b
$ \ Ptr Color
color_ptr ->
Display -> Pixel -> Ptr Color -> IO ()
xStoreColor Display
display Pixel
colormap Ptr Color
color_ptr
foreign import ccall unsafe "HsXlib.h XStoreColor"
xStoreColor :: Display -> Colormap -> Ptr Color -> IO ()
queryColor :: Display -> Colormap -> Color -> IO Color
queryColor :: Display -> Pixel -> Color -> IO Color
queryColor Display
display Pixel
colormap Color
color =
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
color forall a b. (a -> b) -> a -> b
$ \ Ptr Color
color_ptr -> do
Display -> Pixel -> Ptr Color -> IO ()
xQueryColor Display
display Pixel
colormap Ptr Color
color_ptr
forall a. Storable a => Ptr a -> IO a
peek Ptr Color
color_ptr
foreign import ccall unsafe "HsXlib.h XQueryColor"
xQueryColor :: Display -> Colormap -> Ptr Color -> IO ()
queryColors :: Display -> Colormap -> [Color] -> IO [Color]
queryColors :: Display -> Pixel -> [Color] -> IO [Color]
queryColors Display
display Pixel
colormap [Color]
colors =
forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen [Color]
colors forall a b. (a -> b) -> a -> b
$ \ Int
ncolors Ptr Color
color_array -> do
Display -> Pixel -> Ptr Color -> CInt -> IO ()
xQueryColors Display
display Pixel
colormap Ptr Color
color_array (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ncolors)
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
ncolors Ptr Color
color_array
foreign import ccall unsafe "HsXlib.h XQueryColors"
xQueryColors :: Display -> Colormap -> Ptr Color -> CInt -> IO ()
foreign import ccall unsafe "HsXlib.h XInstallColormap"
installColormap :: Display -> Colormap -> IO ()
foreign import ccall unsafe "HsXlib.h XUninstallColormap"
uninstallColormap :: Display -> Colormap -> IO ()
foreign import ccall unsafe "HsXlib.h XCopyColormapAndFree"
copyColormapAndFree :: Display -> Colormap -> IO Colormap
foreign import ccall unsafe "HsXlib.h XCreateColormap"
createColormap :: Display -> Window -> Visual -> ColormapAlloc -> IO Colormap
foreign import ccall unsafe "HsXlib.h XFreeColormap"
freeColormap :: Display -> Colormap -> IO ()