win32_gdi.py 1.79 KB
Newer Older
Francois Mares's avatar
add GUI  
Francois Mares committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
""" wrap GDI constants and functions to Python
"""

from ctypes import c_int, c_void_p, POINTER, Structure, WinDLL
from ctypes.wintypes import BOOL, BYTE, DWORD, HDC, WORD

_gdi32 = WinDLL('gdi32')
_user32 = WinDLL('user32')


class PixelFormatDescriptor(Structure):
    _fields_ = [
        ('nSize', WORD),
        ('nVersion', WORD),
        ('dwFlags', DWORD),
        ('iPixelType', BYTE),
        ('cColorBits', BYTE),
        ('cRedBits', BYTE),
        ('cRedShift', BYTE),
        ('cGreenBits', BYTE),
        ('cGreenShift', BYTE),
        ('cBlueBits', BYTE),
        ('cBlueShift', BYTE),
        ('cAlphaBits', BYTE),
        ('cAlphaShift', BYTE),
        ('cAccumBits', BYTE),
        ('cAccumRedBits', BYTE),
        ('cAccumGreenBits', BYTE),
        ('cAccumBlueBits', BYTE),
        ('cAccumAlphaBits', BYTE),
        ('cDepthBits', BYTE),
        ('cStencilBits', BYTE),
        ('cAuxBuffers', BYTE),
        ('iLayerType', BYTE),
        ('bReserved', BYTE),
        ('dwLayerMask', DWORD),
        ('dwVisibleMask', DWORD),
        ('dwDamageMask', DWORD),
    ]


PFD_DRAW_TO_WINDOW = 4  # Variable c_int
PFD_SUPPORT_OPENGL = 32  # Variable c_int
PFD_DOUBLEBUFFER = 1  # Variable c_int
PFD_TYPE_RGBA = 0  # Variable c_int

get_dc = _user32.GetDC
get_dc.restype = HDC
get_dc.argtypes = [c_void_p]

choose_pixel_format = _gdi32.ChoosePixelFormat
choose_pixel_format.restype = c_int
choose_pixel_format.argtypes = [c_void_p, POINTER(PixelFormatDescriptor)]

set_pixel_format = _gdi32.SetPixelFormat
set_pixel_format.restype = BOOL
set_pixel_format.argtypes = [c_void_p, c_int, POINTER(PixelFormatDescriptor)]

get_pixel_format = _gdi32.GetPixelFormat
get_pixel_format.restype = c_int
get_pixel_format.argtypes = [c_void_p]

swap_buffers = _gdi32.SwapBuffers
swap_buffers.restype = BOOL
swap_buffers.argtypes = [HDC]