2
0

test_cpp_compilation.cpp 5.5 KB

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