Merge branch 'work2'

pull/108/head
Sean Barrett 2015-04-15 02:18:42 -07:00
commit 85c836f33c
1 changed files with 27 additions and 9 deletions

View File

@ -1,4 +1,4 @@
// stb_tilemap_editor.h - v0.30 - 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 // placed in the public domain - not copyrighted - first released 2014-09
// //
// Embeddable tilemap editor for C/C++ // Embeddable tilemap editor for C/C++
@ -275,6 +275,10 @@
// either approach allows cut&pasting between levels.) // either approach allows cut&pasting between levels.)
// //
// REVISION HISTORY // REVISION HISTORY
// 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
// 0.30 properties release // 0.30 properties release
// - properties panel for editing user-defined "object" properties // - properties panel for editing user-defined "object" properties
// - can link each tile to one other tile // - can link each tile to one other tile
@ -296,11 +300,11 @@
// Support STBTE_HITTEST_TILE above // Support STBTE_HITTEST_TILE above
// ?Cancel drags by clicking other button? - may be fixed // ?Cancel drags by clicking other button? - may be fixed
// Finish support for toolbar at side // Finish support for toolbar at side
// Layer name buttons grow to fill box
// //
// CREDITS // CREDITS
// //
// Written by Sean Barrett, September & October 2014. // Written by Sean Barrett, September & October 2014.
// Contributions from Josh Huelsman, January 2015.
// //
// LICENSE // LICENSE
// //
@ -339,7 +343,7 @@ enum
// creation // 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 // create an editable tilemap
// map_x : dimensions of map horizontally (user can change this in editor), <= STBTE_MAX_TILEMAP_X // 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 // map_y : dimensions of map vertically (user can change this in editor) <= STBTE_MAX_TILEMAP_Y
@ -352,7 +356,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); 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 // 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 // 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 // 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) // (note that onscreen, the editor numbers the layers from 1 not 0)
@ -938,6 +942,7 @@ struct stbte_tilemap
int tileinfo_dirty; int tileinfo_dirty;
stbte__layer layerinfo[STBTE_MAX_LAYERS]; stbte__layer layerinfo[STBTE_MAX_LAYERS];
int has_layer_names; int has_layer_names;
int layername_width;
int layer_scroll; int layer_scroll;
int propmode; int propmode;
int solo_layer; int solo_layer;
@ -1016,6 +1021,7 @@ stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacin
tm->layer_scroll = 0; tm->layer_scroll = 0;
tm->propmode = 0; tm->propmode = 0;
tm->has_layer_names = 0; tm->has_layer_names = 0;
tm->layername_width = 0;
tm->undo_available_valid = 0; tm->undo_available_valid = 0;
for (i=0; i < tm->num_layers; ++i) { for (i=0; i < tm->num_layers; ++i) {
@ -1088,12 +1094,17 @@ void stbte_define_tile(stbte_tilemap *tm, unsigned short id, unsigned int layerm
tm->tileinfo_dirty = 1; tm->tileinfo_dirty = 1;
} }
static int stbte__text_width(const char *str);
void stbte_set_layername(stbte_tilemap *tm, int layer, const char *layername) void stbte_set_layername(stbte_tilemap *tm, int layer, const char *layername)
{ {
STBTE_ASSERT(layer >= 0 && layer < tm->num_layers); STBTE_ASSERT(layer >= 0 && layer < tm->num_layers);
if (layer >= 0 && layer < tm->num_layers) { if (layer >= 0 && layer < tm->num_layers) {
int width;
tm->layerinfo[layer].name = layername; tm->layerinfo[layer].name = layername;
tm->has_layer_names = 1; tm->has_layer_names = 1;
width = stbte__text_width(layername);
tm->layername_width = (width > tm->layername_width ? width : tm->layername_width);
} }
} }
@ -3382,14 +3393,21 @@ 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 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;
static char *propmodes[3] = { static char *propmodes[3] = {
"default", "always", "never" "default", "always", "never"
}; };
int num_rows; int num_rows;
int i, y, n;
int x1 = x0+w;
int y1 = y0+h;
int xoff = 20;
if (tm->has_layer_names) {
int side = stbte__ui.panel[STBTE__panel_layers].side;
xoff = stbte__region[side].width - 42;
xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10);
}
x0 += 2; x0 += 2;
y0 += 5; y0 += 5;
if (!tm->has_layer_names) { if (!tm->has_layer_names) {
@ -3427,7 +3445,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h)
n = stbte__text_width("prop:")+2; n = stbte__text_width("prop:")+2;
stbte__draw_text(x0,y+2, "prop:", w, STBTE__TEXTCOLOR(STBTE__cpanel)); stbte__draw_text(x0,y+2, "prop:", w, STBTE__TEXTCOLOR(STBTE__cpanel));
i = w - n - 4; 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)) 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; tm->propmode = (tm->propmode+1)%3;
#endif #endif