test_cpp_compilation.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #define STB_IMAGE_WRITE_STATIC
  2. #define STBIWDEF static inline
  3. #include "stb_image.h"
  4. #include "stb_rect_pack.h"
  5. #include "stb_truetype.h"
  6. #include "stb_image_write.h"
  7. #include "stb_c_lexer.h"
  8. #include "stb_perlin.h"
  9. #include "stb_dxt.h"
  10. #include "stb_divide.h"
  11. #include "stb_herringbone_wang_tile.h"
  12. #include "stb_ds.h"
  13. #include "stb_hexwave.h"
  14. #include "stb_sprintf.h"
  15. #define STB_SPRINTF_IMPLEMENTATION
  16. #include "stb_sprintf.h"
  17. #define STB_IMAGE_WRITE_IMPLEMENTATION
  18. #define STB_TRUETYPE_IMPLEMENTATION
  19. #define STB_PERLIN_IMPLEMENTATION
  20. #define STB_DXT_IMPLEMENATION
  21. #define STB_C_LEXER_IMPLEMENTATIOn
  22. #define STB_DIVIDE_IMPLEMENTATION
  23. #define STB_IMAGE_IMPLEMENTATION
  24. #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION
  25. #define STB_RECT_PACK_IMPLEMENTATION
  26. #define STB_VOXEL_RENDER_IMPLEMENTATION
  27. #define STB_CONNECTED_COMPONENTS_IMPLEMENTATION
  28. #define STB_HEXWAVE_IMPLEMENTATION
  29. #define STB_DS_IMPLEMENTATION
  30. #define STBDS_UNIT_TESTS
  31. #define STBI_MALLOC my_malloc
  32. #define STBI_FREE my_free
  33. #define STBI_REALLOC my_realloc
  34. void *my_malloc(size_t) { return 0; }
  35. void *my_realloc(void *, size_t) { return 0; }
  36. void my_free(void *) { }
  37. #include "stb_image.h"
  38. #include "stb_rect_pack.h"
  39. #include "stb_truetype.h"
  40. #include "stb_image_write.h"
  41. #include "stb_perlin.h"
  42. #include "stb_dxt.h"
  43. #include "stb_divide.h"
  44. #include "stb_herringbone_wang_tile.h"
  45. #include "stb_ds.h"
  46. #include "stb_hexwave.h"
  47. #define STBCC_GRID_COUNT_X_LOG2 10
  48. #define STBCC_GRID_COUNT_Y_LOG2 10
  49. #include "stb_connected_components.h"
  50. #define STBVOX_CONFIG_MODE 1
  51. #include "stb_voxel_render.h"
  52. #define STBTE_DRAW_RECT(x0,y0,x1,y1,color) do ; while(0)
  53. #define STBTE_DRAW_TILE(x,y,id,highlight,data) do ; while(0)
  54. #define STB_TILEMAP_EDITOR_IMPLEMENTATION
  55. #include "stb_tilemap_editor.h"
  56. #include "stb_easy_font.h"
  57. #define STB_LEAKCHECK_IMPLEMENTATION
  58. #include "stb_leakcheck.h"
  59. #define STB_IMAGE_RESIZE_IMPLEMENTATION
  60. #include "stb_image_resize2.h"
  61. //#include "stretchy_buffer.h" // deprecating
  62. // avoid unused-function complaints
  63. void dummy2(void)
  64. {
  65. stb_easy_font_spacing(1.0);
  66. stb_easy_font_print(0,0,NULL,NULL,NULL,0);
  67. stb_easy_font_width(NULL);
  68. stb_easy_font_height(NULL);
  69. }
  70. ////////////////////////////////////////////////////////////
  71. //
  72. // text edit
  73. #include <stdlib.h>
  74. #include <string.h> // memmove
  75. #include <ctype.h> // isspace
  76. #define STB_TEXTEDIT_CHARTYPE char
  77. #define STB_TEXTEDIT_STRING text_control
  78. // get the base type
  79. #include "stb_textedit.h"
  80. // define our editor structure
  81. typedef struct
  82. {
  83. char *string;
  84. int stringlen;
  85. STB_TexteditState state;
  86. } text_control;
  87. // define the functions we need
  88. void layout_func(StbTexteditRow *row, STB_TEXTEDIT_STRING *str, int start_i)
  89. {
  90. int remaining_chars = str->stringlen - start_i;
  91. row->num_chars = remaining_chars > 20 ? 20 : remaining_chars; // should do real word wrap here
  92. row->x0 = 0;
  93. row->x1 = 20; // need to account for actual size of characters
  94. row->baseline_y_delta = 1.25;
  95. row->ymin = -1;
  96. row->ymax = 0;
  97. }
  98. int delete_chars(STB_TEXTEDIT_STRING *str, int pos, int num)
  99. {
  100. memmove(&str->string[pos], &str->string[pos+num], str->stringlen - (pos+num));
  101. str->stringlen -= num;
  102. return 1; // always succeeds
  103. }
  104. int insert_chars(STB_TEXTEDIT_STRING *str, int pos, STB_TEXTEDIT_CHARTYPE *newtext, int num)
  105. {
  106. str->string = (char *) realloc(str->string, str->stringlen + num);
  107. memmove(&str->string[pos+num], &str->string[pos], str->stringlen - pos);
  108. memcpy(&str->string[pos], newtext, num);
  109. str->stringlen += num;
  110. return 1; // always succeeds
  111. }
  112. // define all the #defines needed
  113. #define KEYDOWN_BIT 0x40000000
  114. #define STB_TEXTEDIT_STRINGLEN(tc) ((tc)->stringlen)
  115. #define STB_TEXTEDIT_LAYOUTROW layout_func
  116. #define STB_TEXTEDIT_GETWIDTH(tc,n,i) (1) // quick hack for monospaced
  117. #define STB_TEXTEDIT_KEYTOTEXT(key) (((key) & KEYDOWN_BIT) ? 0 : (key))
  118. #define STB_TEXTEDIT_GETCHAR(tc,i) ((tc)->string[i])
  119. #define STB_TEXTEDIT_NEWLINE '\n'
  120. #define STB_TEXTEDIT_IS_SPACE(ch) isspace(ch)
  121. #define STB_TEXTEDIT_DELETECHARS delete_chars
  122. #define STB_TEXTEDIT_INSERTCHARS insert_chars
  123. #define STB_TEXTEDIT_K_SHIFT 0x20000000
  124. #define STB_TEXTEDIT_K_CONTROL 0x10000000
  125. #define STB_TEXTEDIT_K_LEFT (KEYDOWN_BIT | 1) // actually use VK_LEFT, SDLK_LEFT, etc
  126. #define STB_TEXTEDIT_K_RIGHT (KEYDOWN_BIT | 2) // VK_RIGHT
  127. #define STB_TEXTEDIT_K_UP (KEYDOWN_BIT | 3) // VK_UP
  128. #define STB_TEXTEDIT_K_DOWN (KEYDOWN_BIT | 4) // VK_DOWN
  129. #define STB_TEXTEDIT_K_LINESTART (KEYDOWN_BIT | 5) // VK_HOME
  130. #define STB_TEXTEDIT_K_LINEEND (KEYDOWN_BIT | 6) // VK_END
  131. #define STB_TEXTEDIT_K_TEXTSTART (STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_CONTROL)
  132. #define STB_TEXTEDIT_K_TEXTEND (STB_TEXTEDIT_K_LINEEND | STB_TEXTEDIT_K_CONTROL)
  133. #define STB_TEXTEDIT_K_DELETE (KEYDOWN_BIT | 7) // VK_DELETE
  134. #define STB_TEXTEDIT_K_BACKSPACE (KEYDOWN_BIT | 8) // VK_BACKSPACE
  135. #define STB_TEXTEDIT_K_UNDO (KEYDOWN_BIT | STB_TEXTEDIT_K_CONTROL | 'z')
  136. #define STB_TEXTEDIT_K_REDO (KEYDOWN_BIT | STB_TEXTEDIT_K_CONTROL | 'y')
  137. #define STB_TEXTEDIT_K_INSERT (KEYDOWN_BIT | 9) // VK_INSERT
  138. #define STB_TEXTEDIT_K_WORDLEFT (STB_TEXTEDIT_K_LEFT | STB_TEXTEDIT_K_CONTROL)
  139. #define STB_TEXTEDIT_K_WORDRIGHT (STB_TEXTEDIT_K_RIGHT | STB_TEXTEDIT_K_CONTROL)
  140. #define STB_TEXTEDIT_K_PGUP (KEYDOWN_BIT | 10) // VK_PGUP -- not implemented
  141. #define STB_TEXTEDIT_K_PGDOWN (KEYDOWN_BIT | 11) // VK_PGDOWN -- not implemented
  142. #define STB_TEXTEDIT_IMPLEMENTATION
  143. #include "stb_textedit.h"
  144. void dummy3(void)
  145. {
  146. stb_textedit_click(0,0,0,0);
  147. stb_textedit_drag(0,0,0,0);
  148. stb_textedit_cut(0,0);
  149. stb_textedit_key(0,0,0);
  150. stb_textedit_initialize_state(0,0);
  151. stb_textedit_paste(0,0,0,0);
  152. }
  153. #include "stb_c_lexer.h"