Skip to content

Commit 399d21a

Browse files
authored
Merge win32 extras (#67)
* Win32: Initial merge * Win32: Finish merging Win32. * Win32: Merge finally done. * Win32: Update includes * Win32: Fix build * Win32: Define WINVER level. * Win32: Define WINVER level again. * Win32: GHC compat support. * Merge: Finally rebased. * Merge: Added GHC compat. * Merge: Add compat with layered window. * Merge: Compat with AnimateWindow * Merge: Compat with Input * Merge: Missing structs. * Merge: remove attribute * Merge: include header more places. * Merge: fix remaining issues. * More compat changes for mouse. * Merge: Missing mouse defines. * Merge: So random.. * Merge: such a big mess.. * Merge: such a big mess.. * Merge: such a big mess..
1 parent d1c4a93 commit 399d21a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2419
-247
lines changed

Graphics/Win32.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ module Graphics.Win32 (
3131
module Graphics.Win32.Message,
3232
module Graphics.Win32.Misc,
3333
module Graphics.Win32.Resource,
34-
module Graphics.Win32.Window
34+
module Graphics.Win32.Window,
35+
module Graphics.Win32.LayeredWindow,
36+
module Graphics.Win32.Window.AnimateWindow,
37+
module Graphics.Win32.Window.ForegroundWindow,
38+
module Graphics.Win32.Window.IMM,
39+
module Graphics.Win32.Window.PostMessage
3540
) where
3641

3742
import System.Win32.Types
@@ -45,3 +50,8 @@ import Graphics.Win32.Message
4550
import Graphics.Win32.Misc
4651
import Graphics.Win32.Resource
4752
import Graphics.Win32.Window
53+
import Graphics.Win32.LayeredWindow
54+
import Graphics.Win32.Window.AnimateWindow
55+
import Graphics.Win32.Window.ForegroundWindow
56+
import Graphics.Win32.Window.IMM
57+
import Graphics.Win32.Window.PostMessage

Graphics/Win32/GDI/AlphaBlend.hsc

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{-# LANGUAGE CPP #-}
2+
{- |
3+
Module : Graphics.Win32.GDI.AlphaBlend
4+
Copyright : 2013 shelarcy
5+
License : BSD-style
6+
7+
Maintainer : [email protected]
8+
Stability : Provisional
9+
Portability : Non-portable (Win32 API)
10+
11+
Provides alpha blending functionality.
12+
-}
13+
module Graphics.Win32.GDI.AlphaBlend where
14+
import Foreign.Storable ( Storable(..) )
15+
import Foreign.Ptr ( Ptr )
16+
import Graphics.Win32.GDI.Types ( HDC )
17+
import System.Win32.Types ( BOOL, BYTE, UINT )
18+
19+
#include <windows.h>
20+
##include "windows_cconv.h"
21+
22+
foreign import ccall unsafe "alphablend.h"
23+
c_AlphaBlend :: HDC -> Int -> Int -> Int -> Int -> HDC -> Int -> Int -> Int -> Int -> PBLENDFUNCTION -> IO BOOL
24+
{-
25+
We use C wrapper function to call this API.
26+
Because foreign stacall/ccall/capi doesn't work with non-pointer user defined type.
27+
28+
We think that capi should support that when user defined type has Storable class instance
29+
and using CTYPE pragma in the scope.
30+
31+
{-# LANGUAGE CApiFFI #-}
32+
33+
data {-# CTYPE "windows.h" "BLENDFUNCTION" #-} BLENDFUNCTION =
34+
35+
foreign import capi unsafe "windows.h AlphaBlend"
36+
c_AlphaBlend :: HDC -> Int -> Int -> Int -> Int -> HDC -> Int -> Int -> Int -> Int -> BLENDFUNCTION -> IO BOOL
37+
-}
38+
39+
foreign import WINDOWS_CCONV unsafe "windows.h TransparentBlt"
40+
c_TransparentBlt :: HDC -> Int -> Int -> Int -> Int -> HDC -> Int -> Int -> Int -> Int -> UINT -> IO BOOL
41+
42+
aC_SRC_OVER :: BYTE
43+
aC_SRC_OVER = #const AC_SRC_OVER
44+
45+
aC_SRC_ALPHA :: BYTE
46+
aC_SRC_ALPHA = #const AC_SRC_ALPHA
47+
48+
type PBLENDFUNCTION = Ptr BLENDFUNCTION
49+
type LPBLENDFUNCTION = Ptr BLENDFUNCTION
50+
51+
data BLENDFUNCTION = BLENDFUNCTION
52+
{ blendOp :: BYTE
53+
, blendFlags :: BYTE
54+
, sourceConstantAlpha :: BYTE
55+
, alphaFormat :: BYTE
56+
} deriving (Show)
57+
58+
instance Storable BLENDFUNCTION where
59+
sizeOf = const #size BLENDFUNCTION
60+
alignment = sizeOf
61+
poke buf func = do
62+
(#poke BLENDFUNCTION, BlendOp) buf (blendOp func)
63+
(#poke BLENDFUNCTION, BlendFlags) buf (blendFlags func)
64+
(#poke BLENDFUNCTION, SourceConstantAlpha) buf (sourceConstantAlpha func)
65+
(#poke BLENDFUNCTION, AlphaFormat) buf (alphaFormat func)
66+
67+
peek buf = do
68+
blendOp' <- (#peek BLENDFUNCTION, BlendOp) buf
69+
blendFlags' <- (#peek BLENDFUNCTION, BlendFlags) buf
70+
sourceConstantAlpha' <-
71+
(#peek BLENDFUNCTION, SourceConstantAlpha) buf
72+
alphaFormat' <- (#peek BLENDFUNCTION, AlphaFormat) buf
73+
return $ BLENDFUNCTION blendOp' blendFlags' sourceConstantAlpha' alphaFormat'

Graphics/Win32/GDI/Clip.hsc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ module Graphics.Win32.GDI.Clip where
2222
import Control.Monad
2323
import Graphics.Win32.GDI.Types
2424
import System.Win32.Types
25+
import Graphics.Win32.Message ( WindowMessage )
2526

2627
import Foreign
2728

2829
##include "windows_cconv.h"
2930

31+
#undef WINVER
32+
#define WINVER 0x0600
33+
#undef _WIN32_WINNT
34+
#define _WIN32_WINNT 0x0600
35+
3036
#include <windows.h>
3137

3238
type ClipboardFormat = UINT
@@ -55,8 +61,14 @@ type ClipboardFormat = UINT
5561
, cF_TEXT = CF_TEXT
5662
, cF_WAVE = CF_WAVE
5763
, cF_TIFF = CF_TIFF
64+
, cF_DIBV5 = CF_DIBV5
65+
, cF_GDIOBJLAST = CF_GDIOBJLAST
66+
, cF_UNICODETEXT = CF_UNICODETEXT
5867
}
5968

69+
wM_CLIPBOARDUPDATE :: WindowMessage
70+
wM_CLIPBOARDUPDATE = 0x031D -- #const WM_CLIPBOARDUPDATE -- Can't use constant due to GHC 7.8.x support.
71+
6072
-- % , CF_UNICODETEXT -- WinNT only
6173

6274
foreign import WINDOWS_CCONV unsafe "windows.h ChangeClipboardChain"

0 commit comments

Comments
 (0)