Skip to content
Myr

test_cpp_compilation.cpp

This file

Path

tests/test_cpp_compilation.cpp

185 lines · 5.8 KiB · C++

Last changed by

stb_hexwave added, stretchy_buffer.h deprecatedSean Barrettbefore adoption559d759

History of this file

Take it

1#define STB_IMAGE_WRITE_STATIC2#define STBIWDEF static inline34#include "stb_image.h"5#include "stb_rect_pack.h"6#include "stb_truetype.h"7#include "stb_image_write.h"8#include "stb_perlin.h"9#include "stb_dxt.h"10#include "stb_c_lexer.h"11#include "stb_divide.h"12#include "stb_herringbone_wang_tile.h"13#include "stb_ds.h"14#include "stb_hexwave.h"1516#include "stb_sprintf.h"17#define STB_SPRINTF_IMPLEMENTATION18#include "stb_sprintf.h"192021#define STB_IMAGE_WRITE_IMPLEMENTATION22#define STB_TRUETYPE_IMPLEMENTATION23#define STB_PERLIN_IMPLEMENTATION24#define STB_DXT_IMPLEMENATION25#define STB_C_LEXER_IMPLEMENTATIOn26#define STB_DIVIDE_IMPLEMENTATION27#define STB_IMAGE_IMPLEMENTATION28#define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION29#define STB_RECT_PACK_IMPLEMENTATION30#define STB_VOXEL_RENDER_IMPLEMENTATION31#define STB_CONNECTED_COMPONENTS_IMPLEMENTATION32#define STB_HEXWAVE_IMPLEMENTATION33#define STB_DS_IMPLEMENTATION34#define STBDS_UNIT_TESTS3536#define STBI_MALLOC     my_malloc37#define STBI_FREE       my_free38#define STBI_REALLOC    my_realloc3940void *my_malloc(size_t) { return 0; }41void *my_realloc(void *, size_t) { return 0; }42void my_free(void *) { }4344#include "stb_image.h"45#include "stb_rect_pack.h"46#include "stb_truetype.h"47#include "stb_image_write.h"48#include "stb_perlin.h"49#include "stb_dxt.h"50#include "stb_c_lexer.h"51#include "stb_divide.h"52#include "stb_herringbone_wang_tile.h"53#include "stb_ds.h"54#include "stb_hexwave.h"5556#define STBCC_GRID_COUNT_X_LOG2  1057#define STBCC_GRID_COUNT_Y_LOG2  1058#include "stb_connected_components.h"5960#define STBVOX_CONFIG_MODE 161#include "stb_voxel_render.h"6263#define STBTE_DRAW_RECT(x0,y0,x1,y1,color)      do ; while(0)64#define STBTE_DRAW_TILE(x,y,id,highlight,data)  do ; while(0)65#define STB_TILEMAP_EDITOR_IMPLEMENTATION66#include "stb_tilemap_editor.h"6768#include "stb_easy_font.h"6970#define STB_LEAKCHECK_IMPLEMENTATION71#include "stb_leakcheck.h"7273#define STB_IMAGE_RESIZE_IMPLEMENTATION74#include "stb_image_resize.h"7576//#include "stretchy_buffer.h"  // deprecating777879// avoid unused-function complaints80void dummy2(void)81{82   stb_easy_font_spacing(1.0);83   stb_easy_font_print(0,0,NULL,NULL,NULL,0);84   stb_easy_font_width(NULL);85   stb_easy_font_height(NULL);86}878889////////////////////////////////////////////////////////////90//91// text edit9293#include <stdlib.h>94#include <string.h> // memmove95#include <ctype.h>  // isspace9697#define STB_TEXTEDIT_CHARTYPE   char98#define STB_TEXTEDIT_STRING     text_control99100// get the base type101#include "stb_textedit.h"102103// define our editor structure104typedef struct105{106   char *string;107   int stringlen;108   STB_TexteditState state;109} text_control;110111// define the functions we need112void layout_func(StbTexteditRow *row, STB_TEXTEDIT_STRING *str, int start_i)113{114   int remaining_chars = str->stringlen - start_i;115   row->num_chars = remaining_chars > 20 ? 20 : remaining_chars; // should do real word wrap here116   row->x0 = 0;117   row->x1 = 20; // need to account for actual size of characters118   row->baseline_y_delta = 1.25;119   row->ymin = -1;120   row->ymax =  0;121}122123int delete_chars(STB_TEXTEDIT_STRING *str, int pos, int num)124{125   memmove(&str->string[pos], &str->string[pos+num], str->stringlen - (pos+num));126   str->stringlen -= num;127   return 1; // always succeeds128}129130int insert_chars(STB_TEXTEDIT_STRING *str, int pos, STB_TEXTEDIT_CHARTYPE *newtext, int num)131{132   str->string = (char *) realloc(str->string, str->stringlen + num);133   memmove(&str->string[pos+num], &str->string[pos], str->stringlen - pos);134   memcpy(&str->string[pos], newtext, num);135   str->stringlen += num;136   return 1; // always succeeds137}138139// define all the #defines needed 140141#define KEYDOWN_BIT                    0x40000000142143#define STB_TEXTEDIT_STRINGLEN(tc)     ((tc)->stringlen)144#define STB_TEXTEDIT_LAYOUTROW         layout_func145#define STB_TEXTEDIT_GETWIDTH(tc,n,i)  (1) // quick hack for monospaced146#define STB_TEXTEDIT_KEYTOTEXT(key)    (((key) & KEYDOWN_BIT) ? 0 : (key))147#define STB_TEXTEDIT_GETCHAR(tc,i)     ((tc)->string[i])148#define STB_TEXTEDIT_NEWLINE           '\n'149#define STB_TEXTEDIT_IS_SPACE(ch)      isspace(ch)150#define STB_TEXTEDIT_DELETECHARS       delete_chars151#define STB_TEXTEDIT_INSERTCHARS       insert_chars152153#define STB_TEXTEDIT_K_SHIFT           0x20000000154#define STB_TEXTEDIT_K_CONTROL         0x10000000155#define STB_TEXTEDIT_K_LEFT            (KEYDOWN_BIT | 1) // actually use VK_LEFT, SDLK_LEFT, etc156#define STB_TEXTEDIT_K_RIGHT           (KEYDOWN_BIT | 2) // VK_RIGHT157#define STB_TEXTEDIT_K_UP              (KEYDOWN_BIT | 3) // VK_UP158#define STB_TEXTEDIT_K_DOWN            (KEYDOWN_BIT | 4) // VK_DOWN159#define STB_TEXTEDIT_K_LINESTART       (KEYDOWN_BIT | 5) // VK_HOME160#define STB_TEXTEDIT_K_LINEEND         (KEYDOWN_BIT | 6) // VK_END161#define STB_TEXTEDIT_K_TEXTSTART       (STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_CONTROL)162#define STB_TEXTEDIT_K_TEXTEND         (STB_TEXTEDIT_K_LINEEND   | STB_TEXTEDIT_K_CONTROL)163#define STB_TEXTEDIT_K_DELETE          (KEYDOWN_BIT | 7) // VK_DELETE164#define STB_TEXTEDIT_K_BACKSPACE       (KEYDOWN_BIT | 8) // VK_BACKSPACE165#define STB_TEXTEDIT_K_UNDO            (KEYDOWN_BIT | STB_TEXTEDIT_K_CONTROL | 'z')166#define STB_TEXTEDIT_K_REDO            (KEYDOWN_BIT | STB_TEXTEDIT_K_CONTROL | 'y')167#define STB_TEXTEDIT_K_INSERT          (KEYDOWN_BIT | 9) // VK_INSERT168#define STB_TEXTEDIT_K_WORDLEFT        (STB_TEXTEDIT_K_LEFT  | STB_TEXTEDIT_K_CONTROL)169#define STB_TEXTEDIT_K_WORDRIGHT       (STB_TEXTEDIT_K_RIGHT | STB_TEXTEDIT_K_CONTROL)170#define STB_TEXTEDIT_K_PGUP            (KEYDOWN_BIT | 10) // VK_PGUP -- not implemented171#define STB_TEXTEDIT_K_PGDOWN          (KEYDOWN_BIT | 11) // VK_PGDOWN -- not implemented172173#define STB_TEXTEDIT_IMPLEMENTATION174#include "stb_textedit.h"175176177void dummy3(void)178{179  stb_textedit_click(0,0,0,0);180  stb_textedit_drag(0,0,0,0);181  stb_textedit_cut(0,0);182  stb_textedit_key(0,0,0);183  stb_textedit_initialize_state(0,0);184  stb_textedit_paste(0,0,0,0);185}