Kitomas

work for 2025-04-25 (4/5)

Apr 25th, 2025
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 36.00 KB | None | 0 0
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. //"gdi_maze_game_2025-04-25\include\public_stuff.hpp":
  4. #ifndef _PUBLIC_STUFF_HPP
  5. #define _PUBLIC_STUFF_HPP
  6.  
  7.  
  8.  
  9.  
  10.  
  11. // Comment out any misc. functions you don't plan on using
  12. //#define PRINT_EVENT_USED
  13. #define FRAND_USED // (Includes all types of frand)
  14.  
  15. // Comment out any draw functions you don't plan on using
  16. #define UNPACK_FONT_USED
  17. #define DRAW_TEXT_USED
  18. #define _DRAW_TEXTF_USED // Formatted text variant (implies DRAW_TEXT_USED)
  19. #define BLIT_USED
  20. #define DRAW_LINE_USED
  21. #define DRAW_RECT_USED
  22. #define FILL_RECT_USED
  23. #define DRAW_VSLICE_USED
  24.  
  25. #define FONT_PICO8_USED // (Implies UNPACK_FONT_USED)
  26.  
  27. #define SOUND_STUFF_USED // 'Use the built-in sound effect mixer?'
  28.  
  29.  
  30.  
  31.  
  32.  
  33. // Comment this line out if you don't plan on using stdlib's implementations of:
  34. // memset
  35. // memcpy
  36. // strnlen
  37. // strncpy
  38. // strcat
  39. // strncmp
  40. #define STDLIB_USED
  41.  
  42. #if defined(FRAND_USED) && !defined(STDLIB_USED)
  43.   #define STDLIB_USED
  44. #endif
  45.  
  46. #if defined(FONT_PICO8_USED) && !defined(UNPACK_FONT_USED)
  47.   #define UNPACK_FONT_USED
  48. #endif
  49.  
  50. #if defined(_DRAW_TEXTF_USED) && !defined(DRAW_TEXT_USED)
  51.   #define DRAW_TEXT_USED
  52. #endif
  53.  
  54.  
  55.  
  56. #ifdef STDLIB_USED
  57.   #include <string.h>
  58.   #include <math.h>
  59.   // The framework uses its own implementations for the following stdlib
  60.   // functions so that it doesn't require the C runtime libraries.
  61.   // However, if the user plans on using the standard library for their
  62.   // own purposes, having custom implementations would be redundant
  63.   #define memSet  memset
  64.   #define memCpy  memcpy
  65.   #define strnLen strnlen
  66.   #define strnCpy strncpy
  67.   #define strCat  strcat
  68.   #define strnCmp strncmp
  69.   // (sinF is only used for the example audio usage,
  70.   //  and that's commented out at first anyway!)
  71.   #define sinF    sinf
  72. #endif /* STDLIB_USED */
  73.  
  74.  
  75.  
  76. // If you don't end up using anything else from stdio,
  77. // using this makes sure printf is only included in the debug build!
  78. // This is useful for minimizing size, since the command line is
  79. // only shown in the debug build anyway.
  80. #ifdef _DEBUG
  81.   #include <stdio.h>
  82.   #define _printf(...) printf(__VA_ARGS__)
  83. #else
  84.   #define _printf(...)
  85. #endif /* _DEBUG */
  86.  
  87.  
  88.  
  89.  
  90.  
  91. // Float-specified versions of math.h's pi constants,
  92. // with a slightly different naming convention
  93.  
  94. #ifndef   M_PI4f
  95. #define   M_PI4f 0.7853981633974483096156608f
  96. #endif /* M_PI2 */
  97.  
  98. #ifndef   M_PI2f
  99. #define   M_PI2f 1.5707963267948966192313216f
  100. #endif /* M_PI2 */
  101.  
  102. #ifndef   M_PIf
  103. #define   M_PIf  3.1415926535897932384626433f
  104. #endif /* M_PIf */
  105.  
  106. #ifndef   M_2PIf
  107. #define   M_2PIf 6.2831853071795864769252866f
  108. #endif /* M_2PIf */
  109.  
  110.  
  111.  
  112.  
  113.  
  114. #ifndef   MIN
  115. #define   MIN(a,b)  ( ((a)<(b)) ? (a) : (b) )
  116. #endif /* MIN(a,b) */
  117.  
  118. #ifndef   MAX
  119. #define   MAX(a,b)  ( ((a)>(b)) ? (a) : (b) )
  120. #endif /* MAX(a,b) */
  121.  
  122. #ifndef   MIN3
  123. #define   MIN3(_a, _b, _c) MIN(MIN(_a, _b), _c)
  124. #endif /* MIN3 */
  125.  
  126. #ifndef   MAX3
  127. #define   MAX3(_a, _b, _c) MAX(MAX(_a, _b), _c)
  128. #endif /* MAX3 */
  129.  
  130. #ifndef   CLAMP
  131. #define   CLAMP(n, mn, mx)  MIN(MAX(n,mn),mx)
  132. #endif /* CLAMP(n, mn, mx) */
  133.  
  134. // Precise version of linear interpolation
  135. #ifndef   LERP
  136. #define   LERP(_v0, _v1, _t)  (  (1.0-(_t)) * (_v0)  +  (_t) * (_v1)  )
  137. #endif /* LERP */
  138.  
  139. // Imprecise (but theoretically faster) version
  140. #ifndef   LERP2
  141. #define   LERP2(_v0, _v1, _t)  ( (_v0) + (_t) * ((_v1)-(_v0))  )
  142. #endif /* LERP2 */
  143.  
  144. #ifndef   IN_BOUNDS
  145. #define   IN_BOUNDS(_x, _y) (  (_x) >= 0  &&  (_x) < CANVAS_W  && \
  146.                                (_y) >= 0  &&  (_y) < CANVAS_H  )
  147. #endif /* IN_BOUNDS */
  148.  
  149. // For printing the results of a boolean value.
  150. // To use this, use the "%s" format specifier,
  151. // with this as the parameter
  152. #ifndef   BOOL_STR
  153. #define   BOOL_STR(_is_true) ( (_is_true) ? "true" : "false" )
  154. #endif /* BOOL_STR */
  155.  
  156.  
  157.  
  158.  
  159.  
  160. #ifdef __cplusplus
  161.   #include <cstddef>
  162.   #include <cstdint>
  163.   #include <climits>
  164. #else
  165.   #include <stdint.h>
  166. #endif /* __cplusplus */
  167.  
  168. typedef uint8_t  u8;
  169. typedef uint16_t u16;
  170. typedef uint32_t u32;
  171. typedef uint64_t u64;
  172.  
  173. typedef int8_t  s8;
  174. typedef int16_t s16;
  175. typedef int32_t s32;
  176. typedef int64_t s64;
  177.  
  178. typedef float  f32;
  179. typedef double f64;
  180.  
  181.  
  182.  
  183.  
  184.  
  185. // There's no real point in messing with this stuff
  186. // unless you know how they're useful.
  187. // Relevant documentation if you want to know how to use these:
  188. // PACKED       : https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute
  189. // NOINLINE     : https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Common-Function-Attributes.html#index-noinline-function-attribute
  190. // DEPRECATED   : https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute
  191. // FALLTHROUGH  : https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Statement-Attributes.html#index-fallthrough-statement-attribute
  192. // ALWAYS_INLINE: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute
  193. #if defined(__GNUC__)
  194.   #define ATTR_PACKED        __attribute__((packed))
  195.   #define ATTR_NOINLINE      __attribute__((noinline))
  196.   #define ATTR_DEPRECATED    __attribute__((deprecated))
  197.   #define ATTR_FALLTHROUGH   __attribute__((fallthrough))
  198.   #define ATTR_ALWAYS_INLINE __attribute__((always_inline))
  199. #endif
  200.  
  201.  
  202.  
  203.  
  204.  
  205. /************************************ MISC ************************************/
  206.  
  207. struct Fpoint2d { f32 x, y; };
  208. struct Fpoint3d { f32 x, y, z; };
  209.  
  210. struct Point2d  { s32 x, y; };
  211. struct Point3d  { s32 x, y, z; };
  212.  
  213. struct Rect2d   { s32 x, y, w, h; };
  214.  
  215.  
  216.  
  217. // These are custom implementations for necessary functions.
  218. // They're only included if the std library isn't used,
  219. // since the framework has to use them for some things.
  220.  
  221. #ifndef STDLIB_USED
  222.  
  223. void* memSet(void* dst, int val, size_t len);
  224.  
  225. //(len_max does not include null-terminator!)
  226. //(if !len_max, call is analogous to str(not n)len)
  227. size_t strnLen(const char* str, size_t len_max);
  228.  
  229. char* strnCpy(char* str_dst, const char* str_src, size_t len_max);
  230.  
  231. char* strCat(char* dst, const char* src);
  232.  
  233. //(len_max does not include null-terminator!)
  234. //(if !len_max, call is analogous to str(not n)cmp)
  235. s32 strnCmp(const char* str_a, const char* str_b, size_t len_max);
  236.  
  237. f32 sinF(f32 x);
  238. #define cosF(_x) sinF((_x)+M_PI2f)
  239. #define tanF(_x) ( sinF(_x)/cosF(_x) )
  240.  
  241. #endif
  242.  
  243.  
  244.  
  245. enum MessageBoxEnum {
  246.   // Return values
  247.   MSGBOX_RTN_NULL     = 0x00000000, //showMessageBox failed
  248.   MSGBOX_RTN_OK       = 0x00000001, //'ok' button was clicked
  249.   MSGBOX_RTN_CANCEL   = 0x00000002, //'cancel' button was clicked
  250.   MSGBOX_RTN_ABORT    = 0x00000003, //'abort' button was clicked
  251.   MSGBOX_RTN_RETRY    = 0x00000004, //'retry' button was clicked
  252.   MSGBOX_RTN_IGNORE   = 0x00000005, //'ignore' button was clicked
  253.   MSGBOX_RTN_YES      = 0x00000006, //'yes' button was clicked
  254.   MSGBOX_RTN_NO       = 0x00000007, //'no' button was clicked
  255.   MSGBOX_RTN_TRYAGAIN = 0x0000000A, //'try again' button was clicked
  256.   MSGBOX_RTN_CONTINUE = 0x0000000B, //'continue' button was clicked
  257.  
  258.   // Button types
  259.   MSGBOX_BTN_OK                = 0x00000000,
  260.   MSGBOX_BTN_OKCANCEL          = 0x00000001,
  261.   MSGBOX_BTN_ABORTRETRYIGNORE  = 0x00000002,
  262.   MSGBOX_BTN_YESNOCANCEL       = 0x00000003,
  263.   MSGBOX_BTN_YESNO             = 0x00000004,
  264.   MSGBOX_BTN_RETRYCANCEL       = 0x00000005,
  265.   MSGBOX_BTN_CANCELTRYCONTINUE = 0x00000006,
  266.  
  267.   // Icon types
  268.   MSGBOX_ICN_ERROR    = 0x000000010,
  269.   MSGBOX_ICN_QUESTION = 0x000000020, //apparently deprecated, but still supported
  270.   MSGBOX_ICN_WARNING  = 0x000000030,
  271.   MSGBOX_ICN_INFO     = 0x000000040,
  272.  
  273. };
  274.  
  275. u32 showMessageBox(const char* text = nullptr, const char* title = nullptr,
  276.                    u32 type = MSGBOX_BTN_OK|MSGBOX_ICN_INFO,
  277.                    u32 defaultButton = 0);
  278.  
  279. u64 timeGetPerfCounter();
  280. u64 timeGetPerfFreq();
  281. f64 timeGetSeconds();
  282.  
  283. void timeSleep(u32 milliseconds);
  284.  
  285.  
  286.  
  287. #ifdef PRINT_EVENT_USED
  288. #ifdef _DEBUG
  289.   union Event; // Forward declaration
  290.   void print_event(Event& evt);
  291. #else
  292.   #define print_event(_evt) {}
  293. #endif /* _DEBUG */
  294. #endif /* PRINT_EVENT_USED */
  295.  
  296.  
  297.  
  298. // Warning: this doesn't check if buffer is not nullptr,
  299. // nor does it check if which_bit is inside buffer!
  300. bool is_bit_set(const void* buffer, u32 which_bit);
  301.  
  302.  
  303.  
  304. #ifdef FRAND_USED
  305. f64 frand();   // 0.0f -> 1.0f
  306. f64 frand2();  //-1.0f -> 1.0f
  307. f32 frandf();  // 0.0f -> 1.0f
  308. f32 frandf2(); //-1.0f -> 1.0f
  309. #endif /* FRAND_USED */
  310.  
  311.  
  312.  
  313. /* taken from stb_sprintf.h (what these 2 functions use under-the-hood):
  314.  
  315. 64-BIT INTS:
  316. ============
  317. This library also supports 64-bit integers and you can use MSVC style or
  318. GCC style indicators (%I64d or %lld).  It supports the C99 specifiers
  319. for size_t and ptr_diff_t (%jd %zd) as well.
  320.  
  321. EXTRAS:
  322. =======
  323. Like some GCCs, for integers and floats, you can use a ' (single quote)
  324. specifier and commas will be inserted on the thousands: "%'d" on 12345
  325. would print 12,345.
  326.  
  327. For integers and floats, you can use a "$" specifier and the number
  328. will be converted to float and then divided to get kilo, mega, giga or
  329. tera and then printed, so "%$d" 1000 is "1.0 k", "%$.2d" 2536000 is
  330. "2.53 M", etc. For byte values, use two $:s, like "%$$d" to turn
  331. 2536000 to "2.42 Mi". If you prefer JEDEC suffixes to SI ones, use three
  332. $:s: "%$$$d" -> "2.42 M". To remove the space between the number and the
  333. suffix, add "_" specifier: "%_$d" -> "2.53M".
  334.  
  335. In addition to octal and hexadecimal conversions, you can print
  336. integers in binary: "%b" for 256 would print 100.
  337.  
  338. PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC):
  339. ===================================================================
  340. "%d" across all 32-bit ints (4.8x/4.0x faster than 32-/64-bit MSVC)
  341. "%24d" across all 32-bit ints (4.5x/4.2x faster)
  342. "%x" across all 32-bit ints (4.5x/3.8x faster)
  343. "%08x" across all 32-bit ints (4.3x/3.8x faster)
  344. "%f" across e-10 to e+10 floats (7.3x/6.0x faster)
  345. "%e" across e-10 to e+10 floats (8.1x/6.0x faster)
  346. "%g" across e-10 to e+10 floats (10.0x/7.1x faster)
  347. "%f" for values near e-300 (7.9x/6.5x faster)
  348. "%f" for values near e+300 (10.0x/9.1x faster)
  349. "%e" for values near e-300 (10.1x/7.0x faster)
  350. "%e" for values near e+300 (9.2x/6.0x faster)
  351. "%.320f" for values near e-300 (12.6x/11.2x faster)
  352. "%a" for random values (8.6x/4.3x faster)
  353. "%I64d" for 64-bits with 32-bit values (4.8x/3.4x faster)
  354. "%I64d" for 64-bits > 32-bit values (4.9x/5.5x faster)
  355. "%s%s%s" for 64 char strings (7.1x/7.3x faster)
  356. "...512 char string..." ( 35.0x/32.5x faster!)
  357.  
  358. */
  359.  
  360. #define snprintf snPrintf
  361. #define vsnprintf vsnPrintf
  362. #include <stdarg.h>
  363.  
  364. //if len_max == 0 OR > INT_MAX, call is analogous to s(not n)printf
  365. s32 snPrintf(char* str_dst, size_t len_max, const char* str_fmt, ...);
  366.  
  367. //^^ VV unlike normal snprintf, these'll always return a null-terminated string
  368.  
  369. //if len_max == 0 OR > INT_MAX, call is analogous to vs(not n)printf
  370. s32 vsnPrintf(char* str_dst, size_t len_max, const char* str_fmt, va_list va);
  371.  
  372.  
  373.  
  374. // Use these instead of malloc, free, or realloc!
  375. void* mem_alloc(size_t size);
  376. void  mem_free(void* ptr_p); // ptr_p means: use &ptr instead of ptr
  377. void* mem_realloc(void* ptr_p, size_t newSize); // ptr_p is the same as in free
  378.  
  379. size_t mem_getNumAllocations();
  380. size_t mem_setNumAllocations(size_t value);
  381. size_t mem_addNumAllocations(s32 amount);
  382.  
  383. void* mem_set(void* ptr, s32 value, size_t size);
  384. void* mem_copy(void* destination, const void* source, size_t size);
  385.  
  386. struct mem_Wrapper {
  387.   void* ptr = nullptr;
  388.  
  389.   inline mem_Wrapper(size_t size){ ptr = mem_alloc(size); }
  390.   inline mem_Wrapper(void* _ptr) : ptr(_ptr) {} //existing mem_alloc
  391.   inline ~mem_Wrapper(){ mem_free(&ptr); };
  392.  
  393.   inline void* realloc(size_t newSize){ return mem_realloc(&ptr, newSize); }
  394.  
  395. };
  396.  
  397.  
  398.  
  399.  
  400.  
  401. /*********************************** INPUT ************************************/
  402.  
  403. #define EVENT_ID(_id) ( (_id) & 0xFFFF0000 )
  404. #define SUBEVENT_ID(_id) ( (_id) & 0xFFFF )
  405.  
  406. enum EventEnum {
  407.   EVENT_NULL            = 0x00000000,
  408.  
  409.   EVENT_COMMON          = 0x00010000, // Event_Common (Event.common)
  410.  
  411.   // (Occurs when the window is destroyed!)
  412.   EVENT_QUIT            = 0x00020000, // N/A (N/A)
  413.  
  414.   EVENT_KEY             = 0x00030000, // Event_Key (Event.key)
  415.   EVENT_KEY_CHAR        = EVENT_KEY   | 0x0001,
  416.   EVENT_KEY_UP          = EVENT_KEY   | 0x0002,
  417.   EVENT_KEY_DOWN        = EVENT_KEY   | 0x0003,
  418.  
  419.   EVENT_MOUSE           = 0x00040000, // Event_Mouse (Event.mouse)
  420.   EVENT_MOUSE_MOVED     = EVENT_MOUSE | 0x0001,
  421.   EVENT_MOUSE_HWHEEL    = EVENT_MOUSE | 0x0002,
  422.   EVENT_MOUSE_VWHEEL    = EVENT_MOUSE | 0x0003,
  423.   EVENT_MOUSE_UP        = EVENT_MOUSE | 0x0004,
  424.   EVENT_MOUSE_DOWN      = EVENT_MOUSE | 0x0005,
  425.  
  426.   // (Occurs once every time the cursor is trapped and released respectively!)
  427.   EVENT_CURSOR          = 0x00050000, // N/A (N/A)
  428.   EVENT_CURSOR_TRAPPED  = EVENT_CURSOR | 0x0001,
  429.   EVENT_CURSOR_RELEASED = EVENT_CURSOR | 0x0002,
  430.  
  431.   EVENT_UNKNOWN         = 0xFFFF0000,
  432.  
  433. };
  434.  
  435.  
  436.  
  437. /*+EVENT_COMMON+*/
  438.  
  439. struct Event_Common { //16B
  440.   u32  type;
  441.   u32 _unused; // Unused by common, but not necessarily other event types
  442.   u64  timestamp; // Performance counter is used; see "timeGetPerfCounter()"
  443. };
  444.  
  445. /*-EVENT_COMMON-*/
  446.  
  447.  
  448.  
  449. /*+EVENT_KEY+*/
  450.  
  451. // Event_Key.kmods can use any combination of these OR'd (AKA |) together
  452. enum Event_Key_ModifierEnum { // (These are bitmasks)
  453.   KMOD_NONE      = 0x0000,
  454.   KMOD_LSHIFT    = 0x0001,
  455.   KMOD_RSHIFT    = 0x0002,
  456.   KMOD_LCTRL     = 0x0004,
  457.   KMOD_RCTRL     = 0x0008,
  458.   KMOD_LALT      = 0x0010,
  459.   KMOD_RALT      = 0x0020,
  460.   KMOD_LGUI      = 0x0040, // Windows key?
  461.   KMOD_RGUI      = 0x0080,  //^^
  462.     KMOD_LWIN    = KMOD_LGUI,
  463.     KMOD_RWIN    = KMOD_RGUI,
  464.   KMOD_NUMLOCK   = 0x1000,
  465.   KMOD_CAPSLOCK  = 0x2000,
  466.   KMOD_ALTGRAPH  = 0x4000,
  467.   KMOD_SCROLLOCK = 0x8000,
  468.   KMOD_CTRL      = ( KMOD_LCTRL  | KMOD_RCTRL  ),
  469.   KMOD_SHIFT     = ( KMOD_LSHIFT | KMOD_RSHIFT ),
  470.   KMOD_ALT       = ( KMOD_LALT   | KMOD_RALT   ),
  471.   KMOD_GUI       = ( KMOD_LGUI   | KMOD_RGUI   ),
  472.   KMOD_WIN       = ( KMOD_LWIN   | KMOD_RWIN   ),
  473. };
  474.  
  475.  
  476.  
  477. enum Event_Key_PhysicalEnum {
  478.   // TBD because I don't want to bother with scancode stuff right now
  479. };
  480.  
  481.  
  482.  
  483. enum Event_Key_VirtualEnum {
  484.   VKEY_NULL             = 0x00,
  485.   //(misc. mouse)       = 0x01 -> 0x06
  486.   //(reserved)          = 0x07,
  487.   VKEY_BACK             = 0x08, //backspace key
  488.     VKEY_BACKSPACE      = VKEY_BACK,
  489.   VKEY_TAB              = 0x09,
  490.   //(reserved)          = 0x0A -> 0x0B,
  491.   VKEY_CLEAR            = 0x0C,
  492.   VKEY_RETURN           = 0x0D, //enter key
  493.     VKEY_ENTER          = VKEY_RETURN,
  494.   //(unassigned)        = 0x0E -> 0x0F,
  495.   VKEY_SHIFT            = 0x10,
  496.   VKEY_CONTROL          = 0x11, //ctrl key
  497.     VKEY_CTRL           = VKEY_CONTROL,
  498.   VKEY_MENU             = 0x12, //alt key
  499.     VKEY_ALT            = VKEY_MENU,
  500.   VKEY_PAUSE            = 0x13,
  501.   VKEY_CAPITAL          = 0x14, //caps lock key
  502.     VKEY_CAPSLOCK       = VKEY_CAPITAL,
  503.   //(IME stuff)         = 0x15 -> 0x1A,
  504.   VKEY_ESCAPE           = 0x1B, //esc key
  505.   //(IME stuff)         = 0x1C -> 0x1F,
  506.   VKEY_SPACE            = 0x20, //space bar key
  507.   VKEY_PRIOR            = 0x21, //page up key
  508.     VKEY_PGUP           = VKEY_PRIOR,
  509.   VKEY_NEXT             = 0x22, //page down key
  510.     VKEY_PGDN           = VKEY_NEXT,
  511.   VKEY_END              = 0x23,
  512.   VKEY_HOME             = 0x24,
  513.   VKEY_LEFT             = 0x25, //left arrow key
  514.   VKEY_UP               = 0x26, //up arrow key
  515.   VKEY_RIGHT            = 0x27, //right arrow key
  516.   VKEY_DOWN             = 0x28, //down arrow key
  517.   VKEY_SELECT           = 0x29,
  518.   VKEY_PRINT            = 0x2A,
  519.   VKEY_EXECUTE          = 0x2B,
  520.   VKEY_SNAPSHOT         = 0x2C, //print screen key
  521.     VKEY_PRTSC          = VKEY_SNAPSHOT,
  522.   VKEY_INSERT           = 0x2D, //ins key
  523.   VKEY_DELETE           = 0x2E, //del key
  524.   VKEY_HELP             = 0x2F, //help key
  525.   VKEY_0                = 0x30, //'0'
  526.   VKEY_1                = 0x31, //'1'
  527.   VKEY_2                = 0x32, //'2'
  528.   VKEY_3                = 0x33, //'3'
  529.   VKEY_4                = 0x34, //'4'
  530.   VKEY_5                = 0x35, //'5'
  531.   VKEY_6                = 0x36, //'6'
  532.   VKEY_7                = 0x37, //'7'
  533.   VKEY_8                = 0x38, //'8'
  534.   VKEY_9                = 0x39, //'9'
  535.   //(undefined)         = 0x3A -> 0x40,
  536.   VKEY_A                = 0x41, //'A'
  537.   VKEY_B                = 0x42, //'B'
  538.   VKEY_C                = 0x43, //'C'
  539.   VKEY_D                = 0x44, //'D'
  540.   VKEY_E                = 0x45, //'E'
  541.   VKEY_F                = 0x46, //'F'
  542.   VKEY_G                = 0x47, //'G'
  543.   VKEY_H                = 0x48, //'H'
  544.   VKEY_I                = 0x49, //'I'
  545.   VKEY_J                = 0x4A, //'J'
  546.   VKEY_K                = 0x4B, //'K'
  547.   VKEY_L                = 0x4C, //'L'
  548.   VKEY_M                = 0x4D, //'M'
  549.   VKEY_N                = 0x4E, //'N'
  550.   VKEY_O                = 0x4F, //'O'
  551.   VKEY_P                = 0x50, //'P'
  552.   VKEY_Q                = 0x51, //'Q'
  553.   VKEY_R                = 0x52, //'R'
  554.   VKEY_S                = 0x53, //'S'
  555.   VKEY_T                = 0x54, //'T'
  556.   VKEY_U                = 0x55, //'U'
  557.   VKEY_V                = 0x56, //'V'
  558.   VKEY_W                = 0x57, //'W'
  559.   VKEY_X                = 0x58, //'X'
  560.   VKEY_Y                = 0x59, //'Y'
  561.   VKEY_Z                = 0x5A, //'Z'
  562.   VKEY_LWIN             = 0x5B, //left windows key
  563.   VKEY_RWIN             = 0x5C, //right windows key
  564.   VKEY_APPS             = 0x5D, //applications key
  565.   //(reserved)          = 0x5E,
  566.   VKEY_SLEEP            = 0x5F, //computer sleep key
  567.   VKEY_NUMPAD0          = 0x60,
  568.   VKEY_NUMPAD1          = 0x61,
  569.   VKEY_NUMPAD2          = 0x62,
  570.   VKEY_NUMPAD3          = 0x63,
  571.   VKEY_NUMPAD4          = 0x64,
  572.   VKEY_NUMPAD5          = 0x65,
  573.   VKEY_NUMPAD6          = 0x66,
  574.   VKEY_NUMPAD7          = 0x67,
  575.   VKEY_NUMPAD8          = 0x68,
  576.   VKEY_NUMPAD9          = 0x69,
  577.   VKEY_MULTIPLY         = 0x6A, //numpad '*'
  578.   VKEY_ADD              = 0x6B, //numpad '+'
  579.   VKEY_SEPARATOR        = 0x6C, //numpad enter
  580.   VKEY_SUBTRACT         = 0x6D, //numpad '-'
  581.   VKEY_DECIMAL          = 0x6E, //numpad '.'
  582.   VKEY_DIVIDE           = 0x6F, //numpad '/'
  583.   VKEY_F1               = 0x70,
  584.   VKEY_F2               = 0x71,
  585.   VKEY_F3               = 0x72,
  586.   VKEY_F4               = 0x73,
  587.   VKEY_F5               = 0x74,
  588.   VKEY_F6               = 0x75,
  589.   VKEY_F7               = 0x76,
  590.   VKEY_F8               = 0x77,
  591.   VKEY_F9               = 0x78,
  592.   VKEY_F10              = 0x79,
  593.   VKEY_F11              = 0x7A,
  594.   VKEY_F12              = 0x7B,
  595.   VKEY_F13              = 0x7C,
  596.   VKEY_F14              = 0x7D,
  597.   VKEY_F15              = 0x7E,
  598.   VKEY_F16              = 0x7F,
  599.   VKEY_F17              = 0x80,
  600.   VKEY_F18              = 0x81,
  601.   VKEY_F19              = 0x82,
  602.   VKEY_F20              = 0x83,
  603.   VKEY_F21              = 0x84,
  604.   VKEY_F22              = 0x85,
  605.   VKEY_F23              = 0x86,
  606.   VKEY_F24              = 0x87,
  607.   //(reserved)          = 0x88 -> 0x8F,
  608.   VKEY_NUMLOCK          = 0x90,
  609.   VKEY_SCROLL           = 0x91, //scroll lock key
  610.     VKEY_SCROLLOCK      = VKEY_SCROLL,
  611.   //(OEM-specific)      = 0x92 -> 0x96,
  612.   //(unassigned)        = 0x97 -> 0x9F,
  613.   //(l/r key variants)  = 0xA0 -> 0xA5,
  614.   //(browser keys)      = 0xA6 -> 0xAC,
  615.   VKEY_VOLUME_MUTE      = 0xAD,
  616.   VKEY_VOLUME_DOWN      = 0xAE,
  617.   VKEY_VOLUME_UP        = 0xAF,
  618.   VKEY_MEDIA_NEXT_TRACK = 0xB0,
  619.   VKEY_MEDIA_PREV_TRACK = 0xB1,
  620.   VKEY_MEDIA_STOP       = 0xB2,
  621.   VKEY_MEDIA_PLAY_PAUSE = 0xB3, //Play/Pause Media key
  622.   //(launch keys)       = 0xB4 -> 0xB7,
  623.   //(reserved)          = 0xB8 -> 0xB9,
  624.   VKEY_OEM_1            = 0xBA, //misc. chars; varies by keyboard (';',':' on US standard)
  625.     VKEY_SEMICOLON      = VKEY_OEM_1,
  626.   VKEY_OEM_PLUS         = 0xBB, //'+' in any country/region
  627.     VKEY_PLUS           = VKEY_OEM_PLUS,
  628.   VKEY_OEM_COMMA        = 0xBC, //',' in any country/region
  629.     VKEY_COMMA          = VKEY_OEM_COMMA,
  630.   VKEY_OEM_MINUS        = 0xBD, //'-' in any country/region
  631.     VKEY_MINUS          = VKEY_OEM_MINUS,
  632.   VKEY_OEM_PERIOD       = 0xBE, //'.' in any country/region
  633.     VKEY_PERIOD         = VKEY_OEM_PERIOD,
  634.   VKEY_OEM_2            = 0xBF, //misc. chars; varies by keyboard ('/','?' on US standard)
  635.     VKEY_FSLASH         = VKEY_OEM_2,
  636.   VKEY_OEM_3            = 0xC0, //misc. chars; varies by keyboard ('`','~' on US standard)
  637.     VKEY_BACKTICK       = VKEY_OEM_3,
  638.   //(reserved)          = 0xC1 -> 0xDA,
  639.   VKEY_OEM_4            = 0xDB, //misc. chars; varies by keyboard ('[','{' on US standard)
  640.     VKEY_LBRACKET       = VKEY_OEM_4,
  641.   VKEY_OEM_5            = 0xDC, //misc. chars; varies by keyboard ('\\','|' on US standard)
  642.     VKEY_BSLASH         = VKEY_OEM_5,
  643.   VKEY_OEM_6            = 0xDD, //misc. chars; varies by keyboard (']','}' on US standard)
  644.     VKEY_RBRACKET       = VKEY_OEM_6,
  645.   VKEY_OEM_7            = 0xDE, //misc. chars; varies by keyboard ('\'','\"' on US standard)
  646.     VKEY_APOSTROPHE     = VKEY_OEM_7,
  647.   VKEY_OEM_8            = 0xDF, //misc. chars; varies by keyboard
  648.   //(reserved)          = 0xE0,
  649.   //(misc.)             = 0xE1 -> 0xE7,
  650.   //(unassigned)        = 0xE8,
  651.   //(misc.)             = 0xE9 -> 0xFE,
  652.  
  653. };
  654.  
  655.  
  656.  
  657. // Mod[ifier]
  658. union Event_Key_Mod { //2B
  659.   // IMPORTANT:
  660.   // Due to me having terminal couldn't-care-less syndrome,
  661.   // I haven't implemented differenciating between the
  662.   // left and right variants of shift, control, et cetera,
  663.   // so both variants are set/unset when either are pressed/unpressed.
  664.   // (Except lgui and rgui, since that's easier to detect???)
  665.   // (ALSO ALTGRAPH ISN'T IMPLEMENTED AT ALL THANKS MICROSOFT)
  666.  
  667.   struct {
  668.     u16 lshift    : 1;
  669.     u16 rshift    : 1;
  670.     u16 lctrl     : 1;
  671.     u16 rctrl     : 1;
  672.     u16 lalt      : 1;
  673.     u16 ralt      : 1;
  674.     u16 lgui      : 1;
  675.     u16 rgui      : 1;
  676.     u16 _unused   : 4;
  677.     u16 numlock   : 1;
  678.     u16 capslock  : 1;
  679.     u16 altgraph  : 1;
  680.     u16 scrollock : 1;
  681.   };
  682.  
  683.   u16 all;
  684.  
  685. };
  686.  
  687.  
  688.  
  689. // Short for "Key Symbol"
  690. struct Event_Key_Sym { //8B
  691.   union {
  692.     Event_Key_Mod kmod;
  693.     u16           kmods;
  694.   };
  695.  
  696.   u8  _unused;
  697.   u8   pkey; // Physical key code (named .scancode in SDL's Keysym struct)
  698.   u8   vkey; // Virtual key code (named .sym in SDL's Keysym struct)
  699.   bool pressed;
  700.   bool ischar; // 'is event KEY_CHAR?', otherwise it's KEY_UP or KEY_DOWN
  701.   bool repeat; // Y'know that thing where in a text editor you hold down a key?
  702.  
  703. };
  704.  
  705.  
  706.  
  707. struct Event_Key { //24B
  708.   u32  type;
  709.   u32 _unused_0;
  710.   u64  timestamp; // Performance counter is used; see "timeGetPerfCounter()"
  711.  
  712.   union {
  713.     struct { // (Effectively a copy of Event_Key_Sym)
  714.       u16  kmods;
  715.       u8  _unused_1;
  716.       u8   pkey;
  717.       u8   vkey;
  718.       bool pressed;
  719.       bool ischar;
  720.       bool repeat;
  721.     };
  722.     Event_Key_Sym sym;
  723.   };
  724.  
  725. };
  726.  
  727. /*-EVENT_KEY-*/
  728.  
  729.  
  730.  
  731. /*+EVENT_MOUSE+*/
  732.  
  733. // Event_Mouse.button can use any combination of these OR'd (AKA |) together
  734. enum Event_Mouse_ButtonEnum { // (These are bitmasks)
  735.   MBUTTON_LEFT   = 0x01,
  736.   MBUTTON_MIDDLE = 0x02,
  737.   MBUTTON_RIGHT  = 0x04,
  738.   MBUTTON_X1     = 0x08, // Those 2 buttons on the sides of most mice nowadays
  739.   MBUTTON_X2     = 0x10,  //^^
  740.   MBUTTON_CTRL   = 0x20, // 'Is the control key currently pressed?'
  741.   MBUTTON_SHIFT  = 0x40, // 'Is the shift key currently pressed?'
  742. };
  743.  
  744. // (EVENT_MOUSE_<H/V>WHEEL events use dx and dy!)
  745. struct Event_Mouse { //32B
  746.   u32  type;
  747.  
  748.   u8  _unused;
  749.   u8   button;   // Flags for currently pressed buttons (Event_Mouse_ButtonEnum)
  750.   bool pressed;  // Will be true if button is nonzero
  751.   bool dblClick; // 'Is double click?' (ignored if cursor is trapped)
  752.  
  753.   u64  timestamp;
  754.  
  755.   f32  x;  // Coordinates relative to window
  756.   f32  y;   //^^
  757.   f32  dx; // Delta x (coordinates relative to last recorded x position)
  758.   f32  dy; // Delta y (coordinates relative to last recorded y position)
  759.   // (IF THE CURSOR IS TRAPPED, DELTAS WILL BE GIVEN AS-IS,
  760.   //  WITHOUT BEING SCALED WITH RESPECT TO THE WINDOW'S CURRENT SIZE!)
  761.  
  762. };
  763.  
  764. /*-EVENT_MOUSE-*/
  765.  
  766.  
  767.  
  768. union Event { //32B (assuming Event_Mouse is the largest event bytes-wise)
  769.   u32          type;
  770.  
  771.   Event_Common common;
  772.   Event_Key    key;
  773.   Event_Mouse  mouse;
  774.  
  775. };
  776.  
  777.  
  778.  
  779. // Populates *event_p with the contents of the first event in the event queue.
  780. // Returns false if there were no events left in queue; true otherwise.
  781. // (Calling this exclusively in the main thread is recommended)
  782. bool pollEvent(Event* event_p = nullptr); // Burns events if event_p is nullptr
  783.  
  784.  
  785.  
  786. // Returns true if the mouse cursor is clipped within the window, and is hidden
  787. bool is_cursor_trapped();
  788.  
  789.  
  790.  
  791.  
  792.  
  793. /*********************************** AUDIO ************************************/
  794.  
  795. // Don't edit this one, as it's the hardcoded max length of an audio buffer!
  796. #define AUDIO_SAMPLES_MAX 4096
  797.  
  798.  
  799.  
  800. // Stereo audio samples as two 32-bit floats,
  801. // where each of the two channels can be between -1.0 to 1.0
  802. struct StereoF32 { f32 l,r; };
  803.  
  804.  
  805.  
  806. // The length of the audio stream's buffer, in samples
  807. extern u32 audio_samples;
  808.  
  809. // The audio's sample rate, in hertz
  810. extern u32 sample_rate;
  811.  
  812.  
  813.  
  814. #include "sound_stuff.hpp"
  815.  
  816.  
  817.  
  818.  
  819.  
  820. /*********************************** VIDEO ************************************/
  821.  
  822. #define WINDOW_NAME "Terrible Maze Game (\"esc\" to toggle relative mouse mode)"
  823.  
  824. // If left at 4, window will initially appear 4x as big as canvas
  825. #define WINDOW_RESMUL (4/2)
  826.  
  827. // Technically customizable, but keeping it at 256x144 makes it 16:9,
  828. // while also taking advantage of the fact an x position can just be stored
  829. // within exactly 1 byte. This is useful for several types of optimizations
  830. //
  831. // The next best thing would be to at least keep it a power of 2.
  832. // For example, 512x288 would use the lowest 9 bits (2^9 = 512) as the x
  833. // coordinate, and 64x36 would use the lowest 6 bits (2^6 = 64), et cetera.
  834. #define CANVAS_W (256*2)
  835. #define CANVAS_H (144*2)
  836.  
  837.  
  838.  
  839. // This assumes the canvas width is equal to 256
  840. union PixelCoords {
  841.   u16 v; // Full index
  842.  
  843.   struct { u8 x, y; };
  844.  
  845.   PixelCoords() : v(0) {}
  846.   PixelCoords(u16 _v) : v(_v) {}
  847.   PixelCoords(u8 _x, u8 _y) : x(_x), y(_y) {}
  848.  
  849. };
  850.  
  851.  
  852.  
  853. // Used for the pixel buffer. This corresponds to the 8-bit color palette
  854. // initially set during initialization. However, this palette can be
  855. // changed by setting entries in pixels_palette and calling update_palette().
  856. // (Actually, update_palette doesn't necessarily need to use pixels_palette,
  857. //  Which means you can hotswap completely separate palettes!)
  858. //
  859. // There is a grayscale section of the built-in palette,
  860. // where shades increment every 16 units of the ".v" member.
  861. // (With a max of 255, so the grayscale is effectively "MIN(x*16, 255)")
  862. union Color8 {
  863.   u8 v; // Full pixel value
  864.  
  865.   struct {
  866.     u8 r : 3;
  867.     u8 g : 3;
  868.     u8 b : 2;
  869.   };
  870.  
  871.   Color8() : v(0) {}
  872.   Color8(u8 _v) : v(_v) {}
  873.  
  874. };
  875.  
  876.  
  877.  
  878. // Used for setting pixels_palette.
  879. // This struct is analagous to Win32's own RGBQUAD struct,
  880. // but formatted to be a bit more readable and nicer-looking
  881. //
  882. // (Make sure to call update_palette() to apply any changes to the palette!)
  883. union Color24 {
  884.   // Full pixel value. Since this is a union, this 32-bit value takes
  885.   // up the same space as the four 8-bit values below.
  886.   // The purpose of using a union like this is that by setting v,
  887.   // you are setting b,g,r, and _ at the same time!
  888.   u32 v;
  889.  
  890.   // Before the C11 standard, anonymous structs (or unions for that matter)
  891.   // were compiler-specific extensions, but virtually all modern compilers
  892.   // allow this type of syntax, where structs that are directly declaring
  893.   // the contents of a type (as opposed to defining a type that can be
  894.   // replicated) without giving it a name.
  895.   //
  896.   // In this case, this effectively packages these four bytes to be in this
  897.   // order, rather than reside in the same space (this is a union, after all!)
  898.   struct {
  899.     u8 b;
  900.     u8 g;
  901.     u8 r;
  902.     u8 _; // (Unused; this is just padding to the nearest multiple of 32-bits)
  903.   };
  904.  
  905. };
  906.  
  907.  
  908.  
  909. // Unlike most graphics APIs in the last 30 years, GDI on Windows uses bitmaps
  910. // (which this buffer uses) stores pixels left-right bottom-up,
  911. // and not left-right top-down (for some reason)!!!!!
  912. extern Color8*  pixels;
  913.  
  914. // This is always 256 elements in length, since each pixel is an 8-bit index
  915. // into this color palette (2^8(bits) = 256)
  916. extern Color24* pixels_palette;
  917.  
  918. // This is true if the canvas's window has been closed; false otherwise
  919. extern bool win_closed;
  920.  
  921.  
  922.  
  923. void canvas_present(bool immediate = true);
  924.  
  925. void canvas_clear(Color8 fill_color);
  926.  
  927. void close_window(); // Also triggers an EVENT_QUIT
  928.  
  929. // Updates the 256-color palette. It defaults to the built-in one,
  930. // but not only can you edit the built-in palette, you can make this
  931. // function use another palette, just in case you want to swap out
  932. // entirely different palettes on the fly!
  933. //
  934. // Does nothing if new_palette is given as NULL.
  935. // This also makes sure that no color beyond the 255th is changed.
  936. // For example, if first_color is 255, and num_colors is 2,
  937. // only a single color will be changed, since 255 is the last color index
  938. //
  939. // Returns true on success, false otherwise
  940. bool update_palette(u32 first_color = 0, u32 num_colors = 256,
  941.                     const Color24* new_palette = pixels_palette);
  942.  
  943. // Returns the current size of the window's *client* area,
  944. // which is basically the space in the window where stuff is actually drawn
  945. Point2d get_win_size();
  946.  
  947.  
  948.  
  949.  
  950.  
  951. /********************************** FILE IO ***********************************/
  952.  
  953. struct BinaryData {
  954.   union { // The everything union~
  955.     u8 *  data_u8;
  956.     u16*  data_u16;
  957.     u32*  data_u32;
  958.     u64*  data_u64;
  959.  
  960.     s8 *  data_s8;
  961.     s16*  data_s16;
  962.     s32*  data_s32;
  963.     s64*  data_s64;
  964.  
  965.     f32*  data_f32;
  966.     f64*  data_f64;
  967.  
  968.     char* data_char;
  969.     void* data_void = nullptr;
  970.   };
  971.  
  972.   // Even if size is 0, data will always have at least a single byte of valid
  973.   // allocated memory. This is because there is always one more byte allocated
  974.   // than is requested, to make sure that data is only ever nullptr if
  975.   // construction fails! (This extra byte will always be set to 0.)
  976.   const size_t size;
  977.  
  978.  
  979.   BinaryData(const char* file_path);
  980.  
  981.   // This will allocate _size bytes for data, before copying src to data
  982.   //
  983.   // (It is safe to pass nullptr to src, though that would make the struct
  984.   //  instance sorta equivalent to a garbage-collected CoTaskMemAlloc().)
  985.   BinaryData(const void* src, size_t _size);
  986.  
  987.   ~BinaryData();
  988.  
  989. };
  990.  
  991.  
  992.  
  993. // fileio_read allocates memory! use mem_free on the returned pointer after use!
  994. void* fileio_read(const char* file_path, size_t* dataSize_p);
  995.  
  996. bool fileio_write(const char* file_path, const void* data,
  997.                   size_t data_size, bool append = false);
  998.  
  999.  
  1000.  
  1001. #define FILEIO_SIZE_ERR 0xFFFFFFFFFFFFFFFF
  1002.  
  1003. size_t fileio_size(const char* file_path);
  1004.  
  1005. bool fileio_isreadonly(const char* file_path);
  1006.  
  1007. bool fileio_exists(const char* file_path);
  1008.  
  1009. bool fileio_delete(const char* file_path);
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015. /*********************** DRAW STUFF (NOT WIN32-RELATED) ***********************/
  1016.  
  1017. // IMPORTANT:
  1018. // Refer to the comment right above the pixels buffer declaration,
  1019. // as bitmaps handled by these draw functions use the same formatting!
  1020. //
  1021. // Also, on all draw functions with a customizable destination,
  1022. // that destination must be at least the same length as the "pixel"s buffer!
  1023.  
  1024.  
  1025.  
  1026. struct Triangle32 { //16B
  1027.   u32   a, b, c;
  1028.   Color8  color;
  1029.   u8 _unused[3];
  1030. };
  1031.  
  1032. struct Triangle16 { //8B
  1033.   u16  a, b, c;
  1034.   Color8 color;
  1035.   u8   _unused;
  1036. };
  1037.  
  1038. struct Triangle8 { //4B
  1039.   u8   a, b, c;
  1040.   Color8 color;
  1041. };
  1042.  
  1043. typedef Triangle32 Triangle;
  1044.  
  1045.  
  1046.  
  1047. #ifdef FONT_PICO8_USED
  1048. extern u8     font_pico8_packed[184];    // Initialized; font in compressed form
  1049. extern Color8 font_pico8[4 + 3*5 * 256]; // Uninitialized; must be unpacked into
  1050. #endif
  1051.  
  1052.  
  1053.  
  1054. // Returns false if either dst or src are nullptr; true otherwise
  1055. #ifdef UNPACK_FONT_USED
  1056. bool unpack_font(Color8* dst, const u8* src,
  1057.                  Color8 fontColor         = 0b11111111,  // White
  1058.                  Color8 transparencyColor = 0b11000111); // Magenta
  1059. #endif
  1060.  
  1061.  
  1062.  
  1063. #ifdef FONT_PICO8_USED
  1064.   #define DEFAULT_FONT font_pico8
  1065. #else
  1066.   #define DEFAULT_FONT nullptr
  1067. #endif /* FONT_PICO8_USED */
  1068.  
  1069.  
  1070.  
  1071. #ifdef DRAW_TEXT_USED
  1072.  
  1073. // Set x and/or y to this to center the text on that axis
  1074. #define CENTERED_TEXT (-2147483647) //aka 0x80000001
  1075.  
  1076. #define TEXT_ERROR_RECT {-1, -1, -1, -1}
  1077.  
  1078. void draw_char(u8 chr, s32 x, s32 y, // (Ignores CENTERED_TEXT)
  1079.                const Color8* font = DEFAULT_FONT,
  1080.                Color8* dst = pixels);
  1081.  
  1082. Rect2d get_text_rect(const char* str, s32 x, s32 y,
  1083.                      bool use_negative_position_margin = false,
  1084.                      const Color8* font = DEFAULT_FONT);
  1085.  
  1086. // Returns final rect of the text
  1087. Rect2d draw_text(const char* str, s32 x, s32 y, u32 maxLength = 0,
  1088.                  bool use_negative_position_margin = false,
  1089.                  const Color8* font = DEFAULT_FONT, Color8* dst = pixels);
  1090.  
  1091. #endif /* DRAW_TEXT_USED */
  1092.  
  1093.  
  1094.  
  1095. // THESE ARE NOT THREAD SAFE, SINCE THEY USE THE SAME BUFFER BETWEEN CALLS!
  1096. //
  1097. // (An underscore is used in _DRAW_TEXTF_USED to make
  1098. //  autocomplete on calls to DRAW_TEXTF more convenient)
  1099. #ifdef _DRAW_TEXTF_USED
  1100.  
  1101. #define TEXT_FMT_BUFFER_LEN 8192
  1102.  
  1103. // Also puts the contents of the format into the built-in destination buffer
  1104. Rect2d get_text_rectf(const char* str_fmt, s32 x, s32 y,
  1105.                       bool use_negative_position_margin = false,
  1106.                       const Color8* font = DEFAULT_FONT, ...);
  1107.  
  1108. // (Variadic args version)
  1109. Rect2d get_text_rectvf(const char* str_fmt, s32 x, s32 y, va_list va,
  1110.                        bool use_negative_position_margin = false,
  1111.                        const Color8* font = DEFAULT_FONT);
  1112.  
  1113. // Draws the current contents of the built-in destination buffer
  1114. Rect2d draw_current_textf_buffer(s32 x, s32 y, u32 maxLength = 0,
  1115.                                  bool use_negative_position_margin = false,
  1116.                                  const Color8* font = DEFAULT_FONT,
  1117.                                  Color8* dst = pixels);
  1118.  
  1119. #define DRAW_TEXTF(_fmt, _x, _y, _npm, ...) \
  1120.   draw_textf(_fmt, (_x), (_y), 0, (_npm), DEFAULT_FONT, pixels, __VA_ARGS__)
  1121.  
  1122. Rect2d draw_textf(const char* str_fmt, s32 x, s32 y, u32 maxLength = 0,
  1123.                   bool use_negative_position_margin = false,
  1124.                   const Color8* font = DEFAULT_FONT,
  1125.                   Color8* dst = pixels, ...);
  1126.  
  1127. #endif /* _DRAW_TEXTF_USED */
  1128.  
  1129.  
  1130.  
  1131. // Blits a bitmap, where the first two bytes are its width and height,
  1132. // the third byte corresponding to its transparent color,
  1133. // the fourth byte corresponding to flags (unused by this function),
  1134. // the fifth and sixth bytes are position offsets (of type s8),
  1135. // the seventh and eighth bytes are padding and are currently unused,
  1136. // with the bytes after being the pixels.
  1137. #ifdef BLIT_USED
  1138. void blit(s32 x, s32 y, const Color8* src, Color8* dst = pixels);
  1139. #endif
  1140.  
  1141.  
  1142.  
  1143. #ifdef DRAW_LINE_USED
  1144. void draw_line(s32 x_0, s32 y_0,
  1145.                s32 x_1, s32 y_1,
  1146.                Color8 color,
  1147.                Color8* dst = pixels);
  1148. #endif
  1149.  
  1150.  
  1151.  
  1152. #ifdef DRAW_RECT_USED
  1153. void draw_rect(s32 x, s32 y,
  1154.                s32 w, s32 h,
  1155.                Color8 color,
  1156.                Color8* dst = pixels);
  1157. #endif
  1158.  
  1159. #ifdef FILL_RECT_USED
  1160. void fill_rect(s32 x, s32 y,
  1161.                s32 w, s32 h,
  1162.                Color8 color,
  1163.                Color8* dst = pixels);
  1164. #endif
  1165.  
  1166.  
  1167.  
  1168. // Sretches a vertical column of the source's pixels,
  1169. // using nearest-neighbor interpolation
  1170. #ifdef DRAW_VSLICE_USED
  1171. void draw_vslice(s32  dst_x, f32 height,
  1172.                  f32 _src_x, const Color8* src,
  1173.                  Color8* dst = pixels);
  1174. #endif
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180. /* TBD
  1181. void fill_tri(f32 x_0, f32 y_0,
  1182.               f32 x_1, f32 y_1,
  1183.               f32 x_2, f32 y_2,
  1184.               Color8 color);
  1185.  
  1186. void fill_tris(const Fpoint3d* verts,
  1187.                const Triangle* tris, u32 tris_len);
  1188.  
  1189. void fill_tris2(const Fpoint3d* verts, const Triangle* tris,
  1190.                 const u32*    indices, u32      indices_len);
  1191. */
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197. #endif /* _PUBLIC_STUFF_HPP */
  1198.  
Advertisement
Add Comment
Please, Sign In to add comment