Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.9 KiB

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