added stb, more binaryout changes"
[henge/apc.git] / stb / tests / test_cpp_compilation.cpp
1 #include "stb_sprintf.h"
2 #define STB_SPRINTF_IMPLEMENTATION
3 #include "stb_sprintf.h"
4
5 #define STB_TRUETYPE_IMPLEMENTATION
6 #define STB_PERLIN_IMPLEMENTATION
7 #define STB_IMAGE_WRITE_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
17 #define STBI_MALLOC my_malloc
18 #define STBI_FREE my_free
19 #define STBI_REALLOC my_realloc
20
21 void *my_malloc(size_t) { return 0; }
22 void *my_realloc(void *, size_t) { return 0; }
23 void my_free(void *) { }
24
25 #include "stb_image.h"
26 #include "stb_rect_pack.h"
27 #include "stb_truetype.h"
28 #include "stb_image_write.h"
29 #include "stb_perlin.h"
30 #include "stb_dxt.h"
31 #include "stb_c_lexer.h"
32 #include "stb_divide.h"
33 #include "stb_herringbone_wang_tile.h"
34
35 #define STBCC_GRID_COUNT_X_LOG2 10
36 #define STBCC_GRID_COUNT_Y_LOG2 10
37 #include "stb_connected_components.h"
38
39 #define STBVOX_CONFIG_MODE 1
40 #include "stb_voxel_render.h"
41
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
47 #include "stb_easy_font.h"
48
49 #define STB_LEAKCHECK_IMPLEMENTATION
50 #include "stb_leakcheck.h"
51
52 #define STB_IMAGE_RESIZE_IMPLEMENTATION
53 #include "stb_image_resize.h"
54
55 #include "stretchy_buffer.h"
56
57
58
59 ////////////////////////////////////////////////////////////
60 //
61 // text edit
62
63 #include <stdlib.h>
64 #include <string.h> // memmove
65 #include <ctype.h> // isspace
66
67 #define STB_TEXTEDIT_CHARTYPE char
68 #define STB_TEXTEDIT_STRING text_control
69
70 // get the base type
71 #include "stb_textedit.h"
72
73 // define our editor structure
74 typedef struct
75 {
76 char *string;
77 int stringlen;
78 STB_TexteditState state;
79 } text_control;
80
81 // define the functions we need
82 void layout_func(StbTexteditRow *row, STB_TEXTEDIT_STRING *str, int start_i)
83 {
84 int remaining_chars = str->stringlen - start_i;
85 row->num_chars = remaining_chars > 20 ? 20 : remaining_chars; // should do real word wrap here
86 row->x0 = 0;
87 row->x1 = 20; // need to account for actual size of characters
88 row->baseline_y_delta = 1.25;
89 row->ymin = -1;
90 row->ymax = 0;
91 }
92
93 int delete_chars(STB_TEXTEDIT_STRING *str, int pos, int num)
94 {
95 memmove(&str->string[pos], &str->string[pos+num], str->stringlen - (pos+num));
96 str->stringlen -= num;
97 return 1; // always succeeds
98 }
99
100 int insert_chars(STB_TEXTEDIT_STRING *str, int pos, STB_TEXTEDIT_CHARTYPE *newtext, int num)
101 {
102 str->string = (char *) realloc(str->string, str->stringlen + num);
103 memmove(&str->string[pos+num], &str->string[pos], str->stringlen - pos);
104 memcpy(&str->string[pos], newtext, num);
105 str->stringlen += num;
106 return 1; // always succeeds
107 }
108
109 // define all the #defines needed
110
111 #define KEYDOWN_BIT 0x80000000
112
113 #define STB_TEXTEDIT_STRINGLEN(tc) ((tc)->stringlen)
114 #define STB_TEXTEDIT_LAYOUTROW layout_func
115 #define STB_TEXTEDIT_GETWIDTH(tc,n,i) (1) // quick hack for monospaced
116 #define STB_TEXTEDIT_KEYTOTEXT(key) (((key) & KEYDOWN_BIT) ? 0 : (key))
117 #define STB_TEXTEDIT_GETCHAR(tc,i) ((tc)->string[i])
118 #define STB_TEXTEDIT_NEWLINE '\n'
119 #define STB_TEXTEDIT_IS_SPACE(ch) isspace(ch)
120 #define STB_TEXTEDIT_DELETECHARS delete_chars
121 #define STB_TEXTEDIT_INSERTCHARS insert_chars
122
123 #define STB_TEXTEDIT_K_SHIFT 0x40000000
124 #define STB_TEXTEDIT_K_CONTROL 0x20000000
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
143 #define STB_TEXTEDIT_IMPLEMENTATION
144 #include "stb_textedit.h"
145
146