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