#if __GLASGOW_HASKELL__ >= 709
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
module Graphics.Win32.GDI.Region where
import System.Win32.Types
import Graphics.Win32.GDI.Types
import Foreign
#include "windows_cconv.h"
badRegion :: RegionType -> Bool
badRegion :: Int32 -> Bool
badRegion Int32
n = Int32
n Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
0 Bool -> Bool -> Bool
|| Int32
n Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
forall a. Num a => a
gDI_ERROR
combineRgn :: HRGN -> HRGN -> HRGN -> ClippingMode -> IO RegionType
combineRgn :: HRGN -> HRGN -> HRGN -> Int32 -> IO Int32
combineRgn HRGN
dest HRGN
src1 HRGN
src2 Int32
mode =
HRGN -> (Ptr () -> IO Int32) -> IO Int32
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
dest ((Ptr () -> IO Int32) -> IO Int32)
-> (Ptr () -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_dest ->
HRGN -> (Ptr () -> IO Int32) -> IO Int32
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
src1 ((Ptr () -> IO Int32) -> IO Int32)
-> (Ptr () -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_src1 ->
HRGN -> (Ptr () -> IO Int32) -> IO Int32
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
src2 ((Ptr () -> IO Int32) -> IO Int32)
-> (Ptr () -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_src2 ->
(Int32 -> Bool) -> String -> IO Int32 -> IO Int32
forall a. (a -> Bool) -> String -> IO a -> IO a
failIf Int32 -> Bool
badRegion String
"CombineRgn" (IO Int32 -> IO Int32) -> IO Int32 -> IO Int32
forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr () -> Ptr () -> Int32 -> IO Int32
c_CombineRgn Ptr ()
p_dest Ptr ()
p_src1 Ptr ()
p_src2 Int32
mode
foreign import WINDOWS_CCONV unsafe "windows.h CombineRgn"
c_CombineRgn :: PRGN -> PRGN -> PRGN -> ClippingMode -> IO RegionType
offsetRgn :: HRGN -> INT -> INT -> IO RegionType
offsetRgn :: HRGN -> Int32 -> Int32 -> IO Int32
offsetRgn HRGN
rgn Int32
xoff Int32
yoff =
HRGN -> (Ptr () -> IO Int32) -> IO Int32
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO Int32) -> IO Int32)
-> (Ptr () -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
(Int32 -> Bool) -> String -> IO Int32 -> IO Int32
forall a. (a -> Bool) -> String -> IO a -> IO a
failIf Int32 -> Bool
badRegion String
"OffsetRgn" (IO Int32 -> IO Int32) -> IO Int32 -> IO Int32
forall a b. (a -> b) -> a -> b
$ Ptr () -> Int32 -> Int32 -> IO Int32
c_OffsetRgn Ptr ()
p_rgn Int32
xoff Int32
yoff
foreign import WINDOWS_CCONV unsafe "windows.h OffsetRgn"
c_OffsetRgn :: PRGN -> INT -> INT -> IO RegionType
getRgnBox :: HRGN -> LPRECT -> IO RegionType
getRgnBox :: HRGN -> LPRECT -> IO Int32
getRgnBox HRGN
rgn LPRECT
p_rect =
HRGN -> (Ptr () -> IO Int32) -> IO Int32
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO Int32) -> IO Int32)
-> (Ptr () -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
(Int32 -> Bool) -> String -> IO Int32 -> IO Int32
forall a. (a -> Bool) -> String -> IO a -> IO a
failIf Int32 -> Bool
badRegion String
"GetRgnBox" (IO Int32 -> IO Int32) -> IO Int32 -> IO Int32
forall a b. (a -> b) -> a -> b
$ Ptr () -> LPRECT -> IO Int32
c_GetRgnBox Ptr ()
p_rgn LPRECT
p_rect
foreign import WINDOWS_CCONV unsafe "windows.h GetRgnBox"
c_GetRgnBox :: PRGN -> LPRECT -> IO RegionType
createEllipticRgn :: INT -> INT -> INT -> INT -> IO HRGN
createEllipticRgn :: Int32 -> Int32 -> Int32 -> Int32 -> IO HRGN
createEllipticRgn Int32
x0 Int32
y0 Int32
x1 Int32
y1 = do
ptr <- String -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateEllipticRgn" (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ Int32 -> Int32 -> Int32 -> Int32 -> IO (Ptr ())
c_CreateEllipticRgn Int32
x0 Int32
y0 Int32
x1 Int32
y1
newForeignHANDLE ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateEllipticRgn"
c_CreateEllipticRgn :: INT -> INT -> INT -> INT -> IO PRGN
createEllipticRgnIndirect :: LPRECT -> IO HRGN
createEllipticRgnIndirect :: LPRECT -> IO HRGN
createEllipticRgnIndirect LPRECT
rp = do
ptr <- String -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateEllipticRgnIndirect" (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ LPRECT -> IO (Ptr ())
c_CreateEllipticRgnIndirect LPRECT
rp
newForeignHANDLE ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateEllipticRgnIndirect"
c_CreateEllipticRgnIndirect :: LPRECT -> IO PRGN
createRectRgn :: INT -> INT -> INT -> INT -> IO HRGN
createRectRgn :: Int32 -> Int32 -> Int32 -> Int32 -> IO HRGN
createRectRgn Int32
x0 Int32
y0 Int32
x1 Int32
y1 = do
ptr <- String -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateRectRgn" (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ Int32 -> Int32 -> Int32 -> Int32 -> IO (Ptr ())
c_CreateRectRgn Int32
x0 Int32
y0 Int32
x1 Int32
y1
newForeignHANDLE ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateRectRgn"
c_CreateRectRgn :: INT -> INT -> INT -> INT -> IO PRGN
createRectRgnIndirect :: LPRECT -> IO HRGN
createRectRgnIndirect :: LPRECT -> IO HRGN
createRectRgnIndirect LPRECT
rp = do
ptr <- String -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateRectRgnIndirect" (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ LPRECT -> IO (Ptr ())
c_CreateRectRgnIndirect LPRECT
rp
newForeignHANDLE ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateRectRgnIndirect"
c_CreateRectRgnIndirect :: LPRECT -> IO PRGN
createRoundRectRgn :: INT -> INT -> INT -> INT -> INT -> INT -> IO HRGN
createRoundRectRgn :: Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO HRGN
createRoundRectRgn Int32
x0 Int32
y0 Int32
x1 Int32
y1 Int32
h Int32
w = do
ptr <- String -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateRoundRectRgn" (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO (Ptr ())
c_CreateRoundRectRgn Int32
x0 Int32
y0 Int32
x1 Int32
y1 Int32
h Int32
w
newForeignHANDLE ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateRoundRectRgn"
c_CreateRoundRectRgn :: INT -> INT -> INT -> INT -> INT -> INT -> IO PRGN
createPolygonRgn :: [POINT] -> PolyFillMode -> IO HRGN
createPolygonRgn :: [POINT] -> Int32 -> IO HRGN
createPolygonRgn [POINT]
ps Int32
mode =
[POINT] -> (Ptr POINT -> Int -> IO HRGN) -> IO HRGN
forall a. [POINT] -> (Ptr POINT -> Int -> IO a) -> IO a
withPOINTArray [POINT]
ps ((Ptr POINT -> Int -> IO HRGN) -> IO HRGN)
-> (Ptr POINT -> Int -> IO HRGN) -> IO HRGN
forall a b. (a -> b) -> a -> b
$ \ Ptr POINT
point_array Int
npoints -> do
ptr <- String -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreatePolygonRgn" (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$
Ptr POINT -> Int -> Int32 -> IO (Ptr ())
c_CreatePolygonRgn Ptr POINT
point_array Int
npoints Int32
mode
newForeignHANDLE ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreatePolygonRgn"
c_CreatePolygonRgn :: Ptr POINT -> Int -> PolyFillMode -> IO PRGN
foreign import WINDOWS_CCONV unsafe "windows.h EqualRgn"
equalRgn :: PRGN -> PRGN -> IO Bool
fillRgn :: HDC -> HRGN -> HBRUSH -> IO ()
fillRgn :: Ptr () -> HRGN -> Ptr () -> IO ()
fillRgn Ptr ()
dc HRGN
rgn Ptr ()
brush =
HRGN -> (Ptr () -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
String -> IO Bool -> IO ()
failIfFalse_ String
"FillRgn" (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr () -> Ptr () -> IO Bool
c_FillRgn Ptr ()
dc Ptr ()
p_rgn Ptr ()
brush
foreign import WINDOWS_CCONV unsafe "windows.h FillRgn"
c_FillRgn :: HDC -> PRGN -> HBRUSH -> IO Bool
invertRgn :: HDC -> HRGN -> IO ()
invertRgn :: Ptr () -> HRGN -> IO ()
invertRgn Ptr ()
dc HRGN
rgn =
HRGN -> (Ptr () -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
String -> IO Bool -> IO ()
failIfFalse_ String
"InvertRgn" (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr () -> IO Bool
c_InvertRgn Ptr ()
dc Ptr ()
p_rgn
foreign import WINDOWS_CCONV unsafe "windows.h InvertRgn"
c_InvertRgn :: HDC -> PRGN -> IO Bool
paintRgn :: HDC -> HRGN -> IO ()
paintRgn :: Ptr () -> HRGN -> IO ()
paintRgn Ptr ()
dc HRGN
rgn =
HRGN -> (Ptr () -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
String -> IO Bool -> IO ()
failIfFalse_ String
"PaintRgn" (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr () -> IO Bool
c_PaintRgn Ptr ()
dc Ptr ()
p_rgn
foreign import WINDOWS_CCONV unsafe "windows.h PaintRgn"
c_PaintRgn :: HDC -> PRGN -> IO Bool
frameRgn :: HDC -> HRGN -> HBRUSH -> Int -> Int -> IO ()
frameRgn :: Ptr () -> HRGN -> Ptr () -> Int -> Int -> IO ()
frameRgn Ptr ()
dc HRGN
rgn Ptr ()
brush Int
w Int
h =
HRGN -> (Ptr () -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
String -> IO Bool -> IO ()
failIfFalse_ String
"FrameRgn" (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr () -> Ptr () -> Int -> Int -> IO Bool
c_FrameRgn Ptr ()
dc Ptr ()
p_rgn Ptr ()
brush Int
w Int
h
foreign import WINDOWS_CCONV unsafe "windows.h FrameRgn"
c_FrameRgn :: HDC -> PRGN -> HBRUSH -> Int -> Int -> IO Bool
ptInRegion :: HRGN -> Int -> Int -> IO Bool
ptInRegion :: HRGN -> Int -> Int -> IO Bool
ptInRegion HRGN
rgn Int
x Int
y =
HRGN -> (Ptr () -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
Ptr () -> Int -> Int -> IO Bool
c_PtInRegion Ptr ()
p_rgn Int
x Int
y
foreign import WINDOWS_CCONV unsafe "windows.h PtInRegion"
c_PtInRegion :: PRGN -> Int -> Int -> IO Bool
rectInRegion :: HRGN -> RECT -> IO Bool
rectInRegion :: HRGN -> RECT -> IO Bool
rectInRegion HRGN
rgn RECT
rect =
HRGN -> (Ptr () -> IO Bool) -> IO Bool
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
RECT -> (LPRECT -> IO Bool) -> IO Bool
forall a. RECT -> (LPRECT -> IO a) -> IO a
withRECT RECT
rect ((LPRECT -> IO Bool) -> IO Bool) -> (LPRECT -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr () -> LPRECT -> IO Bool
c_RectInRegion Ptr ()
p_rgn
foreign import WINDOWS_CCONV unsafe "windows.h RectInRegion"
c_RectInRegion :: PRGN -> Ptr RECT -> IO Bool