Skip to content
Myr

fix bug in paste to protected layer;

Before adoption: this commit came in with the history the project adopted, so no landing records it.

add eraser tool

authored by Sean Barrett · committed by Sean Barrett · parent 655d245 · Browse files · 1 file+63 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+63 added−26 removed

  • other:+63 added−26 removed

1 file+63 added−26 removed

modified:stb_tilemap_editor.h+63 added-26 removed
261 unmodified lines
262#if STBTE_UNDO_BUFFER_COUNT & (STBTE_UNDO_BUFFER_COUNT-1)263#error "Undo buffer size must be a power of 2"264#endif265266#define STBTE_COLOR_TOOLBAR_BACKGROUND 0x606060266#define STBTE_COLOR_TOOLBAR_BACKGROUND 0x606060 // stbte__color[STBTE__ctoolbar][STBTE__base][STBTE__idle]267#define STBTE_COLOR_TILEMAP_BACKGROUND 0x000000268#define STBTE_COLOR_TILEMAP_BORDER 0x203060269#define STBTE_COLOR_TILEMAP_HIGHLIGHT 0xffffff270#define STBTE_COLOR_PANEL_BACKGROUND 0x403010
106 unmodified lines
377enum378{379 STBTE__tool_select,380 STBTE__tool_brush,381 STBTE__tool_erase,382 STBTE__tool_rect,383 STBTE__tool_eyedrop,384 STBTE__tool_fill,385
5 unmodified lines
391 STBTE__num_tool,392};393394// icons are stored in the 0-31 range of ASCII in the font394static int toolchar[] = { 26,24,20,23,22, 19,29,28, };395static int toolchar[] = { 26,24,25,20,23,22, 19,29,28, };396397enum398{399 STBTE__paint,
1040 unmodified lines
1440 stbte__ui.alert_msg = msg;1441 stbte__ui.alert_timer = 3;1442}14431444#define STBTE__BG(tm,layer) ((layer) == 0 ? (tm)->background_tile : STBTE__NO_TILE)1445144614471448static void stbte__brush_predict(stbte_tilemap *tm, short result[])1449{1450 int layer_to_paint = tm->cur_layer;1451 stbte__tileinfo *ti;
9 unmodified lines
1461 if (!(ti->layermask & (1 << i)))1462 continue;14631464 if (i != tm->solo_layer) {1460 short bg;14611465 // if there's a selected layer, can only paint on that1466 if (tm->cur_layer >= 0 && i != tm->cur_layer)1467 continue;1468
4 unmodified lines
1473 // if the layer is locked, we can't write to it1474 if (tm->layerinfo[i].locked == STBTE__locked)1475 continue;14761474 bg = i == 0 ? tm->background_tile : STBTE__NO_TILE;1477 // if the layer is non-empty and protected, can't write to it1476 if (tm->layerinfo[i].locked == STBTE__protected && result[i] != bg)1478 if (tm->layerinfo[i].locked == STBTE__protected && result[i] != STBTE__BG(tm,i))1479 continue;1480 }14811482 result[i] = ti->id;
18 unmodified lines
1501 if (!(ti->layermask & (1 << i)))1502 continue;15031504 if (i != tm->solo_layer) {1503 short bg;15041505 // if there's a selected layer, can only paint on that1506 if (tm->cur_layer >= 0 && i != tm->cur_layer)1507 continue;1508
4 unmodified lines
1513 // if the layer is locked, we can't write to it1514 if (tm->layerinfo[i].locked == STBTE__locked)1515 continue;15161517 bg = i == 0 ? tm->background_tile : STBTE__NO_TILE;1517 // if the layer is non-empty and protected, can't write to it1519 if (tm->layerinfo[i].locked == STBTE__protected && tm->data[y][x][i] != bg)1518 if (tm->layerinfo[i].locked == STBTE__protected && tm->data[y][x][i] != STBTE__BG(tm,i))1519 continue;1520 }15211522 stbte__undo_record(tm,x,y,i,tm->data[y][x][i]);
8 unmodified lines
1531{1532 STBTE__erase_none = -1,1533 STBTE__erase_brushonly = 0,1534 STBTE__erase_any = 1,1535 STBTE__erase_all = 2,1536};15371538static int stbte__erase_predict(stbte_tilemap *tm, short result[], int allow_any)1539{
30 unmodified lines
1570 }15711572 // if multiple layers are legit, first scan all for brush data15731574 if (ti) {1574 if (ti && allow_any != STBTE__erase_all) {1575 for (i=tm->num_layers-1; i >= 0; --i) {1576 if (result[i] != ti->id)1577 continue;1578 if (tm->layerinfo[i].locked || tm->layerinfo[i].hidden)1579 continue;1580 if (i == 0 && result[i] == tm->background_tile)1581 return STBTE__erase_none;1582 result[i] = (i == 0 ? tm->background_tile : STBTE__NO_TILE);1582 result[i] = STBTE__BG(tm,i);1583 return STBTE__erase_brushonly;1584 }1585 }1586
7 unmodified lines
1594 if (tm->layerinfo[i].locked || tm->layerinfo[i].hidden)1595 continue;1596 if (i == 0 && result[i] == tm->background_tile)1597 return STBTE__erase_none;1598 result[i] = (i == 0 ? tm->background_tile : STBTE__NO_TILE);1599 return STBTE__erase_any;1598 result[i] = STBTE__BG(tm,i);1599 if (allow_any != STBTE__erase_all)1600 return STBTE__erase_any;1601 }16021603 if (allow_any == STBTE__erase_all)1604 return allow_any;1605 return STBTE__erase_none;1606}16071608
34 unmodified lines
1643 }16441645 // if multiple layers are legit, first scan all for brush data16461644 if (ti) {1647 if (ti && allow_any != STBTE__erase_all) {1648 for (i=tm->num_layers-1; i >= 0; --i) {1649 if (tm->data[y][x][i] != ti->id)1650 continue;1651 if (tm->layerinfo[i].locked || tm->layerinfo[i].hidden)1652 continue;1653 if (i == 0 && tm->data[y][x][i] == tm->background_tile)1654 return STBTE__erase_none;1655 stbte__undo_record(tm,x,y,i,tm->data[y][x][i]);1653 tm->data[y][x][i] = (i == 0 ? tm->background_tile : STBTE__NO_TILE);1656 tm->data[y][x][i] = STBTE__BG(tm,i);1657 return STBTE__erase_brushonly;1658 }1659 }1660
8 unmodified lines
1669 continue;1670 if (i == 0 && tm->data[y][x][i] == tm->background_tile)1671 return STBTE__erase_none;1672 stbte__undo_record(tm,x,y,i,tm->data[y][x][i]);1670 tm->data[y][x][i] = (i == 0 ? tm->background_tile : STBTE__NO_TILE);1671 return STBTE__erase_any;1673 tm->data[y][x][i] = STBTE__BG(tm,i);1674 if (allow_any != STBTE__erase_all)1675 return STBTE__erase_any;1676 }16731677 if (allow_any == STBTE__erase_all)1678 return allow_any;1679 return STBTE__erase_none;1680}16811682static int stbte__find_tile(stbte_tilemap *tm, int tile_id)
56 unmodified lines
1739 if (tm->solo_layer < 0) {1740 // check that we're allowed to write to it1741 if (tm->layerinfo[i].hidden) return;1742 if (tm->layerinfo[i].locked == STBTE__locked) return;1738 // if dragging w/o copy, we have to be allowed to erase1743 // if protected, dest has to be empty1744 if (tm->layerinfo[i].locked == STBTE__protected && dest[i] != STBTE__BG(tm,i)) return;1745 // if dragging w/o copy, we will try to erase stuff, which protection disallows1746 if (dragging && tm->layerinfo[i].locked == STBTE__protected)1747 return;1748 }1749 result[i] = dest[i];1743 if (src[i] != STBTE__NO_TILE)1750 if (src[i] != STBTE__BG(tm,i))1751 result[i] = src[i];1752 return;1753 }17541755 for (i=0; i < tm->num_layers; ++i) {1756 result[i] = dest[i];1757 if (src[i] != STBTE__NO_TILE) {1758 if (!tm->layerinfo[i].hidden && tm->layerinfo[i].locked != STBTE__locked)1752 if (!dragging || tm->layerinfo[i].locked == STBTE__unlocked)1759 if (tm->layerinfo[i].locked == STBTE__unlocked || (!dragging && dest[i] == STBTE__BG(tm,i)))1760 result[i] = src[i];1761 }1762 }1763}
375 unmodified lines
2139 case STBTE__rightdown:2140 if (STBTE__IS_HOT(id) && STBTE__INACTIVE()) {2141 stbte__activate(id);2142 stbte__begin_undo(tm);2136 stbte__ui.brush_state = stbte__erase(tm, mapx, mapy, 1);2143 if (stbte__erase(tm, mapx, mapy, STBTE__erase_any) == STBTE__erase_brushonly)2144 stbte__ui.brush_state = STBTE__erase_brushonly;2145 else2146 stbte__ui.brush_state = STBTE__erase_any;2147 }2148 break;2149 case STBTE__leftup:2150 case STBTE__rightup:
4 unmodified lines
2155 break;2156 }2157 break;21582159 case STBTE__tool_erase:2160 switch (stbte__ui.event) {2161 case STBTE__mousemove:2162 if (STBTE__IS_MAP_ACTIVE() && over)2163 stbte__erase(tm, mapx, mapy, STBTE__erase_all);2164 break;2165 case STBTE__leftdown:2166 if (STBTE__IS_HOT(id) && STBTE__INACTIVE()) {2167 stbte__activate(id);2168 stbte__begin_undo(tm);2169 stbte__erase(tm, mapx, mapy, STBTE__erase_all);2170 }2171 break;2172 case STBTE__leftup:2173 if (STBTE__IS_MAP_ACTIVE()) {2174 stbte__end_undo(tm);2175 stbte__activate(0);2176 }2177 break;2178 }2179 break;21802181 case STBTE__tool_select:2182 if (STBTE__IS_HOT(id)) {2183 switch (stbte__ui.event) {2184 case STBTE__leftdown:
83 unmodified lines
22682269 for (i=0; i < STBTE__num_tool; ++i) {2270 int highlight=0;2271 highlight = (stbte__ui.tool == i);2272 if (i == STBTE__tool_undo || i == STBTE__tool_grid)2273 x += 8;2274 if (i == STBTE__tool_grid && stbte__ui.show_grid)2275 highlight=1;2276 if (i == STBTE__tool_fill)2277 continue;
17 unmodified lines
2295 break;2296 }2297 }2298 x += 13;2265 if (i+1 == STBTE__tool_undo || i+1 == STBTE__tool_grid)2266 x += 8;2299 }23002301 x += 8;2302 if (stbte__button("cut" , x, y,10, 40, STBTE__ID(STBTE__toolbarB,0), 0)) {
155 unmodified lines
2458{2459 int i,x,y;2460 int num_vis_rows = (h-6) / tm->palette_spacing_y;2461 int num_columns = (w-2-6) / tm->palette_spacing_x;2430 int num_total_rows = (tm->cur_palette_count + num_columns-1) / num_columns; // ceil()2462 int num_total_rows;2463 int column,row;2464 int x1 = x0+w, y1=y0+h;2465 x = x0+2;2466 y = y0+6;24672468 if (num_columns == 0)2469 return;24702471 num_total_rows = (tm->cur_palette_count + num_columns-1) / num_columns; // ceil()24722473 column = 0;2474 row = -tm->palette_scroll; 2475 for (i=0; i < tm->num_tiles; ++i) {2476 stbte__tileinfo *t = &tm->tiles[i];
294 unmodified lines