Advertisement
Kitomas

work for 2025-03-28 (2/2)

Mar 28th, 2025
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 32.98 KB | None | 0 0
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. //"gdi_winmm_2025-03-28\include\public_stuff.hpp":
  4. #ifndef _PUBLIC_STUFF_HPP
  5. #define _PUBLIC_STUFF_HPP
  6.  
  7. #include <stdio.h>
  8.  
  9. // If you don't end up using anything else from stdio,
  10. // using this makes sure the function is only included in the debug build!
  11. #ifdef _DEBUG
  12.   #define _printf(...) printf(__VA_ARGS__)
  13. #else
  14.   #define _printf(...)
  15. #endif /* _DEBUG */
  16.  
  17.  
  18.  
  19. #ifndef   M_PI4f
  20. #define   M_PI4f 0.7853981633974483096156608f
  21. #endif /* M_PI2 */
  22.  
  23. #ifndef   M_PI2f
  24. #define   M_PI2f 1.5707963267948966192313216f
  25. #endif /* M_PI2 */
  26.  
  27. #ifndef   M_PIf
  28. #define   M_PIf  3.1415926535897932384626433f
  29. #endif /* M_PIf */
  30.  
  31. #ifndef   M_2PIf
  32. #define   M_2PIf 6.2831853071795864769252866f
  33. #endif /* M_2PIf */
  34.  
  35. #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
  36. #define MAX(a,b) ( ((a)<(b)) ? (b) : (a) )
  37. #define CLAMP(v, mn, mx) MIN(MAX(v, mn), mx)
  38.  
  39.  
  40.  
  41. #ifdef __cplusplus
  42.   #include <cstddef>
  43.   #include <cstdint>
  44. #else
  45.   #include <stdint.h>
  46. #endif /* __cplusplus */
  47.  
  48. typedef uint8_t  u8;
  49. typedef uint16_t u16;
  50. typedef uint32_t u32;
  51. typedef uint64_t u64;
  52.  
  53. typedef int8_t  s8;
  54. typedef int16_t s16;
  55. typedef int32_t s32;
  56. typedef int64_t s64;
  57.  
  58. typedef float  f32;
  59. typedef double f64;
  60.  
  61.  
  62.  
  63.  
  64.  
  65. /************************************ MISC ************************************/
  66.  
  67. struct Fpoint2d { f32 x, y; };
  68. struct Point2d  { s32 x, y; };
  69. struct Rect2d   { s32 x, y, w, h; };
  70.  
  71.  
  72.  
  73. // "std.cpp":
  74.  
  75. void* memSet(void* dst, int val, size_t len);
  76.  
  77. //(len_max does not include null-terminator!)
  78. //(if !len_max, call is analogous to str(not n)len)
  79. size_t strnLen(const char* str, size_t len_max);
  80.  
  81. char* strnCpy(char* str_dst, const char* str_src, size_t len_max);
  82.  
  83. char* strCat(char* dst, const char* src);
  84.  
  85. //(len_max does not include null-terminator!)
  86. //(if !len_max, call is analogous to str(not n)cmp)
  87. s32 strnCmp(const char* str_a, const char* str_b, size_t len_max);
  88.  
  89. f32 sinF(f32 x);
  90. #define cosF(_x) sinF((_x)+M_PI2f)
  91. #define tanF(_x) ( sinF(_x)/cosF(_x) )
  92.  
  93.  
  94.  
  95. #if defined(_INC_STRING) || defined(_GLIBCXX_CSTRING)
  96.   #define memSet  memset
  97.   #define strnLen strnlen
  98.   #define strnCpy strncpy
  99.   #define strCat  strcat
  100.   #define strnCmp strncmp
  101. #endif
  102.  
  103. #if defined(_MATH_H_) || defined(_GLIBCXX_CMATH)
  104.   #define sinF sinf
  105. #endif
  106.  
  107. #if !defined(_INC_STDLIB) && !defined(_GLIBCXX_CSTDLIB) && !defined(_GLIBCXX_STDLIB_H)
  108.   #include <win32/misc.hpp>
  109.   #define malloc  CoTaskMemAlloc
  110.   #define realloc CoTaskMemRealloc
  111.   #define free    CoTaskMemFree
  112. #endif
  113.  
  114.  
  115.  
  116. // "misc.cpp":
  117.  
  118. enum MessageBoxEnum {
  119.   // Return values
  120.   MSGBOX_RTN_NULL     = 0x00000000, //showMessageBox failed
  121.   MSGBOX_RTN_OK       = 0x00000001, //'ok' button was clicked
  122.   MSGBOX_RTN_CANCEL   = 0x00000002, //'cancel' button was clicked
  123.   MSGBOX_RTN_ABORT    = 0x00000003, //'abort' button was clicked
  124.   MSGBOX_RTN_RETRY    = 0x00000004, //'retry' button was clicked
  125.   MSGBOX_RTN_IGNORE   = 0x00000005, //'ignore' button was clicked
  126.   MSGBOX_RTN_YES      = 0x00000006, //'yes' button was clicked
  127.   MSGBOX_RTN_NO       = 0x00000007, //'no' button was clicked
  128.   MSGBOX_RTN_TRYAGAIN = 0x0000000A, //'try again' button was clicked
  129.   MSGBOX_RTN_CONTINUE = 0x0000000B, //'continue' button was clicked
  130.  
  131.   // Button types
  132.   MSGBOX_BTN_OK                = 0x00000000,
  133.   MSGBOX_BTN_OKCANCEL          = 0x00000001,
  134.   MSGBOX_BTN_ABORTRETRYIGNORE  = 0x00000002,
  135.   MSGBOX_BTN_YESNOCANCEL       = 0x00000003,
  136.   MSGBOX_BTN_YESNO             = 0x00000004,
  137.   MSGBOX_BTN_RETRYCANCEL       = 0x00000005,
  138.   MSGBOX_BTN_CANCELTRYCONTINUE = 0x00000006,
  139.  
  140.   // Icon types
  141.   MSGBOX_ICN_ERROR    = 0x000000010,
  142.   MSGBOX_ICN_QUESTION = 0x000000020, //apparently deprecated, but still supported
  143.   MSGBOX_ICN_WARNING  = 0x000000030,
  144.   MSGBOX_ICN_INFO     = 0x000000040,
  145.  
  146. };
  147.  
  148. u32 showMessageBox(const char* text = nullptr, const char* title = nullptr,
  149.                    u32 type = 0, u32 defaultButton = 0);
  150.  
  151. u64 timeGetPerfCounter();
  152. u64 timeGetPerfFreq();
  153. f64 timeGetSeconds();
  154.  
  155. void timeSleep(u32 milliseconds);
  156.  
  157.  
  158.  
  159.  
  160.  
  161. /*********************************** INPUT ************************************/
  162.  
  163. #define EVENT_ID(_id) ( (_id) & 0xFFFF0000 )
  164. #define SUBEVENT_ID(_id) ( (_id) & 0xFFFF )
  165.  
  166. enum EventEnum {
  167.   EVENT_NULL           = 0x00000000,
  168.  
  169.   EVENT_COMMON         = 0x00010000, // Event_Common (Event.common)
  170.  
  171.   // (Occurs when the window is destroyed!)
  172.   EVENT_QUIT           = 0x00020000, // N/A (N/A)
  173.  
  174.   EVENT_KEY            = 0x00030000, // Event_Key (Event.key)
  175.   EVENT_KEY_CHAR       = EVENT_KEY   | 0x0001,
  176.   EVENT_KEY_UP         = EVENT_KEY   | 0x0002,
  177.   EVENT_KEY_DOWN       = EVENT_KEY   | 0x0003,
  178.  
  179.   EVENT_MOUSE          = 0x00040000, // Event_Mouse (Event.mouse)
  180.   EVENT_MOUSE_MOVED    = EVENT_MOUSE | 0x0001,
  181.   EVENT_MOUSE_HWHEEL   = EVENT_MOUSE | 0x0002,
  182.   EVENT_MOUSE_VWHEEL   = EVENT_MOUSE | 0x0003,
  183.   EVENT_MOUSE_UP       = EVENT_MOUSE | 0x0004,
  184.   EVENT_MOUSE_DOWN     = EVENT_MOUSE | 0x0005,
  185.  
  186. };
  187.  
  188.  
  189.  
  190. /*+EVENT_COMMON+*/
  191.  
  192. struct Event_Common { //16B
  193.   u32  type;
  194.   u32 _unused; // Unused by common, but not necessarily other event types
  195.   u64  timestamp; // Performance counter is used; see "timeGetPerfCounter()"
  196. };
  197.  
  198. /*-EVENT_COMMON-*/
  199.  
  200.  
  201.  
  202. /*+EVENT_KEY+*/
  203.  
  204. // Event_Key.kmods can use any combination of these OR'd (AKA |) together
  205. enum Event_Key_ModifierEnum { // (These are bitmasks)
  206.   KMOD_NONE      = 0x0000,
  207.   KMOD_LSHIFT    = 0x0001,
  208.   KMOD_RSHIFT    = 0x0002,
  209.   KMOD_LCTRL     = 0x0004,
  210.   KMOD_RCTRL     = 0x0008,
  211.   KMOD_LALT      = 0x0010,
  212.   KMOD_RALT      = 0x0020,
  213.   KMOD_LGUI      = 0x0040, // Windows key?
  214.   KMOD_RGUI      = 0x0080,  //^^
  215.     KMOD_LWIN    = KMOD_LGUI,
  216.     KMOD_RWIN    = KMOD_RGUI,
  217.   KMOD_NUMLOCK   = 0x1000,
  218.   KMOD_CAPSLOCK  = 0x2000,
  219.   KMOD_ALTGRAPH  = 0x4000,
  220.   KMOD_SCROLLOCK = 0x8000,
  221.   KMOD_CTRL      = ( KMOD_LCTRL  | KMOD_RCTRL  ),
  222.   KMOD_SHIFT     = ( KMOD_LSHIFT | KMOD_RSHIFT ),
  223.   KMOD_ALT       = ( KMOD_LALT   | KMOD_RALT   ),
  224.   KMOD_GUI       = ( KMOD_LGUI   | KMOD_RGUI   ),
  225.   KMOD_WIN       = ( KMOD_LWIN   | KMOD_RWIN   ),
  226. };
  227.  
  228.  
  229.  
  230. enum Event_Key_PhysicalEnum {
  231.   // TBD because I don't want to bother with scancode stuff right now
  232. };
  233.  
  234.  
  235.  
  236. enum Event_Key_VirtualEnum {
  237.   //(misc. mouse)       = 0x01 -> 0x06
  238.   //(reserved)          = 0x07,
  239.   VKEY_BACK             = 0x08, //backspace key
  240.     VKEY_BACKSPACE      = VKEY_BACK,
  241.   VKEY_TAB              = 0x09,
  242.   //(reserved)          = 0x0A -> 0x0B,
  243.   VKEY_CLEAR            = 0x0C,
  244.   VKEY_RETURN           = 0x0D, //enter key
  245.     VKEY_ENTER          = VKEY_RETURN,
  246.   //(unassigned)        = 0x0E -> 0x0F,
  247.   VKEY_SHIFT            = 0x10,
  248.   VKEY_CONTROL          = 0x11, //ctrl key
  249.     VKEY_CTRL           = VKEY_CONTROL,
  250.   VKEY_MENU             = 0x12, //alt key
  251.     VKEY_ALT            = VKEY_MENU,
  252.   VKEY_PAUSE            = 0x13,
  253.   VKEY_CAPITAL          = 0x14, //caps lock key
  254.     VKEY_CAPSLOCK       = VKEY_CAPITAL,
  255.   //(IME stuff)         = 0x15 -> 0x1A,
  256.   VKEY_ESCAPE           = 0x1B, //esc key
  257.   //(IME stuff)         = 0x1C -> 0x1F,
  258.   VKEY_SPACE            = 0x20, //space bar key
  259.   VKEY_PRIOR            = 0x21, //page up key
  260.     VKEY_PGUP           = VKEY_PRIOR,
  261.   VKEY_NEXT             = 0x22, //page down key
  262.     VKEY_PGDN           = VKEY_NEXT,
  263.   VKEY_END              = 0x23,
  264.   VKEY_HOME             = 0x24,
  265.   VKEY_LEFT             = 0x25, //left arrow key
  266.   VKEY_UP               = 0x26, //up arrow key
  267.   VKEY_RIGHT            = 0x27, //right arrow key
  268.   VKEY_DOWN             = 0x28, //down arrow key
  269.   VKEY_SELECT           = 0x29,
  270.   VKEY_PRINT            = 0x2A,
  271.   VKEY_EXECUTE          = 0x2B,
  272.   VKEY_SNAPSHOT         = 0x2C, //print screen key
  273.     VKEY_PRTSC          = VKEY_SNAPSHOT,
  274.   VKEY_INSERT           = 0x2D, //ins key
  275.   VKEY_DELETE           = 0x2E, //del key
  276.   VKEY_HELP             = 0x2F, //help key
  277.   VKEY_0                = 0x30, //'0'
  278.   VKEY_1                = 0x31, //'1'
  279.   VKEY_2                = 0x32, //'2'
  280.   VKEY_3                = 0x33, //'3'
  281.   VKEY_4                = 0x34, //'4'
  282.   VKEY_5                = 0x35, //'5'
  283.   VKEY_6                = 0x36, //'6'
  284.   VKEY_7                = 0x37, //'7'
  285.   VKEY_8                = 0x38, //'8'
  286.   VKEY_9                = 0x39, //'9'
  287.   //(undefined)         = 0x3A -> 0x40,
  288.   VKEY_A                = 0x41, //'A'
  289.   VKEY_B                = 0x42, //'B'
  290.   VKEY_C                = 0x43, //'C'
  291.   VKEY_D                = 0x44, //'D'
  292.   VKEY_E                = 0x45, //'E'
  293.   VKEY_F                = 0x46, //'F'
  294.   VKEY_G                = 0x47, //'G'
  295.   VKEY_H                = 0x48, //'H'
  296.   VKEY_I                = 0x49, //'I'
  297.   VKEY_J                = 0x4A, //'J'
  298.   VKEY_K                = 0x4B, //'K'
  299.   VKEY_L                = 0x4C, //'L'
  300.   VKEY_M                = 0x4D, //'M'
  301.   VKEY_N                = 0x4E, //'N'
  302.   VKEY_O                = 0x4F, //'O'
  303.   VKEY_P                = 0x50, //'P'
  304.   VKEY_Q                = 0x51, //'Q'
  305.   VKEY_R                = 0x52, //'R'
  306.   VKEY_S                = 0x53, //'S'
  307.   VKEY_T                = 0x54, //'T'
  308.   VKEY_U                = 0x55, //'U'
  309.   VKEY_V                = 0x56, //'V'
  310.   VKEY_W                = 0x57, //'W'
  311.   VKEY_X                = 0x58, //'X'
  312.   VKEY_Y                = 0x59, //'Y'
  313.   VKEY_Z                = 0x5A, //'Z'
  314.   VKEY_LWIN             = 0x5B, //left windows key
  315.   VKEY_RWIN             = 0x5C, //right windows key
  316.   VKEY_APPS             = 0x5D, //applications key
  317.   //(reserved)          = 0x5E,
  318.   VKEY_SLEEP            = 0x5F, //computer sleep key
  319.   VKEY_NUMPAD0          = 0x60,
  320.   VKEY_NUMPAD1          = 0x61,
  321.   VKEY_NUMPAD2          = 0x62,
  322.   VKEY_NUMPAD3          = 0x63,
  323.   VKEY_NUMPAD4          = 0x64,
  324.   VKEY_NUMPAD5          = 0x65,
  325.   VKEY_NUMPAD6          = 0x66,
  326.   VKEY_NUMPAD7          = 0x67,
  327.   VKEY_NUMPAD8          = 0x68,
  328.   VKEY_NUMPAD9          = 0x69,
  329.   VKEY_MULTIPLY         = 0x6A, //numpad '*'
  330.   VKEY_ADD              = 0x6B, //numpad '+'
  331.   VKEY_SEPARATOR        = 0x6C, //numpad enter
  332.   VKEY_SUBTRACT         = 0x6D, //numpad '-'
  333.   VKEY_DECIMAL          = 0x6E, //numpad '.'
  334.   VKEY_DIVIDE           = 0x6F, //numpad '/'
  335.   VKEY_F1               = 0x70,
  336.   VKEY_F2               = 0x71,
  337.   VKEY_F3               = 0x72,
  338.   VKEY_F4               = 0x73,
  339.   VKEY_F5               = 0x74,
  340.   VKEY_F6               = 0x75,
  341.   VKEY_F7               = 0x76,
  342.   VKEY_F8               = 0x77,
  343.   VKEY_F9               = 0x78,
  344.   VKEY_F10              = 0x79,
  345.   VKEY_F11              = 0x7A,
  346.   VKEY_F12              = 0x7B,
  347.   VKEY_F13              = 0x7C,
  348.   VKEY_F14              = 0x7D,
  349.   VKEY_F15              = 0x7E,
  350.   VKEY_F16              = 0x7F,
  351.   VKEY_F17              = 0x80,
  352.   VKEY_F18              = 0x81,
  353.   VKEY_F19              = 0x82,
  354.   VKEY_F20              = 0x83,
  355.   VKEY_F21              = 0x84,
  356.   VKEY_F22              = 0x85,
  357.   VKEY_F23              = 0x86,
  358.   VKEY_F24              = 0x87,
  359.   //(reserved)          = 0x88 -> 0x8F,
  360.   VKEY_NUMLOCK          = 0x90,
  361.   VKEY_SCROLL           = 0x91, //scroll lock key
  362.     VKEY_SCROLLOCK      = VKEY_SCROLL,
  363.   //(OEM-specific)      = 0x92 -> 0x96,
  364.   //(unassigned)        = 0x97 -> 0x9F,
  365.   //(l/r key variants)  = 0xA0 -> 0xA5,
  366.   //(browser keys)      = 0xA6 -> 0xAC,
  367.   VKEY_VOLUME_MUTE      = 0xAD,
  368.   VKEY_VOLUME_DOWN      = 0xAE,
  369.   VKEY_VOLUME_UP        = 0xAF,
  370.   VKEY_MEDIA_NEXT_TRACK = 0xB0,
  371.   VKEY_MEDIA_PREV_TRACK = 0xB1,
  372.   VKEY_MEDIA_STOP       = 0xB2,
  373.   VKEY_MEDIA_PLAY_PAUSE = 0xB3, //Play/Pause Media key
  374.   //(launch keys)       = 0xB4 -> 0xB7,
  375.   //(reserved)          = 0xB8 -> 0xB9,
  376.   VKEY_OEM_1            = 0xBA, //misc. chars; varies by keyboard (';',':' on US standard)
  377.     VKEY_SEMICOLON      = VKEY_OEM_1,
  378.   VKEY_OEM_PLUS         = 0xBB, //'+' in any country/region
  379.     VKEY_PLUS           = VKEY_OEM_PLUS,
  380.   VKEY_OEM_COMMA        = 0xBC, //',' in any country/region
  381.     VKEY_COMMA          = VKEY_OEM_COMMA,
  382.   VKEY_OEM_MINUS        = 0xBD, //'-' in any country/region
  383.     VKEY_MINUS          = VKEY_OEM_MINUS,
  384.   VKEY_OEM_PERIOD       = 0xBE, //'.' in any country/region
  385.     VKEY_PERIOD         = VKEY_OEM_PERIOD,
  386.   VKEY_OEM_2            = 0xBF, //misc. chars; varies by keyboard ('/','?' on US standard)
  387.     VKEY_FSLASH         = VKEY_OEM_2,
  388.   VKEY_OEM_3            = 0xC0, //misc. chars; varies by keyboard ('`','~' on US standard)
  389.     VKEY_BACKTICK       = VKEY_OEM_3,
  390.   //(reserved)          = 0xC1 -> 0xDA,
  391.   VKEY_OEM_4            = 0xDB, //misc. chars; varies by keyboard ('[','{' on US standard)
  392.     VKEY_LBRACKET       = VKEY_OEM_4,
  393.   VKEY_OEM_5            = 0xDC, //misc. chars; varies by keyboard ('\\','|' on US standard)
  394.     VKEY_BSLASH         = VKEY_OEM_5,
  395.   VKEY_OEM_6            = 0xDD, //misc. chars; varies by keyboard (']','}' on US standard)
  396.     VKEY_RBRACKET       = VKEY_OEM_6,
  397.   VKEY_OEM_7            = 0xDE, //misc. chars; varies by keyboard ('\'','\"' on US standard)
  398.     VKEY_APOSTROPHE     = VKEY_OEM_7,
  399.   VKEY_OEM_8            = 0xDF, //misc. chars; varies by keyboard
  400.   //(reserved)          = 0xE0,
  401.   //(misc.)             = 0xE1 -> 0xE7,
  402.   //(unassigned)        = 0xE8,
  403.   //(misc.)             = 0xE9 -> 0xFE,
  404.  
  405. };
  406.  
  407.  
  408.  
  409. // Mod[ifier]
  410. union Event_Key_Mod { //2B
  411.   // IMPORTANT:
  412.   // Due to me having terminal couldn't-care-less syndrome,
  413.   // I haven't implemented differenciating between the
  414.   // left and right variants of shift, control, et cetera,
  415.   // so both variants are set/unset when either are pressed/unpressed.
  416.   // (Except lgui and rgui, since that's easier to detect???)
  417.   // (ALSO ALTGRAPH ISN'T IMPLEMENTED AT ALL THANKS MICROSOFT)
  418.  
  419.   struct {
  420.     u16 lshift    : 1;
  421.     u16 rshift    : 1;
  422.     u16 lctrl     : 1;
  423.     u16 rctrl     : 1;
  424.     u16 lalt      : 1;
  425.     u16 ralt      : 1;
  426.     u16 lgui      : 1;
  427.     u16 rgui      : 1;
  428.     u16 _unused   : 4;
  429.     u16 numlock   : 1;
  430.     u16 capslock  : 1;
  431.     u16 altgraph  : 1;
  432.     u16 scrollock : 1;
  433.   };
  434.  
  435.   u16 all;
  436.  
  437. };
  438.  
  439.  
  440.  
  441. // Short for Key Symbol
  442. struct Event_Key_Sym { //8B
  443.   union {
  444.     Event_Key_Mod kmod;
  445.     u16           kmods;
  446.   };
  447.  
  448.   u8  _unused;
  449.   u8   pkey; // Physical key code (named .scancode in SDL's Keysym struct)
  450.   u8   vkey; // Virtual key code (named .sym in SDL's Keysym struct)
  451.   bool pressed;
  452.   bool ischar; // 'is event KEY_CHAR?', otherwise it's KEY_UP or KEY_DOWN
  453.   bool repeat; // Y'know that thing where in a text editor you hold down a key?
  454.  
  455. };
  456.  
  457.  
  458.  
  459. struct Event_Key { //24B
  460.   u32  type;
  461.  
  462.   u32 _unused_0;
  463.  
  464.   u64  timestamp; // Performance counter is used; see "timeGetPerfCounter()"
  465.  
  466.   union {
  467.     struct { // (Effectively a copy of Event_Key_Sym)
  468.       u16  kmods;
  469.       u8  _unused_1;
  470.       u8   pkey;
  471.       u8   vkey;
  472.       bool pressed;
  473.       bool ischar;
  474.       bool repeat;
  475.     };
  476.     Event_Key_Sym sym;
  477.   };
  478.  
  479. };
  480.  
  481. /*-EVENT_KEY-*/
  482.  
  483.  
  484.  
  485. /*+EVENT_MOUSE+*/
  486.  
  487. // Event_Mouse.button can use any combination of these OR'd (AKA |) together
  488. enum Event_Mouse_ButtonEnum { // (These are bitmasks)
  489.   MBUTTON_LEFT   = 0x01,
  490.   MBUTTON_MIDDLE = 0x02,
  491.   MBUTTON_RIGHT  = 0x04,
  492.   MBUTTON_X1     = 0x08, // Those 2 buttons on the sides of most mice nowadays
  493.   MBUTTON_X2     = 0x10,  //^^
  494. };
  495.  
  496. // (EVENT_MOUSE_<H/V>WHEEL events use dx and dy!)
  497. struct Event_Mouse { //32B
  498.   u32  type;
  499.  
  500.   u8  _unused;
  501.   u8   button;   // Flags for currently pressed buttons (Event_Mouse_ButtonEnum)
  502.   bool pressed;  // Will be true if button is nonzero
  503.   bool dblClick; // 'Is double click?'
  504.  
  505.   u64  timestamp;
  506.  
  507.   f32  x;  // Coordinates relative to window
  508.   f32  y;   //^^
  509.   f32  dx; // Delta x (coordinates relative to last recorded x position)
  510.   f32  dy; // Delta y (coordinates relative to last recorded y position)
  511.  
  512. };
  513.  
  514. /*-EVENT_MOUSE-*/
  515.  
  516.  
  517.  
  518. union Event { //32B (assuming Event_Mouse is the largest event bytes-wise)
  519.   u32          type;
  520.  
  521.   Event_Common common;
  522.   Event_Key    key;
  523.   Event_Mouse  mouse;
  524.  
  525. };
  526.  
  527.  
  528.  
  529. // Populates *event_p with the contents of the first event in the event queue.
  530. // Returns false if there were no events left in queue; true otherwise.
  531. // (Calling this exclusively in the main thread is recommended)
  532. bool pollEvent(Event* event_p = nullptr); // Burns events if event_p is nullptr
  533.  
  534.  
  535.  
  536.  
  537.  
  538. /*********************************** AUDIO ************************************/
  539.  
  540. // Stereo audio samples as two 32-bit floats,
  541. // where each of the two channels can be between -1.0 to 1.0
  542. struct StereoF32 { f32 l,r; };
  543.  
  544.  
  545.  
  546. // The length of the audio stream's buffer, in samples
  547. extern u32 audio_samples;
  548.  
  549. // The audio's sample rate, in hertz
  550. extern u32 sample_rate;
  551.  
  552.  
  553.  
  554.  
  555.  
  556. /*********************************** VIDEO ************************************/
  557.  
  558. #define WINDOW_NAME "GDI Playground"
  559.  
  560. // If left at 4, window will initially appear 4x as big as canvas
  561. #define WINDOW_RESMUL 4
  562.  
  563. // Technically customizable, but keeping it at 256x144 makes it 16:9,
  564. // while also taking advantage of the fact an x position can just be
  565. // stored within a single byte. This's useful for several types of optimizations
  566. #define CANVAS_W 256
  567. #define CANVAS_H 144
  568.  
  569.  
  570.  
  571. // This assumes the canvas width is equal to 256
  572. union PixelCoords {
  573.   u16 v; // Full index
  574.  
  575.   struct { u8 x, y; };
  576.  
  577.   PixelCoords() : v(0) {}
  578.   PixelCoords(u16 _v) : v(_v) {}
  579.   PixelCoords(u8 _x, u8 _y) : x(_x), y(_y) {}
  580.  
  581. };
  582.  
  583.  
  584.  
  585. // Used for the pixel buffer. This corresponds to the 8-bit color palette
  586. // initially set during initialization. However, this palette can be
  587. // changed by setting entries in pixels_palette and calling update_palette()
  588. union Color8 {
  589.   u8 v; // Full pixel value
  590.  
  591.   struct {
  592.     u8 r : 3;
  593.     u8 g : 3;
  594.     u8 b : 2;
  595.   };
  596.  
  597.   Color8() : v(0) {}
  598.   Color8(u8 _v) : v(_v) {}
  599.  
  600. };
  601.  
  602.  
  603.  
  604. // Used for setting pixels_palette.
  605. // (Make sure to call update_palette() to apply any changes to the palette!)
  606. union Color24 {
  607.   u32 v; // Full pixel value
  608.  
  609.   struct {
  610.     u8 r;
  611.     u8 g;
  612.     u8 b;
  613.     u8 _; // (Unused; this is just padding to the nearest multiple of 32-bits)
  614.   };
  615.  
  616. };
  617.  
  618.  
  619.  
  620. extern Color8*  pixels;
  621. extern Color24* pixels_palette;
  622.  
  623. extern bool win_closed;
  624.  
  625.  
  626.  
  627. void canvas_present(bool immediate = true);
  628.  
  629. void close_window(); // Also triggers an EVENT_QUIT
  630.  
  631. // Updates the 256-color palette. It defaults to the built-in one,
  632. // but not only can you edit the built-in palette, you can make this
  633. // function use another palette, just in case you want to swap out
  634. // entirely different palettes on the fly!
  635. //
  636. // Does nothing if new_palette is given as NULL.
  637. // This also makes sure that no color beyond the 255th is changed.
  638. // For example, if first_color is 255, and num_colors is 2,
  639. // only a single color will be changed, since 255 is the last color index
  640. //
  641. // Returns true on success, false otherwise
  642. bool update_palette(const Color24* new_palette = pixels_palette,
  643.                     u32 first_color = 0, u32 num_colors = 256);
  644.  
  645.  
  646.  
  647.  
  648.  
  649. #endif /* _PUBLIC_STUFF_HPP */
  650. /******************************************************************************/
  651. /******************************************************************************/
  652. //"gdi_winmm_2025-03-28\include\win32\audio.hpp":
  653. #ifndef _WIN32_AUDIO_HPP
  654. #define _WIN32_AUDIO_HPP
  655.  
  656. #include <public_stuff.hpp>
  657.  
  658. #include <windows.h>
  659. #include <mmsystem.h>
  660.  
  661.  
  662.  
  663. #define waveOutGetNumDevs      _Winmm_func.waveOutGetNumDevs_
  664. #define waveOutGetDevCapsA     _Winmm_func.waveOutGetDevCapsA_
  665. #define waveOutGetVolume       _Winmm_func.waveOutGetVolume_
  666. #define waveOutSetVolume       _Winmm_func.waveOutSetVolume_
  667. #define waveOutGetErrorTextA   _Winmm_func.waveOutGetErrorTextA_
  668. #define waveOutOpen            _Winmm_func.waveOutOpen_
  669. #define waveOutClose           _Winmm_func.waveOutClose_
  670. #define waveOutPrepareHeader   _Winmm_func.waveOutPrepareHeader_
  671. #define waveOutUnprepareHeader _Winmm_func.waveOutUnprepareHeader_
  672. #define waveOutWrite           _Winmm_func.waveOutWrite_
  673. #define waveOutPause           _Winmm_func.waveOutPause_
  674. #define waveOutRestart         _Winmm_func.waveOutRestart_
  675. #define waveOutReset           _Winmm_func.waveOutReset_
  676. #define waveOutBreakLoop       _Winmm_func.waveOutBreakLoop_
  677. #define waveOutGetPosition     _Winmm_func.waveOutGetPosition_
  678. #define waveOutGetPitch        _Winmm_func.waveOutGetPitch_
  679. #define waveOutSetPitch        _Winmm_func.waveOutSetPitch_
  680. #define waveOutGetPlaybackRate _Winmm_func.waveOutGetPlaybackRate_
  681. #define waveOutSetPlaybackRate _Winmm_func.waveOutSetPlaybackRate_
  682. #define waveOutGetID           _Winmm_func.waveOutGetID_
  683. #define waveOutMessage         _Winmm_func.waveOutMessage_
  684.  
  685. union _Winmm_func_t {
  686.   FARPROC ptrs[1];
  687.  
  688.   struct {
  689.     //UINT     (WINAPI *waveOutGetNumDevs_)(void);
  690.     MMRESULT (WINAPI *waveOutGetDevCapsA_)(UINT_PTR, LPWAVEOUTCAPSA, UINT);
  691.     //MMRESULT (WINAPI *waveOutGetVolume_)(HWAVEOUT, LPDWORD);
  692.     MMRESULT (WINAPI *waveOutSetVolume_)(HWAVEOUT, DWORD);
  693.     //MMRESULT (WINAPI *waveOutGetErrorTextA_)(MMRESULT, LPSTR, UINT);
  694.     MMRESULT (WINAPI *waveOutOpen_)(LPHWAVEOUT, UINT, LPCWAVEFORMATEX, DWORD_PTR, DWORD_PTR, DWORD);
  695.     //MMRESULT (WINAPI *waveOutClose_)(HWAVEOUT);
  696.     MMRESULT (WINAPI *waveOutPrepareHeader_)(HWAVEOUT, LPWAVEHDR, UINT);
  697.     //MMRESULT (WINAPI *waveOutUnprepareHeader_)(HWAVEOUT, LPWAVEHDR, UINT);
  698.     MMRESULT (WINAPI *waveOutWrite_)(HWAVEOUT, LPWAVEHDR, UINT);
  699.     MMRESULT (WINAPI *waveOutPause_)(HWAVEOUT);
  700.     //MMRESULT (WINAPI *waveOutRestart_)(HWAVEOUT);
  701.     //MMRESULT (WINAPI *waveOutReset_)(HWAVEOUT);
  702.     //MMRESULT (WINAPI *waveOutBreakLoop_)(HWAVEOUT);
  703.     //MMRESULT (WINAPI *waveOutGetPosition_)(HWAVEOUT, LPMMTIME, UINT);
  704.     //MMRESULT (WINAPI *waveOutGetPitch_)(HWAVEOUT, LPDWORD);
  705.     //MMRESULT (WINAPI *waveOutSetPitch_)(HWAVEOUT, DWORD);
  706.     //MMRESULT (WINAPI *waveOutGetPlaybackRate_)(HWAVEOUT, LPDWORD);
  707.     //MMRESULT (WINAPI *waveOutSetPlaybackRate_)(HWAVEOUT, DWORD);
  708.     //MMRESULT (WINAPI *waveOutGetID_)(HWAVEOUT, LPUINT);
  709.     //MMRESULT (WINAPI *waveOutMessage_)(HWAVEOUT, UINT, DWORD_PTR, DWORD_PTR);
  710.   };
  711. };
  712.  
  713. extern _Winmm_func_t _Winmm_func;
  714. extern char          _Winmm_names[];
  715.  
  716.  
  717.  
  718. /******************************************************************************/
  719.  
  720.  
  721.  
  722. // Stereo audio samples as two 16-bit signed ints
  723. struct StereoS16 { s16 l,r; };
  724.  
  725.  
  726.  
  727. int WaveOutInit();
  728.  
  729. void WaveOutQuit();
  730.  
  731.  
  732.  
  733. #endif /* _WIN32_AUDIO_HPP */
  734. /******************************************************************************/
  735. /******************************************************************************/
  736. //"gdi_winmm_2025-03-28\include\win32\input.hpp":
  737. #ifndef _WIN32_INPUT_HPP
  738. #define _WIN32_INPUT_HPP
  739.  
  740. #include <windows.h>
  741.  
  742. #include <public_stuff.hpp>
  743.  
  744.  
  745.  
  746. int InputInit();
  747.  
  748. void InputQuit();
  749.  
  750.  
  751.  
  752. union Event; // Forward declaration
  753.  
  754. // Returns false if queue is full
  755. bool AddToEventQueue(Event& event);
  756.  
  757. // Returns a EVENT_NULL event if queue is empty
  758. Event RemoveFromEventQueue();
  759.  
  760.  
  761.  
  762. #endif /* _WIN32_INPUT_HPP */
  763. /******************************************************************************/
  764. /******************************************************************************/
  765. //"gdi_winmm_2025-03-28\include\win32\misc.hpp":
  766. #ifndef _WIN32_MISC_HPP
  767. #define _WIN32_MISC_HPP
  768.  
  769. //#include <windows.h>
  770. #include <combaseapi.h>
  771.  
  772.  
  773.  
  774. #define CoTaskMemAlloc   _Ole32_func.CoTaskMemAlloc_
  775. #define CoTaskMemRealloc _Ole32_func.CoTaskMemRealloc_
  776. #define CoTaskMemFree    _Ole32_func.CoTaskMemFree_
  777.  
  778. union _Ole32_func_t {
  779.   FARPROC ptrs[3];
  780.  
  781.   struct {
  782.     LPVOID (*CoTaskMemAlloc_)   (SIZE_T);
  783.     LPVOID (*CoTaskMemRealloc_) (LPVOID, SIZE_T);
  784.     void   (*CoTaskMemFree_)    (LPVOID);
  785.   };
  786.  
  787. };
  788.  
  789. extern _Ole32_func_t _Ole32_func;
  790. extern char          _Ole32_names[];
  791.  
  792.  
  793.  
  794. #define CRITICAL_SECTION_SPINCOUNT 2048
  795.  
  796.  
  797.  
  798. #endif /* _WIN32_MISC_HPP */
  799. /******************************************************************************/
  800. /******************************************************************************/
  801. //"gdi_winmm_2025-03-28\include\win32\video.hpp":
  802. #ifndef _WIN32_VIDEO_HPP
  803. #define _WIN32_VIDEO_HPP
  804.  
  805. #include <windows.h>
  806.  
  807.  
  808.  
  809. #define RegisterClassA     _User32_func.RegisterClassA_
  810. #define CreateWindowExA    _User32_func.CreateWindowExA_
  811. #define DefWindowProcA     _User32_func.DefWindowProcA_
  812. #define InvalidateRect     _User32_func.InvalidateRect_
  813. #define UpdateWindow       _User32_func.UpdateWindow_
  814. #define BeginPaint         _User32_func.BeginPaint_
  815. #define EndPaint           _User32_func.EndPaint_
  816. #define PeekMessageA       _User32_func.PeekMessageA_
  817. #define DispatchMessageA   _User32_func.DispatchMessageA_
  818. #define DestroyWindow      _User32_func.DestroyWindow_
  819. #define ReleaseDC          _User32_func.ReleaseDC_
  820. #define GetDC              _User32_func.GetDC_
  821. #define PostQuitMessage    _User32_func.PostQuitMessage_
  822. #define MessageBoxA        _User32_func.MessageBoxA_
  823. #define TranslateMessage   _User32_func.TranslateMessage_
  824. #define GetWindowLongA     _User32_func.GetWindowLongA_
  825. #define AdjustWindowRectEx _User32_func.AdjustWindowRectEx_
  826. #define LoadCursorA        _User32_func.LoadCursorA_
  827. #define MapVirtualKeyA     _User32_func.MapVirtualKeyA_
  828. #define GetCursorPos       _User32_func.GetCursorPos_
  829. #define ScreenToClient     _User32_func.ScreenToClient_
  830.  
  831. union _User32_func_t {
  832.   FARPROC ptrs[1];
  833.  
  834.   struct {
  835.     ATOM    (WINAPI *RegisterClassA_)(CONST WNDCLASSA*);
  836.     HWND    (WINAPI *CreateWindowExA_)(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
  837.     LRESULT (WINAPI *DefWindowProcA_)(HWND, UINT, WPARAM, LPARAM);
  838.     WINBOOL (WINAPI *InvalidateRect_)(HWND, CONST RECT*, WINBOOL);
  839.     WINBOOL (WINAPI *UpdateWindow_)(HWND);
  840.     HDC     (WINAPI *BeginPaint_)(HWND, LPPAINTSTRUCT);
  841.     WINBOOL (WINAPI *EndPaint_)(HWND, CONST PAINTSTRUCT*);
  842.     WINBOOL (WINAPI *PeekMessageA_)(LPMSG, HWND, UINT, UINT, UINT);
  843.     LRESULT (WINAPI *DispatchMessageA_)(CONST MSG*);
  844.     WINBOOL (WINAPI *DestroyWindow_)(HWND);
  845.   //int     (WINAPI *ReleaseDC_)(HWND, HDC);
  846.   //HDC     (WINAPI *GetDC_)(HWND);
  847.     VOID    (WINAPI *PostQuitMessage_)(int);
  848.     int     (WINAPI *MessageBoxA_)(HWND, LPCSTR, LPCSTR, UINT);
  849.     WINBOOL (WINAPI *TranslateMessage_)(CONST MSG*);
  850.     LONG    (WINAPI *GetWindowLongA_)(HWND, int);
  851.     WINBOOL (WINAPI *AdjustWindowRectEx_)(LPRECT, DWORD, WINBOOL, DWORD);
  852.     HCURSOR (WINAPI *LoadCursorA_)(HINSTANCE, LPCSTR);
  853.     UINT    (WINAPI *MapVirtualKeyA_)(UINT, UINT);
  854.   //WINBOOL (WINAPI *GetCursorPos_)(LPPOINT);
  855.     WINBOOL (WINAPI *ScreenToClient_)(HWND, LPPOINT);
  856.   };
  857. };
  858.  
  859. extern _User32_func_t _User32_func;
  860. extern char           _User32_names_a[];
  861.  
  862.  
  863.  
  864. /******************************************************************************/
  865.  
  866.  
  867.  
  868. #define CreateCompatibleDC     _Gdi32_func.CreateCompatibleDC_
  869. #define CreateDIBSection       _Gdi32_func.CreateDIBSection_
  870. #define SelectObject           _Gdi32_func.SelectObject_
  871. #define DeleteObject           _Gdi32_func.DeleteObject_
  872. #define BitBlt                 _Gdi32_func.BitBlt_
  873. #define DeleteDC               _Gdi32_func.DeleteDC_
  874. #define StretchBlt             _Gdi32_func.StretchBlt_
  875. #define CreateCompatibleBitmap _Gdi32_func.CreateCompatibleBitmap_
  876. #define SetStretchBltMode      _Gdi32_func.SetStretchBltMode_
  877. #define SetDIBColorTable       _Gdi32_func.SetDIBColorTable_
  878.  
  879. union _Gdi32_func_t {
  880.   FARPROC ptrs[1];
  881.  
  882.   struct {
  883.     HDC     (WINAPI *CreateCompatibleDC_)(HDC);
  884.     HBITMAP (WINAPI *CreateDIBSection_)(HDC, CONST BITMAPINFO*, UINT, VOID**, HANDLE, DWORD);
  885.     HGDIOBJ (WINAPI *SelectObject_)(HDC, HGDIOBJ);
  886.     WINBOOL (WINAPI *DeleteObject_)(HGDIOBJ);
  887.   //WINBOOL (WINAPI *BitBlt_)(HDC, int, int, int, int, HDC, int, int, DWORD);
  888.     WINBOOL (WINAPI *DeleteDC_)(HDC);
  889.     WINBOOL (WINAPI *StretchBlt_)(HDC, int, int, int, int, HDC, int, int, int, int, DWORD);
  890.     HBITMAP (WINAPI *CreateCompatibleBitmap_)(HDC, int, int);
  891.     int     (WINAPI *SetStretchBltMode_)(HDC, int);
  892.     UINT    (WINAPI *SetDIBColorTable_)(HDC, UINT, UINT, CONST RGBQUAD*);
  893.   };
  894. };
  895.  
  896. extern _Gdi32_func_t _Gdi32_func;
  897. extern char          _Gdi32_names_a[];
  898.  
  899.  
  900.  
  901. /******************************************************************************/
  902.  
  903.  
  904.  
  905. int WindowInit(HINSTANCE hThisInst);
  906.  
  907. void WindowQuit();
  908.  
  909.  
  910.  
  911. #endif /* _WIN32_VIDEO_HPP */
  912. /******************************************************************************/
  913. /******************************************************************************/
  914. //"gdi_winmm_2025-03-28\src\win32\_WindowProc.hpp":
  915. #ifndef _WIN32__WINDOWPROC_HPP
  916. #define _WIN32__WINDOWPROC_HPP
  917.  
  918. #include <win32/video.hpp>
  919. #include <win32/input.hpp>
  920.  
  921. #include <windowsx.h>
  922.  
  923. #include <public_stuff.hpp>
  924.  
  925.  
  926.  
  927. //assumes window is without a menu
  928. static inline Point2d CalculateWindowSize(u32 innerWidth, u32 innerHeight,
  929.                                           u32 flags,      u32 flagsEx)
  930. {
  931.   RECT winSize;
  932.   winSize.left   = 0;
  933.   winSize.top    = 0;
  934.   winSize.right  = innerWidth;
  935.   winSize.bottom = innerHeight;
  936.   AdjustWindowRectEx(&winSize, flags, false, flagsEx);
  937.  
  938.   Point2d winSizeAdjusted;
  939.   winSizeAdjusted.x = winSize.right  - winSize.left;
  940.   winSizeAdjusted.y = winSize.bottom - winSize.top;
  941.   return winSizeAdjusted;
  942.  
  943. }
  944.  
  945.  
  946.  
  947. static inline Rect2d ConvertToKitRect(RECT& rectIn){
  948.   Rect2d rectOut;
  949.   rectOut.x = rectIn.left;
  950.   rectOut.y = rectIn.top;
  951.   rectOut.w = rectIn.right  - rectIn.left;
  952.   rectOut.h = rectIn.bottom - rectIn.top;
  953.  
  954.   return rectOut;
  955.  
  956. }
  957.  
  958.  
  959.  
  960. static inline RECT ConvertFromKitRect(Rect2d& rectIn){
  961.   RECT rectOut;
  962.   rectOut.left   = rectIn.x;
  963.   rectOut.top    = rectIn.y;
  964.   rectOut.right  = rectIn.x + rectIn.w;
  965.   rectOut.bottom = rectIn.y + rectIn.h;
  966.  
  967.   return rectOut;
  968.  
  969. }
  970.  
  971.  
  972.  
  973.  
  974.  
  975. union KEY_Params {
  976.   struct {
  977.     u32 repeatCount   : 16; // 0 -> 15
  978.     u32 scanCode      :  8; //16 -> 23
  979.     u32 extendedKey   :  1; //24
  980.     u32 _reserved     :  4; //25 -> 28
  981.     u32 altKeyDown    :  1; //29
  982.     u32 prevUnpressed :  1; //30
  983.     u32 currUnpressed :  1; //31
  984.   };
  985.  
  986.   u32 value;
  987.  
  988.   KEY_Params(u32 _value) : value(_value) {}
  989.  
  990. };
  991.  
  992.  
  993.  
  994. // This event handler is used for KEY_CHAR, KEY_UP, and KEY_DOWN events
  995. static inline void HANDLE_KEY_CHARUPDOWN(Event& event,
  996.                                          bool charEvent,u8 virtualKeyCode,
  997.                                          KEY_Params& params, u16 kmods)
  998. {
  999.   if(charEvent){
  1000.     event.type = EVENT_KEY_CHAR;
  1001.   } else {
  1002.     if(params.currUnpressed) event.type = EVENT_KEY_UP;
  1003.     else                     event.type = EVENT_KEY_DOWN;
  1004.   }
  1005.  
  1006.   event.key.kmods = kmods;
  1007.  
  1008.   event.key.pkey = params.scanCode;
  1009.   event.key.vkey = virtualKeyCode;
  1010.  
  1011.   event.key.pressed = !params.currUnpressed;
  1012.   event.key.repeat  = params.repeatCount>0; //modified to act as a boolean
  1013.   event.key.ischar  = charEvent;
  1014.  
  1015. }
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021. union MOUSE_ButtonStates {
  1022.   struct {
  1023.     u8 left    : 1;
  1024.     u8 middle  : 1;
  1025.     u8 right   : 1;
  1026.     u8 x1      : 1;
  1027.     u8 x2      : 1;
  1028.     u8 _unused : 3;
  1029.   };
  1030.  
  1031.   u8 value;
  1032.  
  1033.   MOUSE_ButtonStates() : value(0) {}
  1034.   MOUSE_ButtonStates(u8 _value) : value(_value) {}
  1035.  
  1036. };
  1037.  
  1038.  
  1039.  
  1040. extern Point2d win_size;
  1041.  
  1042. // Converts window coords to canvas coords
  1043. static inline void ConvertCoordinates(f32& x, f32& y){
  1044.   x = (x/(win_size.x-1.0f)) * ((f32)CANVAS_W-1.0f);
  1045.   y = (y/(win_size.y-1.0f)) * ((f32)CANVAS_H-1.0f);
  1046.  
  1047.   // Since canvas is bottom-up instead of top-down,
  1048.   // the y value is inverted!
  1049.   y = ((f32)CANVAS_H-1.0f) - y;
  1050.  
  1051. }
  1052.  
  1053.  
  1054.  
  1055. static inline void HANDLE_MOUSE_MOVED(Event& event, u8 buttonStates,
  1056.                                       Point2d& previous, Point2d& current)
  1057. {
  1058.   event.type = EVENT_MOUSE_MOVED;
  1059.  
  1060.   event.mouse.x = current.x;
  1061.   event.mouse.y = current.y;
  1062.   ConvertCoordinates(event.mouse.x, event.mouse.y);
  1063.  
  1064.   event.mouse.dx = current.x - previous.x;
  1065.   event.mouse.dy = current.y - previous.y;
  1066.   ConvertCoordinates(event.mouse.dx, event.mouse.dy);
  1067.  
  1068.   event.mouse.button  = buttonStates;
  1069.   event.mouse.pressed = buttonStates!=0;
  1070.  
  1071. }
  1072.  
  1073.  
  1074.  
  1075. // Same event handler is used for both MOUSE_HWHEEL and MOUSE_VWHEEL events
  1076. static inline void HANDLE_MOUSE_HVWHEEL(Event& event,
  1077.                                         bool verticalScroll, s16 scrollAmount,
  1078.                                         u8 buttonStates, Point2d& mousePos)
  1079. {
  1080.   if(verticalScroll){
  1081.     event.type = EVENT_MOUSE_VWHEEL;
  1082.     event.mouse.dy = (f32)scrollAmount/WHEEL_DELTA;
  1083.   } else {
  1084.     event.type = EVENT_MOUSE_HWHEEL;
  1085.     event.mouse.dx = (f32)scrollAmount/WHEEL_DELTA;
  1086.   }
  1087.  
  1088.   event.mouse.x = mousePos.x;
  1089.   event.mouse.y = mousePos.y;
  1090.   ConvertCoordinates(event.mouse.x, event.mouse.y);
  1091.  
  1092.   event.mouse.button  = buttonStates;
  1093.   event.mouse.pressed = buttonStates!=0;
  1094.  
  1095. }
  1096.  
  1097.  
  1098.  
  1099. // Same event handler is used for both MOUSE_UP and MOUSE_DOWN events
  1100. static inline void HANDLE_MOUSE_UPDOWN(Event& event, Point2d& clickPosition,
  1101.                                        u8 buttonStates, bool pressed, bool doubleClick)
  1102. {
  1103.   if(pressed) event.type = EVENT_MOUSE_DOWN;
  1104.   else        event.type = EVENT_MOUSE_UP;
  1105.  
  1106.   event.mouse.x = clickPosition.x;
  1107.   event.mouse.y = clickPosition.y;
  1108.   ConvertCoordinates(event.mouse.x, event.mouse.y);
  1109.  
  1110.   event.mouse.button   = buttonStates;
  1111.   event.mouse.pressed  = pressed;
  1112.   event.mouse.dblClick = doubleClick;
  1113.  
  1114. }
  1115.  
  1116.  
  1117.  
  1118. #endif /* _WIN32__WINDOWPROC_HPP */
  1119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement