@ -1,4 +1,4 @@
// stb_tilemap_editor.h - v0.41 - Sean Barrett - http://nothings.org/stb
// stb_tilemap_editor.h - v0.42 - 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,7 @@
// either approach allows cut&pasting between levels.)
//
// REVISION HISTORY
// 0.42 fix compilation errors
// 0.41 fix warnings
// 0.40 fix warning
// 0.39 fix warning
@ -317,6 +318,8 @@
// Bugfixes:
// Ryan Whitworth
// Eugene Opalev
// Rob Loach
// github:wernsey
//
// LICENSE
//
@ -1821,6 +1824,8 @@ static int stbte__button(int colormode, const char *label, int x, int y, int tex
int x0 = x , y0 = y , x1 = x + width , y1 = y + STBTE__BUTTON_HEIGHT ;
int s = STBTE__BUTTON_INTERNAL_SPACING ;
if ( ! disabled ) stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
if ( stbte__ui . event = = STBTE__paint )
stbte__draw_textbox ( x0 , y0 , x1 , y1 , ( char * ) label , s + textoff , s , colormode , STBTE__INDEX_FOR_ID ( id , disabled , toggled ) ) ;
if ( disabled )
@ -1833,6 +1838,8 @@ static int stbte__button_icon(int colormode, char ch, int x, int y, int width, i
int x0 = x , y0 = y , x1 = x + width , y1 = y + STBTE__BUTTON_HEIGHT ;
int s = STBTE__BUTTON_INTERNAL_SPACING ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
if ( stbte__ui . event = = STBTE__paint ) {
char label [ 2 ] = { ch , 0 } ;
int pad = ( 9 - stbte__get_char_width ( ch ) ) / 2 ;
@ -1846,6 +1853,7 @@ static int stbte__button_icon(int colormode, char ch, int x, int y, int width, i
static int stbte__minibutton ( int colormode , int x , int y , int ch , int id )
{
int x0 = x , y0 = y , x1 = x + 8 , y1 = y + 7 ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
if ( stbte__ui . event = = STBTE__paint ) {
char str [ 2 ] = { ( char ) ch , 0 } ;
stbte__draw_textbox ( x0 , y0 , x1 , y1 , str , 1 , 0 , colormode , STBTE__INDEX_FOR_ID ( id , 0 , 0 ) ) ;
@ -1856,6 +1864,7 @@ static int stbte__minibutton(int colormode, int x, int y, int ch, int id)
static int stbte__layerbutton ( int x , int y , int ch , int id , int toggled , int disabled , int colormode )
{
int x0 = x , y0 = y , x1 = x + 10 , y1 = y + 11 ;
if ( ! disabled ) stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
if ( stbte__ui . event = = STBTE__paint ) {
char str [ 2 ] = { ( char ) ch , 0 } ;
int off = ( 9 - stbte__get_char_width ( ch ) ) / 2 ;
@ -1869,6 +1878,7 @@ static int stbte__layerbutton(int x, int y, int ch, int id, int toggled, int dis
static int stbte__microbutton ( int x , int y , int size , int id , int colormode )
{
int x0 = x , y0 = y , x1 = x + size , y1 = y + size ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
if ( stbte__ui . event = = STBTE__paint ) {
stbte__draw_box ( x0 , y0 , x1 , y1 , colormode , STBTE__INDEX_FOR_ID ( id , 0 , 0 ) ) ;
}
@ -1878,6 +1888,7 @@ static int stbte__microbutton(int x, int y, int size, int id, int colormode)
static int stbte__microbutton_dragger ( int x , int y , int size , int id , int * pos )
{
int x0 = x , y0 = y , x1 = x + size , y1 = y + size ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
switch ( stbte__ui . event ) {
case STBTE__paint :
stbte__draw_box ( x0 , y0 , x1 , y1 , STBTE__cexpander , STBTE__INDEX_FOR_ID ( id , 0 , 0 ) ) ;
@ -1908,6 +1919,8 @@ static int stbte__category_button(const char *label, int x, int y, int width, in
int x0 = x , y0 = y , x1 = x + width , y1 = y + STBTE__BUTTON_HEIGHT ;
int s = STBTE__BUTTON_INTERNAL_SPACING ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
if ( stbte__ui . event = = STBTE__paint )
stbte__draw_textbox ( x0 , y0 , x1 , y1 , ( char * ) label , s , s , STBTE__ccategory_button , STBTE__INDEX_FOR_ID ( id , 0 , toggled ) ) ;
@ -1927,6 +1940,7 @@ static int stbte__slider(int x0, int w, int y, int range, int *value, int id)
{
int x1 = x0 + w ;
int pos = * value * w / ( range + 1 ) ;
stbte__hittest ( x0 , y - 2 , x1 , y + 3 , id ) ;
int event_mouse_move = STBTE__change ;
switch ( stbte__ui . event ) {
case STBTE__paint :
@ -1969,6 +1983,7 @@ static int stbte__float_control(int x0, int y0, int w, float minv, float maxv, f
{
int x1 = x0 + w ;
int y1 = y0 + 11 ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
switch ( stbte__ui . event ) {
case STBTE__paint : {
char text [ 32 ] ;
@ -1980,7 +1995,7 @@ static int stbte__float_control(int x0, int y0, int w, float minv, float maxv, f
case STBTE__rightdown :
if ( STBTE__IS_HOT ( id ) & & STBTE__INACTIVE ( ) )
stbte__activate ( id ) ;
return STBTE__begin ;
return STBTE__begin ;
break ;
case STBTE__leftup :
case STBTE__rightup :
@ -2020,7 +2035,6 @@ static int stbte__float_control(int x0, int y0, int w, float minv, float maxv, f
static void stbte__scrollbar ( int x , int y0 , int y1 , int * val , int v0 , int v1 , int num_vis , int id )
{
int over ;
int thumbpos ;
if ( v1 - v0 < = num_vis )
return ;
@ -2029,7 +2043,7 @@ static void stbte__scrollbar(int x, int y0, int y1, int *val, int v0, int v1, in
thumbpos = y0 + 2 + ( y1 - y0 - 4 ) * * val / ( v1 - v0 - num_vis ) ;
if ( thumbpos < y0 ) thumbpos = y0 ;
if ( thumbpos > = y1 ) thumbpos = y1 ;
over = stbte__hittest ( x - 1 , y0 , x + 2 , y1 , id ) ;
stbte__hittest ( x - 1 , y0 , x + 2 , y1 , id ) ;
switch ( stbte__ui . event ) {
case STBTE__paint :
stbte__draw_rect ( x , y0 , x + 1 , y1 , stbte__color_table [ STBTE__cscrollbar ] [ STBTE__text ] [ STBTE__idle ] ) ;
@ -2807,6 +2821,10 @@ static void stbte__drag_update(stbte_tilemap *tm, int mapx, int mapy, int copy_p
int ox , oy , i , deleted = 0 , written = 0 ;
short temp [ STBTE_MAX_LAYERS ] ;
short * data = NULL ;
STBTE__NOTUSED ( deleted ) ;
STBTE__NOTUSED ( written ) ;
if ( ! stbte__ui . shift ) {
ox = mapx - stbte__ui . drag_x ;
oy = mapy - stbte__ui . drag_y ;
@ -2928,6 +2946,9 @@ static void stbte__tile_paint(stbte_tilemap *tm, int sx, int sy, int mapx, int m
{
int i ;
int id = STBTE__IDMAP ( mapx , mapy ) ;
int x0 = sx , y0 = sy ;
int x1 = sx + tm - > spacing_x , y1 = sy + tm - > spacing_y ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
short * data = tm - > data [ mapy ] [ mapx ] ;
short temp [ STBTE_MAX_LAYERS ] ;
@ -2996,7 +3017,7 @@ static void stbte__tile_paint(stbte_tilemap *tm, int sx, int sy, int mapx, int m
i = layer ;
if ( i = = tm - > solo_layer | | ( ! tm - > layerinfo [ i ] . hidden & & tm - > solo_layer < 0 ) )
if ( data [ i ] > = 0 )
STBTE_DRAW_TILE ( x0 , y0 , ( unsigned short ) data [ i ] , 0 , tm - > props [ mapy ] [ mapx ] ) ;
STBTE_DRAW_TILE ( s x, s y, ( unsigned short ) data [ i ] , 0 , tm - > props [ mapy ] [ mapx ] ) ;
}
}
@ -3492,11 +3513,14 @@ static void stbte__categories(stbte_tilemap *tm, int x0, int y0, int w, int h)
static void stbte__tile_in_palette ( stbte_tilemap * tm , int x , int y , int slot )
{
stbte__tileinfo * t = & tm - > tiles [ slot ] ;
int x0 = x , y0 = y , x1 = x + tm - > palette_spacing_x - 1 , y1 = y + tm - > palette_spacing_y ;
int id = STBTE__ID ( STBTE__palette , slot ) ;
stbte__hittest ( x0 , y0 , x1 , y1 , id ) ;
switch ( stbte__ui . event ) {
case STBTE__paint :
stbte__draw_rect ( x , y , x + tm - > palette_spacing_x - 1 , y + tm - > palette_spacing_x - 1 , STBTE_COLOR_TILEPALETTE_BACKGROUND ) ;
STBTE_DRAW_TILE ( x , y , t - > id , slot = = tm - > cur_tile , 0 ) ;
STBTE_DRAW_TILE ( x , y , id , slot = = tm - > cur_tile , 0 ) ;
if ( slot = = tm - > cur_tile )
stbte__draw_frame_delayed ( x - 1 , y - 1 , x + tm - > palette_spacing_x , y + tm - > palette_spacing_y , STBTE_COLOR_TILEPALETTE_OUTLINE ) ;
break ;
@ -3565,6 +3589,7 @@ static void stbte__props_panel(stbte_tilemap *tm, int x0, int y0, int w, int h)
my = stbte__ui . select_y0 ;
p = tm - > props [ my ] [ mx ] ;
data = tm - > data [ my ] [ mx ] ;
STBTE__NOTUSED ( data ) ;
for ( i = 0 ; i < STBTE_MAX_PROPERTIES ; + + i ) {
unsigned int n = STBTE_PROP_TYPE ( i , data , p ) ;
if ( n ) {
@ -3644,8 +3669,9 @@ static void stbte__props_panel(stbte_tilemap *tm, int x0, int y0, int w, int h)
}
}
static int stbte__cp_mode , stbte__cp_aspect , stbte__cp_state , stbte__cp_index , stbte__ save , stbte__cp_altered , stbte__color_copy ;
static int stbte__cp_mode , stbte__cp_aspect , stbte__save , stbte__cp_altered ;
# ifdef STBTE__COLORPICKER
static int stbte__cp_state , stbte__cp_index , stbte__color_copy ;
static void stbte__dump_colorstate ( void )
{
int i , j , k ;