#if __GLASGOW_HASKELL__ >= 709
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
-----------------------------------------------------------------------------
-- |
-- Module      :  Graphics.Win32.GDI.Region
-- Copyright   :  (c) Alastair Reid, 1997-2003
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  Esa Ilari Vuokko <ei@vuokko.info>
-- Stability   :  provisional
-- Portability :  portable
--
-- A collection of FFI declarations for interfacing with Win32.
--
-----------------------------------------------------------------------------

module Graphics.Win32.GDI.Region where

import System.Win32.Types
import Graphics.Win32.GDI.Types

import Foreign

#include "windows_cconv.h"

----------------------------------------------------------------
-- Regions
----------------------------------------------------------------

badRegion :: RegionType -> Bool
badRegion :: RegionType -> Bool
badRegion RegionType
n = RegionType
n forall a. Eq a => a -> a -> Bool
== RegionType
0 Bool -> Bool -> Bool
|| RegionType
n forall a. Eq a => a -> a -> Bool
== forall a. Num a => a
gDI_ERROR

combineRgn :: HRGN -> HRGN -> HRGN -> ClippingMode -> IO RegionType
combineRgn :: HRGN -> HRGN -> HRGN -> RegionType -> IO RegionType
combineRgn HRGN
dest HRGN
src1 HRGN
src2 RegionType
mode =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
dest forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_dest ->
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
src1 forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_src1 ->
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
src2 forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_src2 ->
  forall a. (a -> Bool) -> String -> IO a -> IO a
failIf RegionType -> Bool
badRegion String
"CombineRgn" forall a b. (a -> b) -> a -> b
$ Ptr () -> Ptr () -> Ptr () -> RegionType -> IO RegionType
c_CombineRgn Ptr ()
p_dest Ptr ()
p_src1 Ptr ()
p_src2 RegionType
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 -> RegionType -> RegionType -> IO RegionType
offsetRgn HRGN
rgn RegionType
xoff RegionType
yoff =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  forall a. (a -> Bool) -> String -> IO a -> IO a
failIf RegionType -> Bool
badRegion String
"OffsetRgn" forall a b. (a -> b) -> a -> b
$ Ptr () -> RegionType -> RegionType -> IO RegionType
c_OffsetRgn Ptr ()
p_rgn RegionType
xoff RegionType
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 RegionType
getRgnBox HRGN
rgn LPRECT
p_rect =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  forall a. (a -> Bool) -> String -> IO a -> IO a
failIf RegionType -> Bool
badRegion String
"GetRgnBox" forall a b. (a -> b) -> a -> b
$ Ptr () -> LPRECT -> IO RegionType
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 :: RegionType -> RegionType -> RegionType -> RegionType -> IO HRGN
createEllipticRgn RegionType
x0 RegionType
y0 RegionType
x1 RegionType
y1 = do
  Ptr ()
ptr <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateEllipticRgn" forall a b. (a -> b) -> a -> b
$ RegionType -> RegionType -> RegionType -> RegionType -> IO (Ptr ())
c_CreateEllipticRgn RegionType
x0 RegionType
y0 RegionType
x1 RegionType
y1
  Ptr () -> IO HRGN
newForeignHANDLE Ptr ()
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 ()
ptr <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateEllipticRgnIndirect" forall a b. (a -> b) -> a -> b
$ LPRECT -> IO (Ptr ())
c_CreateEllipticRgnIndirect LPRECT
rp
  Ptr () -> IO HRGN
newForeignHANDLE Ptr ()
ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateEllipticRgnIndirect"
  c_CreateEllipticRgnIndirect :: LPRECT -> IO PRGN

createRectRgn :: INT -> INT -> INT -> INT -> IO HRGN
createRectRgn :: RegionType -> RegionType -> RegionType -> RegionType -> IO HRGN
createRectRgn RegionType
x0 RegionType
y0 RegionType
x1 RegionType
y1 = do
  Ptr ()
ptr <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateRectRgn" forall a b. (a -> b) -> a -> b
$ RegionType -> RegionType -> RegionType -> RegionType -> IO (Ptr ())
c_CreateRectRgn RegionType
x0 RegionType
y0 RegionType
x1 RegionType
y1
  Ptr () -> IO HRGN
newForeignHANDLE Ptr ()
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 ()
ptr <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateRectRgnIndirect" forall a b. (a -> b) -> a -> b
$ LPRECT -> IO (Ptr ())
c_CreateRectRgnIndirect LPRECT
rp
  Ptr () -> IO HRGN
newForeignHANDLE Ptr ()
ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreateRectRgnIndirect"
  c_CreateRectRgnIndirect :: LPRECT -> IO PRGN

createRoundRectRgn :: INT -> INT -> INT -> INT -> INT -> INT -> IO HRGN
createRoundRectRgn :: RegionType
-> RegionType
-> RegionType
-> RegionType
-> RegionType
-> RegionType
-> IO HRGN
createRoundRectRgn RegionType
x0 RegionType
y0 RegionType
x1 RegionType
y1 RegionType
h RegionType
w = do
  Ptr ()
ptr <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreateRoundRectRgn" forall a b. (a -> b) -> a -> b
$ RegionType
-> RegionType
-> RegionType
-> RegionType
-> RegionType
-> RegionType
-> IO (Ptr ())
c_CreateRoundRectRgn RegionType
x0 RegionType
y0 RegionType
x1 RegionType
y1 RegionType
h RegionType
w
  Ptr () -> IO HRGN
newForeignHANDLE Ptr ()
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] -> RegionType -> IO HRGN
createPolygonRgn [POINT]
ps RegionType
mode =
  forall a. [POINT] -> (Ptr POINT -> Int -> IO a) -> IO a
withPOINTArray [POINT]
ps forall a b. (a -> b) -> a -> b
$ \ Ptr POINT
point_array Int
npoints -> do
  Ptr ()
ptr <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
failIfNull String
"CreatePolygonRgn" forall a b. (a -> b) -> a -> b
$
    Ptr POINT -> Int -> RegionType -> IO (Ptr ())
c_CreatePolygonRgn Ptr POINT
point_array Int
npoints RegionType
mode
  Ptr () -> IO HRGN
newForeignHANDLE Ptr ()
ptr
foreign import WINDOWS_CCONV unsafe "windows.h CreatePolygonRgn"
  c_CreatePolygonRgn :: Ptr POINT -> Int -> PolyFillMode -> IO PRGN

-- Needs to do proper error test for EqualRgn; GSL ???

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 =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  String -> IO Bool -> IO ()
failIfFalse_ String
"FillRgn" 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 =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  String -> IO Bool -> IO ()
failIfFalse_ String
"InvertRgn" 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 =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  String -> IO Bool -> IO ()
failIfFalse_ String
"PaintRgn" 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 =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  String -> IO Bool -> IO ()
failIfFalse_ String
"FrameRgn" 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 =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn 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 =
  forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr HRGN
rgn forall a b. (a -> b) -> a -> b
$ \ Ptr ()
p_rgn ->
  forall a. RECT -> (LPRECT -> IO a) -> IO a
withRECT RECT
rect 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

----------------------------------------------------------------
-- End
----------------------------------------------------------------