this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

#1225: added BPP buttons to the Map Editor

Nesbox 0f901520 d6dea1d9

+331 -105
+1 -1
src/core/core.c
··· 252 252 253 253 static void resetBlitSegment(tic_mem* memory) 254 254 { 255 - memory->ram.vram.blit.segment = 2; 255 + memory->ram.vram.blit.segment = TIC_DEFAULT_BLIT_MODE; 256 256 } 257 257 258 258 static const char* readMetatag(const char* code, const char* tag, const char* comment)
+214 -29
src/studio/editors/map.c
··· 23 23 #include "map.h" 24 24 #include "ext/history.h" 25 25 26 - #define SHEET_COLS (TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE) 27 - 28 26 #define MAP_WIDTH (TIC80_WIDTH) 29 27 #define MAP_HEIGHT (TIC80_HEIGHT - TOOLBAR_SIZE) 30 28 #define MAP_X (0) ··· 310 308 mx /= TIC_SPRITESIZE; 311 309 my /= TIC_SPRITESIZE; 312 310 313 - index = mx + my * SHEET_COLS; 311 + index = my * map->sheet.blit.pages * TIC_SPRITESHEET_COLS + mx + tic_blit_calc_index(&map->sheet.blit); 314 312 } 315 313 } 316 314 else ··· 334 332 } 335 333 } 336 334 335 + static void drawBppButtons(Map* map, s32 x, s32 y) 336 + { 337 + tic_mem* tic = map->tic; 338 + 339 + static const char Labels[] = "421"; 340 + 341 + for(s32 i = 0; i < sizeof Labels - 1; i++) 342 + { 343 + tic_rect rect = {x + i * TIC_ALTFONT_WIDTH, y, TIC_ALTFONT_WIDTH, TIC_FONT_HEIGHT}; 344 + tic_bpp mode = 1 << (2 - i); 345 + 346 + bool hover = false; 347 + if(checkMousePos(&rect)) 348 + { 349 + setCursor(tic_cursor_hand); 350 + hover = true; 351 + 352 + if(mode > 1) 353 + SHOW_TOOLTIP("%iBITS PER PIXEL", mode); 354 + else 355 + SHOW_TOOLTIP("%iBIT PER PIXEL", mode); 356 + 357 + if(checkMouseClick(&rect, tic_mouse_left)) 358 + { 359 + tic_blit_update_bpp(&map->sheet.blit, mode); 360 + } 361 + } 362 + 363 + const char* label = (char[]){Labels[i], '\0'}; 364 + tic_api_print(tic, label, rect.x, rect.y, 365 + mode == map->sheet.blit.mode 366 + ? tic_color_dark_grey 367 + : hover 368 + ? tic_color_grey 369 + : tic_color_light_grey, 370 + true, 1, true); 371 + } 372 + } 373 + 374 + static void drawBankButtons(Map* map, s32 x, s32 y) 375 + { 376 + tic_mem* tic = map->tic; 377 + 378 + static const u8 Icons[] = 379 + { 380 + 0b11111000, 381 + 0b10101000, 382 + 0b11111000, 383 + 0b10101000, 384 + 0b11111000, 385 + 0b00000000, 386 + 0b00000000, 387 + 0b00000000, 388 + 389 + 0b10101000, 390 + 0b11111000, 391 + 0b01110000, 392 + 0b01110000, 393 + 0b01010000, 394 + 0b00000000, 395 + 0b00000000, 396 + 0b00000000, 397 + }; 398 + 399 + enum{Size = 6}; 400 + 401 + for(s32 i = 0; i < sizeof Icons / BITS_IN_BYTE; i++) 402 + { 403 + tic_rect rect = {x + i * Size, y, Size, Size}; 404 + 405 + bool hover = false; 406 + if(checkMousePos(&rect)) 407 + { 408 + setCursor(tic_cursor_hand); 409 + hover = true; 410 + 411 + showTooltip(i ? "SPRITES" : "TILES"); 412 + 413 + if(checkMouseClick(&rect, tic_mouse_left)) 414 + { 415 + map->sheet.blit.bank = i; 416 + } 417 + } 418 + 419 + drawBitIcon(rect.x, rect.y, Icons + i * BITS_IN_BYTE, 420 + i == map->sheet.blit.bank 421 + ? tic_color_dark_grey 422 + : hover 423 + ? tic_color_grey 424 + : tic_color_light_grey); 425 + } 426 + } 427 + 428 + static void drawPagesButtons(Map* map, s32 x, s32 y) 429 + { 430 + tic_mem* tic = map->tic; 431 + 432 + enum{Width = TIC_ALTFONT_WIDTH + 1, Height = TOOLBAR_SIZE}; 433 + 434 + if(map->sheet.blit.pages > 1) 435 + { 436 + for(s32 i = 0; i < map->sheet.blit.pages; i++) 437 + { 438 + tic_rect rect = {x + i * Width - 1, y, Width, Height}; 439 + 440 + bool hover = false; 441 + if(checkMousePos(&rect)) 442 + { 443 + setCursor(tic_cursor_hand); 444 + hover = true; 445 + 446 + SHOW_TOOLTIP("PAGE %i", i); 447 + 448 + if(checkMouseClick(&rect, tic_mouse_left)) 449 + { 450 + map->sheet.blit.page = i; 451 + } 452 + } 453 + 454 + bool active = i == map->sheet.blit.page; 455 + if(active) 456 + { 457 + tic_api_rect(tic, rect.x, rect.y, Width, Height, tic_color_black); 458 + } 459 + 460 + const char* label = (char[]){i + '1', '\0'}; 461 + tic_api_print(tic, label, rect.x + 1, rect.y + 1, 462 + active 463 + ? tic_color_white 464 + : hover 465 + ? tic_color_grey 466 + : tic_color_light_grey, 467 + true, 1, true); 468 + } 469 + } 470 + } 471 + 337 472 static void drawMapToolbar(Map* map, s32 x, s32 y) 338 473 { 339 474 tic_api_rect(map->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, tic_color_white); ··· 341 476 drawTileIndex(map, TIC80_WIDTH/2 - TIC_FONT_WIDTH, y); 342 477 343 478 x = drawSheetButton(map, x, 0); 344 - x = drawFillButton(map, x, 0); 345 - x = drawSelectButton(map, x, 0); 346 - x = drawHandButton(map, x, 0); 347 - x = drawPenButton(map, x, 0); 479 + 480 + if(sheetVisible(map)) 481 + { 482 + drawBankButtons(map, 183, 1); 483 + drawBppButtons(map, 199, 1); 484 + drawPagesButtons(map, 213, 0); 485 + } 486 + else 487 + { 488 + x = drawFillButton(map, x, 0); 489 + x = drawSelectButton(map, x, 0); 490 + x = drawHandButton(map, x, 0); 491 + x = drawPenButton(map, x, 0); 348 492 349 - x = drawGridButton(map, x - 5, 0); 350 - drawWorldButton(map, x, 0); 493 + x = drawGridButton(map, x - 5, 0); 494 + drawWorldButton(map, x, 0); 495 + } 351 496 } 352 497 353 498 static void drawSheetOvr(Map* map, s32 x, s32 y) 354 499 { 355 500 if(!sheetVisible(map))return; 356 501 502 + tic_mem* tic = map->tic; 503 + const tic_blit* blit = &map->sheet.blit; 504 + 357 505 tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; 358 506 359 507 tic_api_rectb(map->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, tic_color_white); 360 508 509 + for(s32 i = 1; i < rect.h; i += 4) 510 + { 511 + if (blit->page > 0) 512 + { 513 + tic_api_pix(tic, rect.x-1, rect.y + i, tic_color_black, false); 514 + tic_api_pix(tic, rect.x-1, rect.y + i + 1, tic_color_black, false); 515 + } 516 + 517 + if (blit->page < blit->pages - 1) 518 + { 519 + tic_api_pix(tic, rect.x+rect.w, rect.y + i, tic_color_black, false); 520 + tic_api_pix(tic, rect.x+rect.w, rect.y + i + 1, tic_color_black, false); 521 + } 522 + } 523 + 361 524 { 362 525 s32 bx = map->sheet.rect.x * TIC_SPRITESIZE - 1 + x; 363 526 s32 by = map->sheet.rect.y * TIC_SPRITESIZE - 1 + y; ··· 368 531 } 369 532 } 370 533 534 + static void initBlitMode(Map* map) 535 + { 536 + tic_mem* tic = map->tic; 537 + tiles2ram(&tic->ram, getBankTiles()); 538 + tic_tool_poke4(&tic->ram.vram.blit, 0, tic_blit_calc_segment(&map->sheet.blit)); 539 + } 540 + 541 + static void resetBlitMode(tic_mem* tic) 542 + { 543 + tic_tool_poke4(&tic->ram.vram.blit, 0, TIC_DEFAULT_BLIT_MODE); 544 + } 545 + 371 546 static void drawSheetReg(Map* map, s32 x, s32 y) 372 547 { 373 548 tic_mem* tic = map->tic; ··· 414 589 } 415 590 } 416 591 417 - tiles2ram(&tic->ram, getBankTiles()); 418 - for(s32 j = 0, index = 0; j < rect.h; j += TIC_SPRITESIZE) 419 - for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) 420 - tic_api_spr(tic, index, x + i, y + j, 1, 1, NULL, 0, 1, tic_no_flip, tic_no_rotate); 592 + initBlitMode(map); 593 + tic_api_spr(tic, 0, x, y, TIC_SPRITESHEET_COLS, TIC_SPRITESHEET_COLS, NULL, 0, 1, tic_no_flip, tic_no_rotate); 594 + resetBlitMode(map->tic); 421 595 } 422 596 423 597 static void drawCursorPos(Map* map, s32 x, s32 y) ··· 454 628 455 629 for(s32 j = 0; j < map->sheet.rect.h; j++) 456 630 for(s32 i = 0; i < map->sheet.rect.w; i++) 457 - tic_api_mset(map->tic, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * SHEET_COLS); 631 + tic_api_mset(map->tic, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * TIC_SPRITESHEET_COLS); 458 632 459 633 ram2map(&map->tic->ram, map->src); 460 634 ··· 490 664 s32 sx = map->sheet.rect.x; 491 665 s32 sy = map->sheet.rect.y; 492 666 493 - tiles2ram(&tic->ram, getBankTiles()); 494 - 495 - for(s32 j = 0, ty=pos.y; j < map->sheet.rect.h; j++, ty+=TIC_SPRITESIZE) 496 - for(s32 i = 0, tx=pos.x; i < map->sheet.rect.w; i++, tx+=TIC_SPRITESIZE) 497 - tic_api_spr(tic, (sx+i) + (sy+j) * SHEET_COLS, tx, ty, 1, 1, NULL, 0, 1, tic_no_flip, tic_no_rotate); 667 + initBlitMode(map); 668 + tic_api_spr(tic, sx + map->sheet.blit.pages * sy * TIC_SPRITESHEET_COLS, pos.x, pos.y, map->sheet.rect.w, map->sheet.rect.h, NULL, 0, 1, tic_no_flip, tic_no_rotate); 669 + resetBlitMode(map->tic); 498 670 } 499 671 } 500 672 ··· 555 727 map2ram(&tic->ram, map->src); 556 728 s32 index = tic_api_mget(map->tic, tx, ty); 557 729 558 - map->sheet.rect = (tic_rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; 730 + map->sheet.rect = (tic_rect){index % TIC_SPRITESHEET_COLS, index / TIC_SPRITESHEET_COLS, 1, 1}; 559 731 } 560 732 } 561 733 ··· 653 825 mx += -map->scroll.x; 654 826 my += -map->scroll.y; 655 827 656 - tiles2ram(&tic->ram, getBankTiles()); 828 + initBlitMode(map); 829 + 657 830 for(s32 j = 0; j < h; j++) 658 831 for(s32 i = 0; i < w; i++) 659 - tic_api_spr(tic, data[i + j * w], mx + i*TIC_SPRITESIZE, my + j*TIC_SPRITESIZE, 1, 1, NULL, 0, 1, tic_no_flip, tic_no_rotate); 832 + { 833 + s32 index = data[i + j * w]; 834 + s32 sx = index % TIC_SPRITESHEET_COLS; 835 + s32 sy = index / TIC_SPRITESHEET_COLS; 836 + tic_api_spr(tic, sx + map->sheet.blit.pages * sy * TIC_SPRITESHEET_COLS, 837 + mx + i * TIC_SPRITESIZE, my + j * TIC_SPRITESIZE, 1, 1, NULL, 0, 1, tic_no_flip, tic_no_rotate); 838 + } 839 + 840 + resetBlitMode(map->tic); 660 841 } 661 842 } 662 843 ··· 786 967 787 968 static void fillMap(Map* map, s32 x, s32 y, u8 tile) 788 969 { 789 - if(tile == (map->sheet.rect.x + map->sheet.rect.y * SHEET_COLS)) return; 970 + if(tile == (map->sheet.rect.x + map->sheet.rect.y * TIC_SPRITESHEET_COLS)) return; 790 971 791 972 static FillStack stack = {NULL, NULL}; 792 973 ··· 824 1005 { 825 1006 for(s32 j = 0; j < map->sheet.rect.h; j++) 826 1007 for(s32 i = 0; i < map->sheet.rect.w; i++) 827 - tic_api_mset(map->tic, x+i, y+j, (mx+i) + (my+j) * SHEET_COLS); 1008 + tic_api_mset(map->tic, x+i, y+j, (mx+i) + (my+j) * TIC_SPRITESHEET_COLS); 828 1009 829 1010 for(s32 i = 0; i < COUNT_OF(dx); i++) 830 1011 { ··· 933 1114 tic_mem* tic = map->tic; 934 1115 935 1116 map2ram(&tic->ram, map->src); 936 - tiles2ram(&tic->ram, getBankTiles()); 1117 + 1118 + initBlitMode(map); 937 1119 tic_api_map(tic, map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, 938 1120 TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, 0, 0, 1, NULL, NULL); 1121 + resetBlitMode(map->tic); 939 1122 940 1123 if(map->canvas.grid || map->scroll.active) 941 1124 drawGrid(map); ··· 1126 1309 { 1127 1310 switch(event) 1128 1311 { 1129 - case TIC_TOOLBAR_CUT: cutToClipboard(map); break; 1130 - case TIC_TOOLBAR_COPY: copyToClipboard(map); break; 1312 + case TIC_TOOLBAR_CUT: cutToClipboard(map); break; 1313 + case TIC_TOOLBAR_COPY: copyToClipboard(map); break; 1131 1314 case TIC_TOOLBAR_PASTE: copyFromClipboard(map); break; 1132 - case TIC_TOOLBAR_UNDO: undo(map); break; 1133 - case TIC_TOOLBAR_REDO: redo(map); break; 1315 + case TIC_TOOLBAR_UNDO: undo(map); break; 1316 + case TIC_TOOLBAR_REDO: redo(map); break; 1134 1317 default: break; 1135 1318 } 1136 1319 } ··· 1205 1388 .rect = {0, 0, 1, 1}, 1206 1389 .start = {0, 0}, 1207 1390 .drag = false, 1391 + .blit = {0}, 1208 1392 }, 1209 1393 .select = 1210 1394 { ··· 1229 1413 }; 1230 1414 1231 1415 normalizeMap(&map->scroll.x, &map->scroll.y); 1416 + tic_blit_update_bpp(&map->sheet.blit, TIC_DEFAULT_BIT_DEPTH); 1232 1417 } 1233 1418 1234 1419 void freeMap(Map* map)
+4 -1
src/studio/editors/map.h
··· 23 23 #pragma once 24 24 25 25 #include "studio/studio.h" 26 + #include "tilesheet.h" 26 27 27 28 typedef struct Map Map; 28 29 ··· 31 32 tic_mem* tic; 32 33 33 34 tic_map* src; 34 - 35 + 35 36 s32 tickCounter; 36 37 37 38 enum ··· 55 56 tic_rect rect; 56 57 tic_point start; 57 58 bool drag; 59 + 60 + tic_blit blit; 58 61 } sheet; 59 62 60 63 struct
+77 -68
src/studio/editors/sprite.c
··· 29 29 #define PALETTE_COLS (TIC_PALETTE_SIZE / PALETTE_ROWS) 30 30 #define PALETTE_WIDTH (PALETTE_COLS * PALETTE_CELL_SIZE) 31 31 #define PALETTE_HEIGHT (PALETTE_ROWS * PALETTE_CELL_SIZE) 32 - #define SHEET_COLS (TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE) 33 32 34 33 enum 35 34 { ··· 53 52 memset(&sprite->select.rect, 0, sizeof(tic_rect)); 54 53 } 55 54 56 - void initTileSheet(Sprite* sprite); 57 - // VIEWPORT & INDEX BOOKKEEPING 58 - 59 - static u16 viewportToIndex(tic_bpp bpp, u8 nb_pages, u8 bank, u8 page, u16 x, u16 y) 55 + static void initTileSheet(Sprite* sprite) 60 56 { 61 - u16 sheet_w = nb_pages * SHEET_COLS, sheet_y=y; 62 - 63 - return sheet_y * sheet_w + x; 57 + sprite->sheet = tic_tilesheet_get((( sprite->blit.pages + sprite->blit.page) << 1) + sprite->blit.bank, (u8*)sprite->src); 64 58 } 65 59 66 60 static void updateIndex(Sprite* sprite) 67 61 { 68 - u8 nb_pages = sprite->nbPages; 69 - sprite->page %= nb_pages; 70 - sprite->index = viewportToIndex(sprite->bpp, sprite->nbPages, sprite->bank, sprite->page, sprite->x, sprite->y); 62 + sprite->blit.page %= sprite->blit.pages; 63 + sprite->index = sprite->y * sprite->blit.pages * TIC_SPRITESHEET_COLS + sprite->x; 71 64 // index has changed, clear selection 72 65 clearCanvasSelection(sprite); 73 66 } 74 67 75 68 static void leftViewport(Sprite* sprite) 76 69 { 77 - if (sprite->page > 0) sprite->page--; 70 + if (sprite->blit.page > 0) sprite->blit.page--; 78 71 updateIndex(sprite); 79 72 initTileSheet(sprite); 80 73 } 81 74 82 75 static void rightViewport(Sprite* sprite) 83 76 { 84 - if (sprite->page < sprite->nbPages-1) sprite->page++; 77 + if (sprite->blit.page < sprite->blit.pages-1) sprite->blit.page++; 85 78 updateIndex(sprite); 86 79 initTileSheet(sprite); 87 80 } 88 81 89 82 static void selectViewportPage(Sprite* sprite, u8 page) 90 83 { 91 - sprite->page = page; 84 + sprite->blit.page = page; 92 85 updateIndex(sprite); 93 86 initTileSheet(sprite); 94 87 } ··· 105 98 106 99 static s32 getIndexPosX(Sprite* sprite) 107 100 { 108 - return (sprite->x + sprite->page * SHEET_COLS) * TIC_SPRITESIZE; 101 + return (sprite->x + sprite->blit.page * TIC_SPRITESHEET_COLS) * TIC_SPRITESIZE; 109 102 } 110 103 111 104 static s32 getIndexPosY(Sprite* sprite) 112 105 { 113 - return (sprite->y + sprite->bank * SHEET_COLS) * TIC_SPRITESIZE; 106 + return (sprite->y + sprite->blit.bank * TIC_SPRITESHEET_COLS) * TIC_SPRITESIZE; 114 107 } 115 108 116 109 static void drawSelection(Sprite* sprite, s32 x, s32 y, s32 w, s32 h) ··· 463 456 sprite->select.rect.w * Size + 2, sprite->select.rect.h * Size + 2); 464 457 else 465 458 { 466 - static const char Format[] = "#%04i"; 467 - char buf[sizeof Format]; 468 - sprintf(buf, Format, sprite->index + sprite->bank*sprite->nbPages*TIC_BANK_SPRITES + sprite->page*SHEET_COLS); 459 + char buf[sizeof "9999"]; 460 + sprintf(buf, "#%i", sprite->index + tic_blit_calc_index(&sprite->blit)); 469 461 470 - s32 ix = x + (CANVAS_SIZE - 5*TIC_FONT_WIDTH)/2; 462 + s32 ix = x + (CANVAS_SIZE - strlen(buf) * TIC_FONT_WIDTH) / 2; 471 463 s32 iy = TIC_SPRITESIZE + 2; 472 464 tic_api_print(tic, buf, ix, iy+1, tic_color_black, true, 1, false); 473 465 tic_api_print(tic, buf, ix, iy, tic_color_white, true, 1, false); ··· 644 636 static s32 indexes[TIC_SPRITESIZE*TIC_SPRITESIZE+1]; 645 637 memset(indexes, -1, sizeof indexes); 646 638 647 - u16 sheet_cols = SHEET_COLS * sprite->nbPages; 639 + u16 sheet_cols = TIC_SPRITESHEET_COLS * sprite->blit.pages; 648 640 649 641 { 650 642 tic_rect r = {sprite->index % sheet_cols, sprite->index / sheet_cols ··· 653 645 s32 c = 0; 654 646 for(s32 j = r.y; j < r.h + r.y; j++) 655 647 for(s32 i = r.x; i < r.w + r.x; i++) 656 - indexes[c++] = (i + j * sheet_cols) + sprite->bank * TIC_BANK_SPRITES; 648 + indexes[c++] = (i + j * sheet_cols) + sprite->blit.bank * TIC_BANK_SPRITES; 657 649 } 658 650 659 651 return indexes; ··· 730 722 731 723 static void switchBitMode(Sprite* sprite, tic_bpp bpp) 732 724 { 733 - sprite->bpp = bpp; 734 - sprite->nbPages = 4 / bpp; 725 + tic_blit_update_bpp(&sprite->blit, bpp); 735 726 updateIndex(sprite); 736 727 initTileSheet(sprite); 737 728 738 - sprite->color %= 1 << sprite->bpp; 739 - sprite->color2 %= 1 << sprite->bpp; 729 + sprite->color %= 1 << sprite->blit.mode; 730 + sprite->color2 %= 1 << sprite->blit.mode; 740 731 } 741 732 742 733 static void drawBitMode(Sprite* sprite, s32 x, s32 y, s32 w, s32 h) ··· 753 744 for(s32 i = 0; i < Modes; i++) 754 745 { 755 746 tic_bpp mode = 1 << (2-i); 756 - bool current = mode == sprite->bpp; 747 + bool current = mode == sprite->blit.mode; 757 748 758 749 tic_rect rect = {centerX - SizeX / 2 + (i-1) * OffsetX, y, SizeX, SizeY}; 759 750 ··· 764 755 over = true; 765 756 766 757 if(mode > 1) 767 - SHOW_TOOLTIP("%iBITS PER PIXEL", mode) 758 + SHOW_TOOLTIP("%iBITS PER PIXEL", mode); 768 759 else 769 760 SHOW_TOOLTIP("%iBIT PER PIXEL", mode); 770 761 ··· 1105 1096 static tic_palette_dimensions getPaletteDimensions(Sprite* sprite) 1106 1097 { 1107 1098 1108 - tic_bpp bpp = sprite->bpp; 1099 + tic_bpp bpp = sprite->blit.mode; 1109 1100 1110 1101 s32 cols = bpp == tic_bpp_4 ? PALETTE_COLS : bpp == tic_bpp_2 ? 4 : 2; 1111 1102 s32 rows = bpp == tic_bpp_4 ? PALETTE_ROWS : 1; ··· 1321 1312 1322 1313 tic_api_rectb(tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, tic_color_white); 1323 1314 1324 - for(s32 i=1; i<rect.h; i+=4) { 1325 - if (sprite->page > 0) { 1315 + for(s32 i = 1; i < rect.h; i += 4) 1316 + { 1317 + if (sprite->blit.page > 0) 1318 + { 1326 1319 tic_api_pix(tic, rect.x-1, rect.y + i, tic_color_black, false); 1327 1320 tic_api_pix(tic, rect.x-1, rect.y + i + 1, tic_color_black, false); 1328 1321 } 1329 - if (sprite->page < sprite->nbPages-1) { 1322 + 1323 + if (sprite->blit.page < sprite->blit.pages - 1) 1324 + { 1330 1325 tic_api_pix(tic, rect.x+rect.w, rect.y + i, tic_color_black, false); 1331 1326 tic_api_pix(tic, rect.x+rect.w, rect.y + i + 1, tic_color_black, false); 1332 1327 } ··· 1353 1348 { 1354 1349 tic_mem* tic = sprite->tic; 1355 1350 tiles2ram(&tic->ram, sprite->src); 1356 - tic_tool_poke4(&tic->ram.vram.blit, 0, sprite->nbPages * (2 +sprite->bank) + sprite->page); 1357 - tic_api_spr(tic, 0, x, y, SHEET_COLS, SHEET_COLS, NULL, 0, 1, tic_no_flip, tic_no_rotate); 1358 - tic_tool_poke4(&tic->ram.vram.blit, 0, 2); 1351 + tic_tool_poke4(&tic->ram.vram.blit, 0, tic_blit_calc_segment(&sprite->blit)); 1352 + tic_api_spr(tic, 0, x, y, TIC_SPRITESHEET_COLS, TIC_SPRITESHEET_COLS, NULL, 0, 1, tic_no_flip, tic_no_rotate); 1353 + tic_tool_poke4(&tic->ram.vram.blit, 0, TIC_DEFAULT_BLIT_MODE); 1359 1354 } 1360 1355 1361 1356 static void flipSpriteHorz(Sprite* sprite) ··· 1683 1678 1684 1679 static void downSprite(Sprite* sprite) 1685 1680 { 1686 - if ((sprite->y + sprite->size/TIC_SPRITESIZE) < SHEET_COLS) sprite->y++; 1681 + if ((sprite->y + sprite->size/TIC_SPRITESIZE) < TIC_SPRITESHEET_COLS) sprite->y++; 1687 1682 updateIndex(sprite); 1688 1683 } 1689 1684 ··· 1695 1690 1696 1691 static void rightSprite(Sprite* sprite) 1697 1692 { 1698 - if ((sprite->x + sprite->size/TIC_SPRITESIZE) < SHEET_COLS) sprite->x++; 1693 + if ((sprite->x + sprite->size/TIC_SPRITESIZE) < TIC_SPRITESHEET_COLS) sprite->x++; 1699 1694 updateIndex(sprite); 1700 1695 } 1701 1696 ··· 1711 1706 1712 1707 static void switchBanks(Sprite* sprite) 1713 1708 { 1714 - sprite->bank = !sprite->bank; 1709 + sprite->blit.bank = !sprite->blit.bank; 1715 1710 1716 1711 updateIndex(sprite); 1717 1712 initTileSheet(sprite); 1718 1713 } 1719 1714 1720 1715 1721 - static void drawTab(tic_mem* tic, s32 x, s32 y, s32 w, s32 h, char* label, bool small_font, bool active, bool over) 1716 + static void drawTab(tic_mem* tic, s32 x, s32 y, s32 w, s32 h, const u8* icon, bool active, bool over) 1722 1717 { 1723 - u8 tab_color = active ? tic_color_white : over ? tic_color_light_grey : tic_color_dark_grey; 1724 - u8 label_color = active ? tic_color_black : tic_color_grey; 1718 + tic_color tab_color = active ? tic_color_white : over ? tic_color_light_grey : tic_color_dark_grey; 1719 + tic_color label_color = active ? tic_color_dark_grey : tic_color_grey; 1725 1720 1726 1721 tic_api_rect(tic, x+1, y, w-1, h, tab_color); 1727 1722 tic_api_line(tic, x, y+1, x, y+h-2, tab_color); 1728 1723 1729 - if (active){ 1730 - tic_api_line(tic, x+1, y + h, x + w-1, y + h, label_color); 1724 + if (active) 1725 + { 1726 + tic_api_line(tic, x+1, y + h, x + w-1, y + h, tic_color_black); 1731 1727 tic_api_pix(tic, x, y-1 + h, label_color, false); 1732 1728 } 1733 1729 1734 - tic_api_print(tic, label, x+1, y+1, label_color, false, 1, small_font); 1730 + drawBitIcon(x, y, icon, label_color); 1735 1731 } 1736 1732 1737 1733 static void drawBankTabs(Sprite* sprite, s32 x, s32 y) ··· 1740 1736 1741 1737 if(hasCanvasSelection(sprite)) return; 1742 1738 1743 - enum {Banks = 2, SizeY = 7, SizeX = 10}; 1744 - static char *labels[] = {"BG", "FG"}; 1745 - static char *tooltips[] = {"TILES [tab]", "SPRITES [tab]"}; 1739 + enum {Banks = 2, SizeY = 7, SizeX = 9}; 1740 + 1741 + static const char* tooltips[] = {"TILES [tab]", "SPRITES [tab]"}; 1742 + 1743 + static const u8 Icons[] = 1744 + { 1745 + 0b00000000, 1746 + 0b00111110, 1747 + 0b00101010, 1748 + 0b00111110, 1749 + 0b00101010, 1750 + 0b00111110, 1751 + 0b00000000, 1752 + 0b00000000, 1753 + 1754 + 0b00000000, 1755 + 0b00101010, 1756 + 0b00111110, 1757 + 0b00011100, 1758 + 0b00011100, 1759 + 0b00010100, 1760 + 0b00000000, 1761 + 0b00000000, 1762 + }; 1746 1763 1747 1764 for(s32 i = 0; i < Banks; i++) 1748 1765 { 1749 - bool current = i == sprite->bank; 1766 + bool current = i == sprite->blit.bank; 1750 1767 1751 - tic_rect rect = {x-SizeX, y + (SizeY+1)*i, SizeX, SizeY}; 1768 + tic_rect rect = {x - SizeX, y + (SizeY + 1) * i, SizeX, SizeY}; 1752 1769 1753 1770 bool over = false; 1754 1771 if(checkMousePos(&rect)) ··· 1760 1777 1761 1778 if(checkMouseClick(&rect, tic_mouse_left)) 1762 1779 { 1763 - if (!current) { 1780 + if (!current) 1781 + { 1764 1782 switchBanks(sprite); 1765 1783 } 1766 1784 } 1767 1785 } 1768 - drawTab(tic, rect.x, rect.y, SizeX, SizeY, labels[i], true, current, over); 1786 + 1787 + drawTab(tic, rect.x, rect.y, SizeX, SizeY, Icons + i * BITS_IN_BYTE, current, over); 1769 1788 } 1770 1789 } 1771 1790 ··· 1794 1813 else if(keyWasPressed(tic_key_right)) rightViewport(sprite); 1795 1814 1796 1815 else if(keyWasPressed(tic_key_tab)) 1797 - switchBitMode(sprite, sprite->bpp==4 ? 2 : sprite->bpp==2 ? 1 : 4); 1816 + switchBitMode(sprite, sprite->blit.mode==4 ? 2 : sprite->blit.mode==2 ? 1 : 4); 1798 1817 } 1799 1818 else 1800 1819 { ··· 1884 1903 } 1885 1904 1886 1905 { 1887 - u8 nbPages = sprite->nbPages; 1906 + u8 nbPages = sprite->blit.pages; 1888 1907 1889 1908 if (nbPages > 1) { 1890 1909 enum {SizeX = 7, SizeY = TOOLBAR_SIZE}; 1891 1910 1892 1911 for(s32 page = 0; page < nbPages; page++) 1893 1912 { 1894 - bool active = page == sprite->page; 1913 + bool active = page == sprite->blit.page; 1895 1914 1896 1915 tic_rect rect = {TIC80_WIDTH - 1 - 7*(nbPages-page), 0, 7, TOOLBAR_SIZE}; 1897 1916 ··· 1901 1920 setCursor(tic_cursor_hand); 1902 1921 over = true; 1903 1922 1904 - SHOW_TOOLTIP("PAGE %i", page); 1923 + SHOW_TOOLTIP("PAGE %i", page + 1); 1905 1924 1906 1925 if(checkMouseClick(&rect, tic_mouse_left)) 1907 1926 { ··· 1910 1929 } 1911 1930 1912 1931 if (active) tic_api_rect(tic, rect.x, rect.y, rect.w, rect.h, tic_color_black); 1913 - tic_api_print(tic, (char[]){'0' + page, '\0'}, rect.x+2, rect.y+1, active ? tic_color_white : tic_color_grey, false, 1, true); 1932 + tic_api_print(tic, (char[]){'1' + page, '\0'}, rect.x + 2, rect.y + 1, active ? tic_color_white : tic_color_grey, false, 1, true); 1914 1933 } 1915 1934 } 1916 1935 } ··· 2020 2039 2021 2040 if(sprite->advanced) 2022 2041 { 2023 - if(sprite->bpp == 4) 2042 + if(sprite->blit.mode == 4) 2024 2043 drawFlags(sprite, 24+64+7, 20+8); 2025 2044 2026 2045 drawBitMode(sprite, PaletteX, PaletteY + PaletteH + 2, PaletteW, 8); ··· 2040 2059 drawToolbar(tic, false); 2041 2060 } 2042 2061 2043 - void initTileSheet(Sprite* sprite) 2044 - { 2045 - tic_bpp bpp = sprite->bpp; 2046 - u8 page = sprite->page; 2047 - u8 nbPages = sprite->nbPages; 2048 - u8* src = (u8*)sprite->src; 2049 - sprite->sheet = tic_tilesheet_get((( nbPages + page) << 1) + sprite->bank, src); 2050 - } 2051 - 2052 2062 void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src) 2053 2063 { 2054 2064 if(sprite->select.back == NULL) sprite->select.back = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE); ··· 2064 2074 .x = 1, 2065 2075 .y = 0, 2066 2076 .advanced = false, 2067 - .bank = 0, 2068 - .page = 0, 2077 + .blit = {0}, 2069 2078 .color = 2, 2070 2079 .color2 = 0, 2071 2080 .size = TIC_SPRITESIZE,
+2 -4
src/studio/editors/sprite.h
··· 41 41 u8 color2; 42 42 u8 size; 43 43 u8 brushSize; 44 - tic_bpp bpp; 45 - u8 nbPages; 46 - u8 page; 47 - u8 bank; 48 44 u16 x,y; 49 45 bool advanced; 46 + 47 + tic_blit blit; 50 48 51 49 struct 52 50 {
+2 -2
src/studio/studio.h
··· 59 59 #define CART_EXT ".tic" 60 60 61 61 #define SHOW_TOOLTIP(FORMAT, ...) \ 62 - { \ 62 + do{ \ 63 63 static const char Format[] = FORMAT; \ 64 64 static char buf[sizeof Format]; \ 65 65 sprintf(buf, Format, __VA_ARGS__); \ 66 66 showTooltip(buf); \ 67 - } 67 + }while(0) 68 68 69 69 typedef enum 70 70 {
+2
src/tic.h
··· 36 36 #define TIC_SPRITESIZE 8 37 37 38 38 #define TIC_DEFAULT_BIT_DEPTH 4 39 + #define TIC_DEFAULT_BLIT_MODE 2 39 40 40 41 #define BITS_IN_BYTE 8 41 42 #define TIC_BANK_SPRITES (1 << BITS_IN_BYTE) ··· 44 45 #define TIC_SPRITES (TIC_BANK_SPRITES * TIC_SPRITE_BANKS) 45 46 46 47 #define TIC_SPRITESHEET_SIZE 128 48 + #define TIC_SPRITESHEET_COLS (TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE) 47 49 48 50 #define TIC_MAP_ROWS (TIC_SPRITESIZE) 49 51 #define TIC_MAP_COLS (TIC_SPRITESIZE)
+4
src/tilesheet.c
··· 92 92 93 93 return (tic_tileptr) { segment, offset, ptr }; 94 94 } 95 + 96 + extern s32 tic_blit_calc_segment(const tic_blit* blit); 97 + extern void tic_blit_update_bpp(tic_blit* blit, tic_bpp bpp); 98 + extern s32 tic_blit_calc_index(const tic_blit* blit);
+25
src/tilesheet.h
··· 83 83 u32 addr = tile->offset + x + (y * tile->segment->tile_width); 84 84 tile->segment->poke(tile->ptr, addr, value); 85 85 } 86 + 87 + typedef struct 88 + { 89 + tic_bpp mode; 90 + u8 pages; 91 + u8 page; 92 + u8 bank; 93 + } tic_blit; 94 + 95 + inline s32 tic_blit_calc_segment(const tic_blit* blit) 96 + { 97 + return blit->pages * (2 + blit->bank) + blit->page; 98 + } 99 + 100 + inline void tic_blit_update_bpp(tic_blit* blit, tic_bpp bpp) 101 + { 102 + blit->mode = bpp; 103 + blit->pages = 4 / bpp; 104 + blit->page %= blit->pages; 105 + } 106 + 107 + inline s32 tic_blit_calc_index(const tic_blit* blit) 108 + { 109 + return blit->bank * blit->pages * TIC_BANK_SPRITES + blit->page * TIC_SPRITESHEET_COLS; 110 + }