gdi32.odin 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // +build windows
  2. package sys_windows
  3. import "core:math/fixed"
  4. foreign import gdi32 "system:Gdi32.lib"
  5. @(default_calling_convention="system")
  6. foreign gdi32 {
  7. GetStockObject :: proc(i: c_int) -> HGDIOBJ ---
  8. SelectObject :: proc(hdc: HDC, h: HGDIOBJ) -> HGDIOBJ ---
  9. DeleteObject :: proc(ho: HGDIOBJ) -> BOOL ---
  10. SetBkColor :: proc(hdc: HDC, color: COLORREF) -> COLORREF ---
  11. CreateCompatibleDC :: proc(hdc: HDC) -> HDC ---
  12. DeleteDC :: proc(hdc: HDC) -> BOOL ---
  13. CreateDIBPatternBrush :: proc(h: HGLOBAL, iUsage: UINT) -> HBRUSH ---
  14. CreateDIBitmap :: proc(
  15. hdc: HDC,
  16. pbmih: ^BITMAPINFOHEADER,
  17. flInit: DWORD,
  18. pjBits: VOID,
  19. pbmi: ^BITMAPINFO,
  20. iUsage: UINT,
  21. ) -> HBITMAP ---
  22. CreateDIBSection :: proc(
  23. hdc: HDC,
  24. pbmi: ^BITMAPINFO,
  25. usage: UINT,
  26. ppvBits: VOID,
  27. hSection: HANDLE,
  28. offset: DWORD,
  29. ) -> HBITMAP ---
  30. StretchDIBits :: proc(
  31. hdc: HDC,
  32. xDest: c_int,
  33. yDest: c_int,
  34. DestWidth: c_int,
  35. DestHeight: c_int,
  36. xSrc: c_int,
  37. ySrc: c_int,
  38. SrcWidth: c_int,
  39. SrcHeight: c_int,
  40. lpBits: VOID,
  41. lpbmi: ^BITMAPINFO,
  42. iUsage: UINT,
  43. rop: DWORD,
  44. ) -> c_int ---
  45. StretchBlt :: proc(
  46. hdcDest: HDC,
  47. xDest: c_int,
  48. yDest: c_int,
  49. wDest: c_int,
  50. hDest: c_int,
  51. hdcSrc: HDC,
  52. xSrc: c_int,
  53. ySrc: c_int,
  54. wSrc: c_int,
  55. hSrc: c_int,
  56. rop: DWORD,
  57. ) -> BOOL ---
  58. SetPixelFormat :: proc(hdc: HDC, format: c_int, ppfd: ^PIXELFORMATDESCRIPTOR) -> BOOL ---
  59. ChoosePixelFormat :: proc(hdc: HDC, ppfd: ^PIXELFORMATDESCRIPTOR) -> c_int ---
  60. DescribePixelFormat :: proc(hdc: HDC, iPixelFormat: c_int, nBytes: UINT, ppfd: ^PIXELFORMATDESCRIPTOR) -> c_int ---
  61. SwapBuffers :: proc(HDC) -> BOOL ---
  62. SetDCBrushColor :: proc(hdc: HDC, color: COLORREF) -> COLORREF ---
  63. GetDCBrushColor :: proc(hdc: HDC) -> COLORREF ---
  64. PatBlt :: proc(hdc: HDC, x, y, w, h: c_int, rop: DWORD) -> BOOL ---
  65. Rectangle :: proc(hdc: HDC, left, top, right, bottom: c_int) -> BOOL ---
  66. CreateFontW :: proc(
  67. cHeight, cWidth, cEscapement, cOrientation, cWeight: c_int,
  68. bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision: DWORD,
  69. iClipPrecision, iQuality, iPitchAndFamily: DWORD,
  70. pszFaceName: LPCWSTR,
  71. ) -> HFONT ---
  72. TextOutW :: proc(hdc: HDC, x, y: c_int, lpString: LPCWSTR, c: c_int) -> BOOL ---
  73. GetTextExtentPoint32W :: proc(hdc: HDC, lpString: LPCWSTR, c: c_int, psizl: LPSIZE) -> BOOL ---
  74. GetTextMetricsW :: proc(hdc: HDC, lptm: LPTEXTMETRICW) -> BOOL ---
  75. CreateSolidBrush :: proc(color: COLORREF) -> HBRUSH ---
  76. GetObjectW :: proc(h: HANDLE, c: c_int, pv: LPVOID) -> int ---
  77. CreateCompatibleBitmap :: proc(hdc: HDC, cx, cy: c_int) -> HBITMAP ---
  78. BitBlt :: proc(hdc: HDC, x, y, cx, cy: c_int, hdcSrc: HDC, x1, y1: c_int, rop: DWORD) -> BOOL ---
  79. GetDIBits :: proc(hdc: HDC, hbm: HBITMAP, start, cLines: UINT, lpvBits: LPVOID, lpbmi: ^BITMAPINFO, usage: UINT) -> int ---
  80. }
  81. RGB :: #force_inline proc "contextless" (r, g, b: u8) -> COLORREF {
  82. return transmute(COLORREF)[4]u8{r, g, b, 0}
  83. }
  84. FXPT2DOT30 :: distinct fixed.Fixed(i32, 30)
  85. CIEXYZ :: struct {
  86. ciexyzX: FXPT2DOT30,
  87. ciexyzY: FXPT2DOT30,
  88. ciexyzZ: FXPT2DOT30,
  89. }
  90. CIEXYZTRIPLE :: struct {
  91. ciexyzRed: CIEXYZ,
  92. ciexyzGreen: CIEXYZ,
  93. ciexyzBlue: CIEXYZ,
  94. }
  95. // https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapv5header
  96. BITMAPV5HEADER :: struct {
  97. bV5Size: DWORD,
  98. bV5Width: LONG,
  99. bV5Height: LONG,
  100. bV5Planes: WORD,
  101. bV5BitCount: WORD,
  102. bV5Compression: DWORD,
  103. bV5SizeImage: DWORD,
  104. bV5XPelsPerMeter: LONG,
  105. bV5YPelsPerMeter: LONG,
  106. bV5ClrUsed: DWORD,
  107. bV5ClrImportant: DWORD,
  108. bV5RedMask: DWORD,
  109. bV5GreenMask: DWORD,
  110. bV5BlueMask: DWORD,
  111. bV5AlphaMask: DWORD,
  112. bV5CSType: DWORD,
  113. bV5Endpoints: CIEXYZTRIPLE,
  114. bV5GammaRed: DWORD,
  115. bV5GammaGreen: DWORD,
  116. bV5GammaBlue: DWORD,
  117. bV5Intent: DWORD,
  118. bV5ProfileData: DWORD,
  119. bV5ProfileSize: DWORD,
  120. bV5Reserved: DWORD,
  121. }