From 7a0b46075ca5fcd46fc6b161f84c13e4cb7d8cf4 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 17:07:57 -0500 Subject: [PATCH 1/9] Fix stbte_create_map declaration --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ed56a10..e751980 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -339,7 +339,7 @@ enum // creation // -extern stbte_tilemap *stbte_create(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); +extern stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); // create an editable tilemap // map_x : dimensions of map horizontally (user can change this in editor), <= STBTE_MAX_TILEMAP_X // map_y : dimensions of map vertically (user can change this in editor) <= STBTE_MAX_TILEMAP_Y From f82fbb2e36bcacc781561e6034813f808df1648f Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 17:55:03 -0500 Subject: [PATCH 2/9] stbte: layername button grows/shrinks Layer name buttons grow to fill box --- stb_tilemap_editor.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index e751980..0a8339b 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -938,6 +938,7 @@ struct stbte_tilemap int tileinfo_dirty; stbte__layer layerinfo[STBTE_MAX_LAYERS]; int has_layer_names; + int layername_width; int layer_scroll; int propmode; int solo_layer; @@ -1016,6 +1017,7 @@ stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacin tm->layer_scroll = 0; tm->propmode = 0; tm->has_layer_names = 0; + tm->layername_width = 0; tm->undo_available_valid = 0; for (i=0; i < tm->num_layers; ++i) { @@ -1088,12 +1090,16 @@ void stbte_define_tile(stbte_tilemap *tm, unsigned short id, unsigned int layerm tm->tileinfo_dirty = 1; } +static int stbte__text_width(const char *str); + void stbte_set_layername(stbte_tilemap *tm, int layer, const char *layername) { STBTE_ASSERT(layer >= 0 && layer < tm->num_layers); if (layer >= 0 && layer < tm->num_layers) { tm->layerinfo[layer].name = layername; tm->has_layer_names = 1; + int width = stbte__text_width(layername); + tm->layername_width = (width > tm->layername_width ? width : tm->layername_width); } } @@ -3385,7 +3391,9 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) int i, y, n; int x1 = x0+w; int y1 = y0+h; - int xoff = tm->has_layer_names ? 50 : 20; + int side = stbte__ui.panel[STBTE__layer].side; + int xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; + xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); static char *propmodes[3] = { "default", "always", "never" }; From 87faf06b5d195462a2c9b66ecc86b69febd908a2 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 18:06:40 -0500 Subject: [PATCH 3/9] stbte: update documentation/version 0.31 Changed REVISION HISTORY, TODO, CREDITS, and README --- README.md | 5 +---- stb_tilemap_editor.h | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8918d86..ad57108 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ library | lastest version | category | description **stb_textedit.h** | 1.5 | UI | guts of a text editor for games etc implementing them from scratch **stb_dxt.h** | 1.04 | 3D graphics | Fabian "ryg" Giesen's real-time DXT compressor **stb_perlin.h** | 0.2 | 3D graphics | revised Perlin noise (3D input, 1D output) -**stb_tilemap_editor.h** | 0.30 | games | embeddable tilemap editor +**stb_tilemap_editor.h** | 0.31 | games | embeddable tilemap editor **stb_herringbone_wang_tile.h** | 0.6 | games | herringbone Wang tile map generator **stb_c_lexer.h** | 0.06 | parsing | simplify writing parsers for C-like languages **stb_divide.h** | 0.91 | math | more useful 32-bit modulus e.g. "euclidean divide" @@ -82,6 +82,3 @@ for other people to use them from other languages. I still use MSVC 6 (1998) as my IDE because it has better human factors for me than later versions of MSVC. - - - diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 0a8339b..bfa0d11 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -1,4 +1,4 @@ -// stb_tilemap_editor.h - v0.30 - Sean Barrett - http://nothings.org/stb +// stb_tilemap_editor.h - v0.31 - Sean Barrett - http://nothings.org/stb // placed in the public domain - not copyrighted - first released 2014-09 // // Embeddable tilemap editor for C/C++ @@ -275,6 +275,9 @@ // either approach allows cut&pasting between levels.) // // REVISION HISTORY +// 0.31 layername button changes +// - layername buttons grow with the layer panel +// - fix stbte_create_map being declared as stbte_create // 0.30 properties release // - properties panel for editing user-defined "object" properties // - can link each tile to one other tile @@ -296,11 +299,11 @@ // Support STBTE_HITTEST_TILE above // ?Cancel drags by clicking other button? - may be fixed // Finish support for toolbar at side -// Layer name buttons grow to fill box // // CREDITS // // Written by Sean Barrett, September & October 2014. +// Contributions from Josh Huelsman, January 2015. // // LICENSE // From ba38019c9585af63fd9759879f11f764cfb26210 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 18:46:57 -0500 Subject: [PATCH 4/9] stbte: fix layername button growing for both sides --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index bfa0d11..ade6783 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3394,7 +3394,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) int i, y, n; int x1 = x0+w; int y1 = y0+h; - int side = stbte__ui.panel[STBTE__layer].side; + int side = stbte__ui.panel[STBTE__panel_layers].side; int xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); static char *propmodes[3] = { From e62a54ee0bdf88aa5c42b71790d58b95e6203b99 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 18:58:59 -0500 Subject: [PATCH 5/9] stbte: fix number rendering when no layernames set --- stb_tilemap_editor.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ade6783..ac9eaf2 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3394,9 +3394,14 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) int i, y, n; int x1 = x0+w; int y1 = y0+h; - int side = stbte__ui.panel[STBTE__panel_layers].side; - int xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; - xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); + int xoff = 20; + + if (tm->has_layer_names) { + int side = stbte__ui.panel[STBTE__panel_layers].side; + xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; + xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); + } + static char *propmodes[3] = { "default", "always", "never" }; From 6cc48214ac02181d3c771ad3dd47abd647b2517e Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 21:17:24 -0500 Subject: [PATCH 6/9] stbte: removed redundant conditional --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ac9eaf2..21dabcf 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3398,7 +3398,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) if (tm->has_layer_names) { int side = stbte__ui.panel[STBTE__panel_layers].side; - xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; + xoff = stbte__region[side].width - 42; xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); } From 3f418bfe6e4db5dd93fe93b35b55c7af7b4a745c Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 21:59:01 -0500 Subject: [PATCH 7/9] stbte: fix; prop button now draws 't' in default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prop button didn’t draw the ’t’ when the panel is expanded --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 21dabcf..cc6a398 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3443,7 +3443,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) n = stbte__text_width("prop:")+2; stbte__draw_text(x0,y+2, "prop:", w, STBTE__TEXTCOLOR(STBTE__cpanel)); i = w - n - 4; - if (i > 45) i = 45; + if (i > 50) i = 50; if (stbte__button(STBTE__clayer_button, propmodes[tm->propmode], x0+n,y,0,i, STBTE__ID(STBTE__layer,256), 0,0)) tm->propmode = (tm->propmode+1)%3; #endif From 53011a3d96761196a09ef74ac872fdb8bf9cbd91 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:10:02 -0700 Subject: [PATCH 8/9] fix declaration of stbte_create_map --- stb_tilemap_editor.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ed56a10..41d02fe 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -275,6 +275,8 @@ // either approach allows cut&pasting between levels.) // // REVISION HISTORY +// 0.31 bugfixes +// - fix declaration of stbte_create_map // 0.30 properties release // - properties panel for editing user-defined "object" properties // - can link each tile to one other tile @@ -339,7 +341,7 @@ enum // creation // -extern stbte_tilemap *stbte_create(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); +extern stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); // create an editable tilemap // map_x : dimensions of map horizontally (user can change this in editor), <= STBTE_MAX_TILEMAP_X // map_y : dimensions of map vertically (user can change this in editor) <= STBTE_MAX_TILEMAP_Y @@ -352,7 +354,7 @@ extern stbte_tilemap *stbte_create(int map_x, int map_y, int map_layers, int spa extern void stbte_define_tile(stbte_tilemap *tm, unsigned short id, unsigned int layermask, const char * category); // call this repeatedly for each tile to install the tile definitions into the editable tilemap -// tm : tilemap created by stbte_create +// tm : tilemap created by stbte_create_map // id : unique identifier for each tile, 0 <= id < 32768 // layermask : bitmask of which layers tile is allowed on: 1 = layer 0, 255 = layers 0..7 // (note that onscreen, the editor numbers the layers from 1 not 0) From 6cb8c1b624a15f4266c16ef2898b63a1db6a963f Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:17:44 -0700 Subject: [PATCH 9/9] make compile as C --- stb_tilemap_editor.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 80c6275..3cb9471 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -1,4 +1,4 @@ -// stb_tilemap_editor.h - v0.31 - Sean Barrett - http://nothings.org/stb +// stb_tilemap_editor.h - v0.35 - Sean Barrett - http://nothings.org/stb // placed in the public domain - not copyrighted - first released 2014-09 // // Embeddable tilemap editor for C/C++ @@ -275,7 +275,7 @@ // either approach allows cut&pasting between levels.) // // REVISION HISTORY -// 0.31 layername button changes +// 0.35 layername button changes // - layername buttons grow with the layer panel // - fix stbte_create_map being declared as stbte_create // - fix declaration of stbte_create_map @@ -1100,9 +1100,10 @@ void stbte_set_layername(stbte_tilemap *tm, int layer, const char *layername) { STBTE_ASSERT(layer >= 0 && layer < tm->num_layers); if (layer >= 0 && layer < tm->num_layers) { + int width; tm->layerinfo[layer].name = layername; tm->has_layer_names = 1; - int width = stbte__text_width(layername); + width = stbte__text_width(layername); tm->layername_width = (width > tm->layername_width ? width : tm->layername_width); } } @@ -3392,6 +3393,10 @@ static void stbte__info(stbte_tilemap *tm, int x0, int y0, int w, int h) static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) { + static char *propmodes[3] = { + "default", "always", "never" + }; + int num_rows; int i, y, n; int x1 = x0+w; int y1 = y0+h; @@ -3403,10 +3408,6 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); } - static char *propmodes[3] = { - "default", "always", "never" - }; - int num_rows; x0 += 2; y0 += 5; if (!tm->has_layer_names) {