Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"gdi_winmm_2025-03-28\include\public_stuff.hpp":
- #ifndef _PUBLIC_STUFF_HPP
- #define _PUBLIC_STUFF_HPP
- #include <stdio.h>
- // If you don't end up using anything else from stdio,
- // using this makes sure the function is only included in the debug build!
- #ifdef _DEBUG
- #define _printf(...) printf(__VA_ARGS__)
- #else
- #define _printf(...)
- #endif /* _DEBUG */
- #ifndef M_PI4f
- #define M_PI4f 0.7853981633974483096156608f
- #endif /* M_PI2 */
- #ifndef M_PI2f
- #define M_PI2f 1.5707963267948966192313216f
- #endif /* M_PI2 */
- #ifndef M_PIf
- #define M_PIf 3.1415926535897932384626433f
- #endif /* M_PIf */
- #ifndef M_2PIf
- #define M_2PIf 6.2831853071795864769252866f
- #endif /* M_2PIf */
- #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
- #define MAX(a,b) ( ((a)<(b)) ? (b) : (a) )
- #define CLAMP(v, mn, mx) MIN(MAX(v, mn), mx)
- #ifdef __cplusplus
- #include <cstddef>
- #include <cstdint>
- #else
- #include <stdint.h>
- #endif /* __cplusplus */
- typedef uint8_t u8;
- typedef uint16_t u16;
- typedef uint32_t u32;
- typedef uint64_t u64;
- typedef int8_t s8;
- typedef int16_t s16;
- typedef int32_t s32;
- typedef int64_t s64;
- typedef float f32;
- typedef double f64;
- /************************************ MISC ************************************/
- struct Fpoint2d { f32 x, y; };
- struct Point2d { s32 x, y; };
- struct Rect2d { s32 x, y, w, h; };
- // "std.cpp":
- void* memSet(void* dst, int val, size_t len);
- //(len_max does not include null-terminator!)
- //(if !len_max, call is analogous to str(not n)len)
- size_t strnLen(const char* str, size_t len_max);
- char* strnCpy(char* str_dst, const char* str_src, size_t len_max);
- char* strCat(char* dst, const char* src);
- //(len_max does not include null-terminator!)
- //(if !len_max, call is analogous to str(not n)cmp)
- s32 strnCmp(const char* str_a, const char* str_b, size_t len_max);
- f32 sinF(f32 x);
- #define cosF(_x) sinF((_x)+M_PI2f)
- #define tanF(_x) ( sinF(_x)/cosF(_x) )
- #if defined(_INC_STRING) || defined(_GLIBCXX_CSTRING)
- #define memSet memset
- #define strnLen strnlen
- #define strnCpy strncpy
- #define strCat strcat
- #define strnCmp strncmp
- #endif
- #if defined(_MATH_H_) || defined(_GLIBCXX_CMATH)
- #define sinF sinf
- #endif
- #if !defined(_INC_STDLIB) && !defined(_GLIBCXX_CSTDLIB) && !defined(_GLIBCXX_STDLIB_H)
- #include <win32/misc.hpp>
- #define malloc CoTaskMemAlloc
- #define realloc CoTaskMemRealloc
- #define free CoTaskMemFree
- #endif
- // "misc.cpp":
- enum MessageBoxEnum {
- // Return values
- MSGBOX_RTN_NULL = 0x00000000, //showMessageBox failed
- MSGBOX_RTN_OK = 0x00000001, //'ok' button was clicked
- MSGBOX_RTN_CANCEL = 0x00000002, //'cancel' button was clicked
- MSGBOX_RTN_ABORT = 0x00000003, //'abort' button was clicked
- MSGBOX_RTN_RETRY = 0x00000004, //'retry' button was clicked
- MSGBOX_RTN_IGNORE = 0x00000005, //'ignore' button was clicked
- MSGBOX_RTN_YES = 0x00000006, //'yes' button was clicked
- MSGBOX_RTN_NO = 0x00000007, //'no' button was clicked
- MSGBOX_RTN_TRYAGAIN = 0x0000000A, //'try again' button was clicked
- MSGBOX_RTN_CONTINUE = 0x0000000B, //'continue' button was clicked
- // Button types
- MSGBOX_BTN_OK = 0x00000000,
- MSGBOX_BTN_OKCANCEL = 0x00000001,
- MSGBOX_BTN_ABORTRETRYIGNORE = 0x00000002,
- MSGBOX_BTN_YESNOCANCEL = 0x00000003,
- MSGBOX_BTN_YESNO = 0x00000004,
- MSGBOX_BTN_RETRYCANCEL = 0x00000005,
- MSGBOX_BTN_CANCELTRYCONTINUE = 0x00000006,
- // Icon types
- MSGBOX_ICN_ERROR = 0x000000010,
- MSGBOX_ICN_QUESTION = 0x000000020, //apparently deprecated, but still supported
- MSGBOX_ICN_WARNING = 0x000000030,
- MSGBOX_ICN_INFO = 0x000000040,
- };
- u32 showMessageBox(const char* text = nullptr, const char* title = nullptr,
- u32 type = 0, u32 defaultButton = 0);
- u64 timeGetPerfCounter();
- u64 timeGetPerfFreq();
- f64 timeGetSeconds();
- void timeSleep(u32 milliseconds);
- /*********************************** INPUT ************************************/
- #define EVENT_ID(_id) ( (_id) & 0xFFFF0000 )
- #define SUBEVENT_ID(_id) ( (_id) & 0xFFFF )
- enum EventEnum {
- EVENT_NULL = 0x00000000,
- EVENT_COMMON = 0x00010000, // Event_Common (Event.common)
- // (Occurs when the window is destroyed!)
- EVENT_QUIT = 0x00020000, // N/A (N/A)
- EVENT_KEY = 0x00030000, // Event_Key (Event.key)
- EVENT_KEY_CHAR = EVENT_KEY | 0x0001,
- EVENT_KEY_UP = EVENT_KEY | 0x0002,
- EVENT_KEY_DOWN = EVENT_KEY | 0x0003,
- EVENT_MOUSE = 0x00040000, // Event_Mouse (Event.mouse)
- EVENT_MOUSE_MOVED = EVENT_MOUSE | 0x0001,
- EVENT_MOUSE_HWHEEL = EVENT_MOUSE | 0x0002,
- EVENT_MOUSE_VWHEEL = EVENT_MOUSE | 0x0003,
- EVENT_MOUSE_UP = EVENT_MOUSE | 0x0004,
- EVENT_MOUSE_DOWN = EVENT_MOUSE | 0x0005,
- };
- /*+EVENT_COMMON+*/
- struct Event_Common { //16B
- u32 type;
- u32 _unused; // Unused by common, but not necessarily other event types
- u64 timestamp; // Performance counter is used; see "timeGetPerfCounter()"
- };
- /*-EVENT_COMMON-*/
- /*+EVENT_KEY+*/
- // Event_Key.kmods can use any combination of these OR'd (AKA |) together
- enum Event_Key_ModifierEnum { // (These are bitmasks)
- KMOD_NONE = 0x0000,
- KMOD_LSHIFT = 0x0001,
- KMOD_RSHIFT = 0x0002,
- KMOD_LCTRL = 0x0004,
- KMOD_RCTRL = 0x0008,
- KMOD_LALT = 0x0010,
- KMOD_RALT = 0x0020,
- KMOD_LGUI = 0x0040, // Windows key?
- KMOD_RGUI = 0x0080, //^^
- KMOD_LWIN = KMOD_LGUI,
- KMOD_RWIN = KMOD_RGUI,
- KMOD_NUMLOCK = 0x1000,
- KMOD_CAPSLOCK = 0x2000,
- KMOD_ALTGRAPH = 0x4000,
- KMOD_SCROLLOCK = 0x8000,
- KMOD_CTRL = ( KMOD_LCTRL | KMOD_RCTRL ),
- KMOD_SHIFT = ( KMOD_LSHIFT | KMOD_RSHIFT ),
- KMOD_ALT = ( KMOD_LALT | KMOD_RALT ),
- KMOD_GUI = ( KMOD_LGUI | KMOD_RGUI ),
- KMOD_WIN = ( KMOD_LWIN | KMOD_RWIN ),
- };
- enum Event_Key_PhysicalEnum {
- // TBD because I don't want to bother with scancode stuff right now
- };
- enum Event_Key_VirtualEnum {
- //(misc. mouse) = 0x01 -> 0x06
- //(reserved) = 0x07,
- VKEY_BACK = 0x08, //backspace key
- VKEY_BACKSPACE = VKEY_BACK,
- VKEY_TAB = 0x09,
- //(reserved) = 0x0A -> 0x0B,
- VKEY_CLEAR = 0x0C,
- VKEY_RETURN = 0x0D, //enter key
- VKEY_ENTER = VKEY_RETURN,
- //(unassigned) = 0x0E -> 0x0F,
- VKEY_SHIFT = 0x10,
- VKEY_CONTROL = 0x11, //ctrl key
- VKEY_CTRL = VKEY_CONTROL,
- VKEY_MENU = 0x12, //alt key
- VKEY_ALT = VKEY_MENU,
- VKEY_PAUSE = 0x13,
- VKEY_CAPITAL = 0x14, //caps lock key
- VKEY_CAPSLOCK = VKEY_CAPITAL,
- //(IME stuff) = 0x15 -> 0x1A,
- VKEY_ESCAPE = 0x1B, //esc key
- //(IME stuff) = 0x1C -> 0x1F,
- VKEY_SPACE = 0x20, //space bar key
- VKEY_PRIOR = 0x21, //page up key
- VKEY_PGUP = VKEY_PRIOR,
- VKEY_NEXT = 0x22, //page down key
- VKEY_PGDN = VKEY_NEXT,
- VKEY_END = 0x23,
- VKEY_HOME = 0x24,
- VKEY_LEFT = 0x25, //left arrow key
- VKEY_UP = 0x26, //up arrow key
- VKEY_RIGHT = 0x27, //right arrow key
- VKEY_DOWN = 0x28, //down arrow key
- VKEY_SELECT = 0x29,
- VKEY_PRINT = 0x2A,
- VKEY_EXECUTE = 0x2B,
- VKEY_SNAPSHOT = 0x2C, //print screen key
- VKEY_PRTSC = VKEY_SNAPSHOT,
- VKEY_INSERT = 0x2D, //ins key
- VKEY_DELETE = 0x2E, //del key
- VKEY_HELP = 0x2F, //help key
- VKEY_0 = 0x30, //'0'
- VKEY_1 = 0x31, //'1'
- VKEY_2 = 0x32, //'2'
- VKEY_3 = 0x33, //'3'
- VKEY_4 = 0x34, //'4'
- VKEY_5 = 0x35, //'5'
- VKEY_6 = 0x36, //'6'
- VKEY_7 = 0x37, //'7'
- VKEY_8 = 0x38, //'8'
- VKEY_9 = 0x39, //'9'
- //(undefined) = 0x3A -> 0x40,
- VKEY_A = 0x41, //'A'
- VKEY_B = 0x42, //'B'
- VKEY_C = 0x43, //'C'
- VKEY_D = 0x44, //'D'
- VKEY_E = 0x45, //'E'
- VKEY_F = 0x46, //'F'
- VKEY_G = 0x47, //'G'
- VKEY_H = 0x48, //'H'
- VKEY_I = 0x49, //'I'
- VKEY_J = 0x4A, //'J'
- VKEY_K = 0x4B, //'K'
- VKEY_L = 0x4C, //'L'
- VKEY_M = 0x4D, //'M'
- VKEY_N = 0x4E, //'N'
- VKEY_O = 0x4F, //'O'
- VKEY_P = 0x50, //'P'
- VKEY_Q = 0x51, //'Q'
- VKEY_R = 0x52, //'R'
- VKEY_S = 0x53, //'S'
- VKEY_T = 0x54, //'T'
- VKEY_U = 0x55, //'U'
- VKEY_V = 0x56, //'V'
- VKEY_W = 0x57, //'W'
- VKEY_X = 0x58, //'X'
- VKEY_Y = 0x59, //'Y'
- VKEY_Z = 0x5A, //'Z'
- VKEY_LWIN = 0x5B, //left windows key
- VKEY_RWIN = 0x5C, //right windows key
- VKEY_APPS = 0x5D, //applications key
- //(reserved) = 0x5E,
- VKEY_SLEEP = 0x5F, //computer sleep key
- VKEY_NUMPAD0 = 0x60,
- VKEY_NUMPAD1 = 0x61,
- VKEY_NUMPAD2 = 0x62,
- VKEY_NUMPAD3 = 0x63,
- VKEY_NUMPAD4 = 0x64,
- VKEY_NUMPAD5 = 0x65,
- VKEY_NUMPAD6 = 0x66,
- VKEY_NUMPAD7 = 0x67,
- VKEY_NUMPAD8 = 0x68,
- VKEY_NUMPAD9 = 0x69,
- VKEY_MULTIPLY = 0x6A, //numpad '*'
- VKEY_ADD = 0x6B, //numpad '+'
- VKEY_SEPARATOR = 0x6C, //numpad enter
- VKEY_SUBTRACT = 0x6D, //numpad '-'
- VKEY_DECIMAL = 0x6E, //numpad '.'
- VKEY_DIVIDE = 0x6F, //numpad '/'
- VKEY_F1 = 0x70,
- VKEY_F2 = 0x71,
- VKEY_F3 = 0x72,
- VKEY_F4 = 0x73,
- VKEY_F5 = 0x74,
- VKEY_F6 = 0x75,
- VKEY_F7 = 0x76,
- VKEY_F8 = 0x77,
- VKEY_F9 = 0x78,
- VKEY_F10 = 0x79,
- VKEY_F11 = 0x7A,
- VKEY_F12 = 0x7B,
- VKEY_F13 = 0x7C,
- VKEY_F14 = 0x7D,
- VKEY_F15 = 0x7E,
- VKEY_F16 = 0x7F,
- VKEY_F17 = 0x80,
- VKEY_F18 = 0x81,
- VKEY_F19 = 0x82,
- VKEY_F20 = 0x83,
- VKEY_F21 = 0x84,
- VKEY_F22 = 0x85,
- VKEY_F23 = 0x86,
- VKEY_F24 = 0x87,
- //(reserved) = 0x88 -> 0x8F,
- VKEY_NUMLOCK = 0x90,
- VKEY_SCROLL = 0x91, //scroll lock key
- VKEY_SCROLLOCK = VKEY_SCROLL,
- //(OEM-specific) = 0x92 -> 0x96,
- //(unassigned) = 0x97 -> 0x9F,
- //(l/r key variants) = 0xA0 -> 0xA5,
- //(browser keys) = 0xA6 -> 0xAC,
- VKEY_VOLUME_MUTE = 0xAD,
- VKEY_VOLUME_DOWN = 0xAE,
- VKEY_VOLUME_UP = 0xAF,
- VKEY_MEDIA_NEXT_TRACK = 0xB0,
- VKEY_MEDIA_PREV_TRACK = 0xB1,
- VKEY_MEDIA_STOP = 0xB2,
- VKEY_MEDIA_PLAY_PAUSE = 0xB3, //Play/Pause Media key
- //(launch keys) = 0xB4 -> 0xB7,
- //(reserved) = 0xB8 -> 0xB9,
- VKEY_OEM_1 = 0xBA, //misc. chars; varies by keyboard (';',':' on US standard)
- VKEY_SEMICOLON = VKEY_OEM_1,
- VKEY_OEM_PLUS = 0xBB, //'+' in any country/region
- VKEY_PLUS = VKEY_OEM_PLUS,
- VKEY_OEM_COMMA = 0xBC, //',' in any country/region
- VKEY_COMMA = VKEY_OEM_COMMA,
- VKEY_OEM_MINUS = 0xBD, //'-' in any country/region
- VKEY_MINUS = VKEY_OEM_MINUS,
- VKEY_OEM_PERIOD = 0xBE, //'.' in any country/region
- VKEY_PERIOD = VKEY_OEM_PERIOD,
- VKEY_OEM_2 = 0xBF, //misc. chars; varies by keyboard ('/','?' on US standard)
- VKEY_FSLASH = VKEY_OEM_2,
- VKEY_OEM_3 = 0xC0, //misc. chars; varies by keyboard ('`','~' on US standard)
- VKEY_BACKTICK = VKEY_OEM_3,
- //(reserved) = 0xC1 -> 0xDA,
- VKEY_OEM_4 = 0xDB, //misc. chars; varies by keyboard ('[','{' on US standard)
- VKEY_LBRACKET = VKEY_OEM_4,
- VKEY_OEM_5 = 0xDC, //misc. chars; varies by keyboard ('\\','|' on US standard)
- VKEY_BSLASH = VKEY_OEM_5,
- VKEY_OEM_6 = 0xDD, //misc. chars; varies by keyboard (']','}' on US standard)
- VKEY_RBRACKET = VKEY_OEM_6,
- VKEY_OEM_7 = 0xDE, //misc. chars; varies by keyboard ('\'','\"' on US standard)
- VKEY_APOSTROPHE = VKEY_OEM_7,
- VKEY_OEM_8 = 0xDF, //misc. chars; varies by keyboard
- //(reserved) = 0xE0,
- //(misc.) = 0xE1 -> 0xE7,
- //(unassigned) = 0xE8,
- //(misc.) = 0xE9 -> 0xFE,
- };
- // Mod[ifier]
- union Event_Key_Mod { //2B
- // IMPORTANT:
- // Due to me having terminal couldn't-care-less syndrome,
- // I haven't implemented differenciating between the
- // left and right variants of shift, control, et cetera,
- // so both variants are set/unset when either are pressed/unpressed.
- // (Except lgui and rgui, since that's easier to detect???)
- // (ALSO ALTGRAPH ISN'T IMPLEMENTED AT ALL THANKS MICROSOFT)
- struct {
- u16 lshift : 1;
- u16 rshift : 1;
- u16 lctrl : 1;
- u16 rctrl : 1;
- u16 lalt : 1;
- u16 ralt : 1;
- u16 lgui : 1;
- u16 rgui : 1;
- u16 _unused : 4;
- u16 numlock : 1;
- u16 capslock : 1;
- u16 altgraph : 1;
- u16 scrollock : 1;
- };
- u16 all;
- };
- // Short for Key Symbol
- struct Event_Key_Sym { //8B
- union {
- Event_Key_Mod kmod;
- u16 kmods;
- };
- u8 _unused;
- u8 pkey; // Physical key code (named .scancode in SDL's Keysym struct)
- u8 vkey; // Virtual key code (named .sym in SDL's Keysym struct)
- bool pressed;
- bool ischar; // 'is event KEY_CHAR?', otherwise it's KEY_UP or KEY_DOWN
- bool repeat; // Y'know that thing where in a text editor you hold down a key?
- };
- struct Event_Key { //24B
- u32 type;
- u32 _unused_0;
- u64 timestamp; // Performance counter is used; see "timeGetPerfCounter()"
- union {
- struct { // (Effectively a copy of Event_Key_Sym)
- u16 kmods;
- u8 _unused_1;
- u8 pkey;
- u8 vkey;
- bool pressed;
- bool ischar;
- bool repeat;
- };
- Event_Key_Sym sym;
- };
- };
- /*-EVENT_KEY-*/
- /*+EVENT_MOUSE+*/
- // Event_Mouse.button can use any combination of these OR'd (AKA |) together
- enum Event_Mouse_ButtonEnum { // (These are bitmasks)
- MBUTTON_LEFT = 0x01,
- MBUTTON_MIDDLE = 0x02,
- MBUTTON_RIGHT = 0x04,
- MBUTTON_X1 = 0x08, // Those 2 buttons on the sides of most mice nowadays
- MBUTTON_X2 = 0x10, //^^
- };
- // (EVENT_MOUSE_<H/V>WHEEL events use dx and dy!)
- struct Event_Mouse { //32B
- u32 type;
- u8 _unused;
- u8 button; // Flags for currently pressed buttons (Event_Mouse_ButtonEnum)
- bool pressed; // Will be true if button is nonzero
- bool dblClick; // 'Is double click?'
- u64 timestamp;
- f32 x; // Coordinates relative to window
- f32 y; //^^
- f32 dx; // Delta x (coordinates relative to last recorded x position)
- f32 dy; // Delta y (coordinates relative to last recorded y position)
- };
- /*-EVENT_MOUSE-*/
- union Event { //32B (assuming Event_Mouse is the largest event bytes-wise)
- u32 type;
- Event_Common common;
- Event_Key key;
- Event_Mouse mouse;
- };
- // Populates *event_p with the contents of the first event in the event queue.
- // Returns false if there were no events left in queue; true otherwise.
- // (Calling this exclusively in the main thread is recommended)
- bool pollEvent(Event* event_p = nullptr); // Burns events if event_p is nullptr
- /*********************************** AUDIO ************************************/
- // Stereo audio samples as two 32-bit floats,
- // where each of the two channels can be between -1.0 to 1.0
- struct StereoF32 { f32 l,r; };
- // The length of the audio stream's buffer, in samples
- extern u32 audio_samples;
- // The audio's sample rate, in hertz
- extern u32 sample_rate;
- /*********************************** VIDEO ************************************/
- #define WINDOW_NAME "GDI Playground"
- // If left at 4, window will initially appear 4x as big as canvas
- #define WINDOW_RESMUL 4
- // Technically customizable, but keeping it at 256x144 makes it 16:9,
- // while also taking advantage of the fact an x position can just be
- // stored within a single byte. This's useful for several types of optimizations
- #define CANVAS_W 256
- #define CANVAS_H 144
- // This assumes the canvas width is equal to 256
- union PixelCoords {
- u16 v; // Full index
- struct { u8 x, y; };
- PixelCoords() : v(0) {}
- PixelCoords(u16 _v) : v(_v) {}
- PixelCoords(u8 _x, u8 _y) : x(_x), y(_y) {}
- };
- // Used for the pixel buffer. This corresponds to the 8-bit color palette
- // initially set during initialization. However, this palette can be
- // changed by setting entries in pixels_palette and calling update_palette()
- union Color8 {
- u8 v; // Full pixel value
- struct {
- u8 r : 3;
- u8 g : 3;
- u8 b : 2;
- };
- Color8() : v(0) {}
- Color8(u8 _v) : v(_v) {}
- };
- // Used for setting pixels_palette.
- // (Make sure to call update_palette() to apply any changes to the palette!)
- union Color24 {
- u32 v; // Full pixel value
- struct {
- u8 r;
- u8 g;
- u8 b;
- u8 _; // (Unused; this is just padding to the nearest multiple of 32-bits)
- };
- };
- extern Color8* pixels;
- extern Color24* pixels_palette;
- extern bool win_closed;
- void canvas_present(bool immediate = true);
- void close_window(); // Also triggers an EVENT_QUIT
- // Updates the 256-color palette. It defaults to the built-in one,
- // but not only can you edit the built-in palette, you can make this
- // function use another palette, just in case you want to swap out
- // entirely different palettes on the fly!
- //
- // Does nothing if new_palette is given as NULL.
- // This also makes sure that no color beyond the 255th is changed.
- // For example, if first_color is 255, and num_colors is 2,
- // only a single color will be changed, since 255 is the last color index
- //
- // Returns true on success, false otherwise
- bool update_palette(const Color24* new_palette = pixels_palette,
- u32 first_color = 0, u32 num_colors = 256);
- #endif /* _PUBLIC_STUFF_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"gdi_winmm_2025-03-28\include\win32\audio.hpp":
- #ifndef _WIN32_AUDIO_HPP
- #define _WIN32_AUDIO_HPP
- #include <public_stuff.hpp>
- #include <windows.h>
- #include <mmsystem.h>
- #define waveOutGetNumDevs _Winmm_func.waveOutGetNumDevs_
- #define waveOutGetDevCapsA _Winmm_func.waveOutGetDevCapsA_
- #define waveOutGetVolume _Winmm_func.waveOutGetVolume_
- #define waveOutSetVolume _Winmm_func.waveOutSetVolume_
- #define waveOutGetErrorTextA _Winmm_func.waveOutGetErrorTextA_
- #define waveOutOpen _Winmm_func.waveOutOpen_
- #define waveOutClose _Winmm_func.waveOutClose_
- #define waveOutPrepareHeader _Winmm_func.waveOutPrepareHeader_
- #define waveOutUnprepareHeader _Winmm_func.waveOutUnprepareHeader_
- #define waveOutWrite _Winmm_func.waveOutWrite_
- #define waveOutPause _Winmm_func.waveOutPause_
- #define waveOutRestart _Winmm_func.waveOutRestart_
- #define waveOutReset _Winmm_func.waveOutReset_
- #define waveOutBreakLoop _Winmm_func.waveOutBreakLoop_
- #define waveOutGetPosition _Winmm_func.waveOutGetPosition_
- #define waveOutGetPitch _Winmm_func.waveOutGetPitch_
- #define waveOutSetPitch _Winmm_func.waveOutSetPitch_
- #define waveOutGetPlaybackRate _Winmm_func.waveOutGetPlaybackRate_
- #define waveOutSetPlaybackRate _Winmm_func.waveOutSetPlaybackRate_
- #define waveOutGetID _Winmm_func.waveOutGetID_
- #define waveOutMessage _Winmm_func.waveOutMessage_
- union _Winmm_func_t {
- FARPROC ptrs[1];
- struct {
- //UINT (WINAPI *waveOutGetNumDevs_)(void);
- MMRESULT (WINAPI *waveOutGetDevCapsA_)(UINT_PTR, LPWAVEOUTCAPSA, UINT);
- //MMRESULT (WINAPI *waveOutGetVolume_)(HWAVEOUT, LPDWORD);
- MMRESULT (WINAPI *waveOutSetVolume_)(HWAVEOUT, DWORD);
- //MMRESULT (WINAPI *waveOutGetErrorTextA_)(MMRESULT, LPSTR, UINT);
- MMRESULT (WINAPI *waveOutOpen_)(LPHWAVEOUT, UINT, LPCWAVEFORMATEX, DWORD_PTR, DWORD_PTR, DWORD);
- //MMRESULT (WINAPI *waveOutClose_)(HWAVEOUT);
- MMRESULT (WINAPI *waveOutPrepareHeader_)(HWAVEOUT, LPWAVEHDR, UINT);
- //MMRESULT (WINAPI *waveOutUnprepareHeader_)(HWAVEOUT, LPWAVEHDR, UINT);
- MMRESULT (WINAPI *waveOutWrite_)(HWAVEOUT, LPWAVEHDR, UINT);
- MMRESULT (WINAPI *waveOutPause_)(HWAVEOUT);
- //MMRESULT (WINAPI *waveOutRestart_)(HWAVEOUT);
- //MMRESULT (WINAPI *waveOutReset_)(HWAVEOUT);
- //MMRESULT (WINAPI *waveOutBreakLoop_)(HWAVEOUT);
- //MMRESULT (WINAPI *waveOutGetPosition_)(HWAVEOUT, LPMMTIME, UINT);
- //MMRESULT (WINAPI *waveOutGetPitch_)(HWAVEOUT, LPDWORD);
- //MMRESULT (WINAPI *waveOutSetPitch_)(HWAVEOUT, DWORD);
- //MMRESULT (WINAPI *waveOutGetPlaybackRate_)(HWAVEOUT, LPDWORD);
- //MMRESULT (WINAPI *waveOutSetPlaybackRate_)(HWAVEOUT, DWORD);
- //MMRESULT (WINAPI *waveOutGetID_)(HWAVEOUT, LPUINT);
- //MMRESULT (WINAPI *waveOutMessage_)(HWAVEOUT, UINT, DWORD_PTR, DWORD_PTR);
- };
- };
- extern _Winmm_func_t _Winmm_func;
- extern char _Winmm_names[];
- /******************************************************************************/
- // Stereo audio samples as two 16-bit signed ints
- struct StereoS16 { s16 l,r; };
- int WaveOutInit();
- void WaveOutQuit();
- #endif /* _WIN32_AUDIO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"gdi_winmm_2025-03-28\include\win32\input.hpp":
- #ifndef _WIN32_INPUT_HPP
- #define _WIN32_INPUT_HPP
- #include <windows.h>
- #include <public_stuff.hpp>
- int InputInit();
- void InputQuit();
- union Event; // Forward declaration
- // Returns false if queue is full
- bool AddToEventQueue(Event& event);
- // Returns a EVENT_NULL event if queue is empty
- Event RemoveFromEventQueue();
- #endif /* _WIN32_INPUT_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"gdi_winmm_2025-03-28\include\win32\misc.hpp":
- #ifndef _WIN32_MISC_HPP
- #define _WIN32_MISC_HPP
- //#include <windows.h>
- #include <combaseapi.h>
- #define CoTaskMemAlloc _Ole32_func.CoTaskMemAlloc_
- #define CoTaskMemRealloc _Ole32_func.CoTaskMemRealloc_
- #define CoTaskMemFree _Ole32_func.CoTaskMemFree_
- union _Ole32_func_t {
- FARPROC ptrs[3];
- struct {
- LPVOID (*CoTaskMemAlloc_) (SIZE_T);
- LPVOID (*CoTaskMemRealloc_) (LPVOID, SIZE_T);
- void (*CoTaskMemFree_) (LPVOID);
- };
- };
- extern _Ole32_func_t _Ole32_func;
- extern char _Ole32_names[];
- #define CRITICAL_SECTION_SPINCOUNT 2048
- #endif /* _WIN32_MISC_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"gdi_winmm_2025-03-28\include\win32\video.hpp":
- #ifndef _WIN32_VIDEO_HPP
- #define _WIN32_VIDEO_HPP
- #include <windows.h>
- #define RegisterClassA _User32_func.RegisterClassA_
- #define CreateWindowExA _User32_func.CreateWindowExA_
- #define DefWindowProcA _User32_func.DefWindowProcA_
- #define InvalidateRect _User32_func.InvalidateRect_
- #define UpdateWindow _User32_func.UpdateWindow_
- #define BeginPaint _User32_func.BeginPaint_
- #define EndPaint _User32_func.EndPaint_
- #define PeekMessageA _User32_func.PeekMessageA_
- #define DispatchMessageA _User32_func.DispatchMessageA_
- #define DestroyWindow _User32_func.DestroyWindow_
- #define ReleaseDC _User32_func.ReleaseDC_
- #define GetDC _User32_func.GetDC_
- #define PostQuitMessage _User32_func.PostQuitMessage_
- #define MessageBoxA _User32_func.MessageBoxA_
- #define TranslateMessage _User32_func.TranslateMessage_
- #define GetWindowLongA _User32_func.GetWindowLongA_
- #define AdjustWindowRectEx _User32_func.AdjustWindowRectEx_
- #define LoadCursorA _User32_func.LoadCursorA_
- #define MapVirtualKeyA _User32_func.MapVirtualKeyA_
- #define GetCursorPos _User32_func.GetCursorPos_
- #define ScreenToClient _User32_func.ScreenToClient_
- union _User32_func_t {
- FARPROC ptrs[1];
- struct {
- ATOM (WINAPI *RegisterClassA_)(CONST WNDCLASSA*);
- HWND (WINAPI *CreateWindowExA_)(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
- LRESULT (WINAPI *DefWindowProcA_)(HWND, UINT, WPARAM, LPARAM);
- WINBOOL (WINAPI *InvalidateRect_)(HWND, CONST RECT*, WINBOOL);
- WINBOOL (WINAPI *UpdateWindow_)(HWND);
- HDC (WINAPI *BeginPaint_)(HWND, LPPAINTSTRUCT);
- WINBOOL (WINAPI *EndPaint_)(HWND, CONST PAINTSTRUCT*);
- WINBOOL (WINAPI *PeekMessageA_)(LPMSG, HWND, UINT, UINT, UINT);
- LRESULT (WINAPI *DispatchMessageA_)(CONST MSG*);
- WINBOOL (WINAPI *DestroyWindow_)(HWND);
- //int (WINAPI *ReleaseDC_)(HWND, HDC);
- //HDC (WINAPI *GetDC_)(HWND);
- VOID (WINAPI *PostQuitMessage_)(int);
- int (WINAPI *MessageBoxA_)(HWND, LPCSTR, LPCSTR, UINT);
- WINBOOL (WINAPI *TranslateMessage_)(CONST MSG*);
- LONG (WINAPI *GetWindowLongA_)(HWND, int);
- WINBOOL (WINAPI *AdjustWindowRectEx_)(LPRECT, DWORD, WINBOOL, DWORD);
- HCURSOR (WINAPI *LoadCursorA_)(HINSTANCE, LPCSTR);
- UINT (WINAPI *MapVirtualKeyA_)(UINT, UINT);
- //WINBOOL (WINAPI *GetCursorPos_)(LPPOINT);
- WINBOOL (WINAPI *ScreenToClient_)(HWND, LPPOINT);
- };
- };
- extern _User32_func_t _User32_func;
- extern char _User32_names_a[];
- /******************************************************************************/
- #define CreateCompatibleDC _Gdi32_func.CreateCompatibleDC_
- #define CreateDIBSection _Gdi32_func.CreateDIBSection_
- #define SelectObject _Gdi32_func.SelectObject_
- #define DeleteObject _Gdi32_func.DeleteObject_
- #define BitBlt _Gdi32_func.BitBlt_
- #define DeleteDC _Gdi32_func.DeleteDC_
- #define StretchBlt _Gdi32_func.StretchBlt_
- #define CreateCompatibleBitmap _Gdi32_func.CreateCompatibleBitmap_
- #define SetStretchBltMode _Gdi32_func.SetStretchBltMode_
- #define SetDIBColorTable _Gdi32_func.SetDIBColorTable_
- union _Gdi32_func_t {
- FARPROC ptrs[1];
- struct {
- HDC (WINAPI *CreateCompatibleDC_)(HDC);
- HBITMAP (WINAPI *CreateDIBSection_)(HDC, CONST BITMAPINFO*, UINT, VOID**, HANDLE, DWORD);
- HGDIOBJ (WINAPI *SelectObject_)(HDC, HGDIOBJ);
- WINBOOL (WINAPI *DeleteObject_)(HGDIOBJ);
- //WINBOOL (WINAPI *BitBlt_)(HDC, int, int, int, int, HDC, int, int, DWORD);
- WINBOOL (WINAPI *DeleteDC_)(HDC);
- WINBOOL (WINAPI *StretchBlt_)(HDC, int, int, int, int, HDC, int, int, int, int, DWORD);
- HBITMAP (WINAPI *CreateCompatibleBitmap_)(HDC, int, int);
- int (WINAPI *SetStretchBltMode_)(HDC, int);
- UINT (WINAPI *SetDIBColorTable_)(HDC, UINT, UINT, CONST RGBQUAD*);
- };
- };
- extern _Gdi32_func_t _Gdi32_func;
- extern char _Gdi32_names_a[];
- /******************************************************************************/
- int WindowInit(HINSTANCE hThisInst);
- void WindowQuit();
- #endif /* _WIN32_VIDEO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"gdi_winmm_2025-03-28\src\win32\_WindowProc.hpp":
- #ifndef _WIN32__WINDOWPROC_HPP
- #define _WIN32__WINDOWPROC_HPP
- #include <win32/video.hpp>
- #include <win32/input.hpp>
- #include <windowsx.h>
- #include <public_stuff.hpp>
- //assumes window is without a menu
- static inline Point2d CalculateWindowSize(u32 innerWidth, u32 innerHeight,
- u32 flags, u32 flagsEx)
- {
- RECT winSize;
- winSize.left = 0;
- winSize.top = 0;
- winSize.right = innerWidth;
- winSize.bottom = innerHeight;
- AdjustWindowRectEx(&winSize, flags, false, flagsEx);
- Point2d winSizeAdjusted;
- winSizeAdjusted.x = winSize.right - winSize.left;
- winSizeAdjusted.y = winSize.bottom - winSize.top;
- return winSizeAdjusted;
- }
- static inline Rect2d ConvertToKitRect(RECT& rectIn){
- Rect2d rectOut;
- rectOut.x = rectIn.left;
- rectOut.y = rectIn.top;
- rectOut.w = rectIn.right - rectIn.left;
- rectOut.h = rectIn.bottom - rectIn.top;
- return rectOut;
- }
- static inline RECT ConvertFromKitRect(Rect2d& rectIn){
- RECT rectOut;
- rectOut.left = rectIn.x;
- rectOut.top = rectIn.y;
- rectOut.right = rectIn.x + rectIn.w;
- rectOut.bottom = rectIn.y + rectIn.h;
- return rectOut;
- }
- union KEY_Params {
- struct {
- u32 repeatCount : 16; // 0 -> 15
- u32 scanCode : 8; //16 -> 23
- u32 extendedKey : 1; //24
- u32 _reserved : 4; //25 -> 28
- u32 altKeyDown : 1; //29
- u32 prevUnpressed : 1; //30
- u32 currUnpressed : 1; //31
- };
- u32 value;
- KEY_Params(u32 _value) : value(_value) {}
- };
- // This event handler is used for KEY_CHAR, KEY_UP, and KEY_DOWN events
- static inline void HANDLE_KEY_CHARUPDOWN(Event& event,
- bool charEvent,u8 virtualKeyCode,
- KEY_Params& params, u16 kmods)
- {
- if(charEvent){
- event.type = EVENT_KEY_CHAR;
- } else {
- if(params.currUnpressed) event.type = EVENT_KEY_UP;
- else event.type = EVENT_KEY_DOWN;
- }
- event.key.kmods = kmods;
- event.key.pkey = params.scanCode;
- event.key.vkey = virtualKeyCode;
- event.key.pressed = !params.currUnpressed;
- event.key.repeat = params.repeatCount>0; //modified to act as a boolean
- event.key.ischar = charEvent;
- }
- union MOUSE_ButtonStates {
- struct {
- u8 left : 1;
- u8 middle : 1;
- u8 right : 1;
- u8 x1 : 1;
- u8 x2 : 1;
- u8 _unused : 3;
- };
- u8 value;
- MOUSE_ButtonStates() : value(0) {}
- MOUSE_ButtonStates(u8 _value) : value(_value) {}
- };
- extern Point2d win_size;
- // Converts window coords to canvas coords
- static inline void ConvertCoordinates(f32& x, f32& y){
- x = (x/(win_size.x-1.0f)) * ((f32)CANVAS_W-1.0f);
- y = (y/(win_size.y-1.0f)) * ((f32)CANVAS_H-1.0f);
- // Since canvas is bottom-up instead of top-down,
- // the y value is inverted!
- y = ((f32)CANVAS_H-1.0f) - y;
- }
- static inline void HANDLE_MOUSE_MOVED(Event& event, u8 buttonStates,
- Point2d& previous, Point2d& current)
- {
- event.type = EVENT_MOUSE_MOVED;
- event.mouse.x = current.x;
- event.mouse.y = current.y;
- ConvertCoordinates(event.mouse.x, event.mouse.y);
- event.mouse.dx = current.x - previous.x;
- event.mouse.dy = current.y - previous.y;
- ConvertCoordinates(event.mouse.dx, event.mouse.dy);
- event.mouse.button = buttonStates;
- event.mouse.pressed = buttonStates!=0;
- }
- // Same event handler is used for both MOUSE_HWHEEL and MOUSE_VWHEEL events
- static inline void HANDLE_MOUSE_HVWHEEL(Event& event,
- bool verticalScroll, s16 scrollAmount,
- u8 buttonStates, Point2d& mousePos)
- {
- if(verticalScroll){
- event.type = EVENT_MOUSE_VWHEEL;
- event.mouse.dy = (f32)scrollAmount/WHEEL_DELTA;
- } else {
- event.type = EVENT_MOUSE_HWHEEL;
- event.mouse.dx = (f32)scrollAmount/WHEEL_DELTA;
- }
- event.mouse.x = mousePos.x;
- event.mouse.y = mousePos.y;
- ConvertCoordinates(event.mouse.x, event.mouse.y);
- event.mouse.button = buttonStates;
- event.mouse.pressed = buttonStates!=0;
- }
- // Same event handler is used for both MOUSE_UP and MOUSE_DOWN events
- static inline void HANDLE_MOUSE_UPDOWN(Event& event, Point2d& clickPosition,
- u8 buttonStates, bool pressed, bool doubleClick)
- {
- if(pressed) event.type = EVENT_MOUSE_DOWN;
- else event.type = EVENT_MOUSE_UP;
- event.mouse.x = clickPosition.x;
- event.mouse.y = clickPosition.y;
- ConvertCoordinates(event.mouse.x, event.mouse.y);
- event.mouse.button = buttonStates;
- event.mouse.pressed = pressed;
- event.mouse.dblClick = doubleClick;
- }
- #endif /* _WIN32__WINDOWPROC_HPP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement