Skip to content

Commit

Permalink
fix *most* tools in palettized mode
Browse files Browse the repository at this point in the history
  • Loading branch information
counter185 committed Sep 13, 2024
1 parent cf7e3ad commit 0d9914b
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion freesprite/Brush1pxLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void Brush1pxLine::clickPress(MainEditor* editor, XY pos)

void Brush1pxLine::clickRelease(MainEditor* editor, XY pos)
{
editor->DrawLine(startPos, pos, 0xFF000000 | editor->pickedColor);
editor->DrawLine(startPos, pos, editor->getActiveColor());
dragging = false;
}

Expand Down
2 changes: 1 addition & 1 deletion freesprite/Brush1pxLinePathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void Brush1pxLinePathfind::clickRelease(MainEditor* editor, XY pos)
{
std::vector<Node> pathfindResult = genAStar(editor->getCurrentLayer(), startPos, pos);
for (Node& n : pathfindResult) {
editor->SetPixel(XY{ n.x, n.y }, editor->pickedColor);
editor->SetPixel(XY{ n.x, n.y }, editor->getActiveColor());
}
//editor->DrawLine(startPos, pos, 0xFF000000 | editor->pickedColor);
dragging = false;
Expand Down
4 changes: 2 additions & 2 deletions freesprite/Brush1x1ArcX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include "maineditor.h"

void Brush1x1ArcX::clickPress(MainEditor* editor, XY pos) {
editor->SetPixel(pos, 0xFF000000 | editor->pickedColor);
editor->SetPixel(pos, editor->getActiveColor());
}

void Brush1x1ArcX::clickDrag(MainEditor* editor, XY from, XY to) {
//editor->DrawLine(from, to, 0xFF000000 | editor->pickedColor);
rasterizeLine(from, to, [&](XY a)->void {
editor->SetPixel(a, editor->pickedColor);
editor->SetPixel(a, editor->getActiveColor());
}, 1);
}
5 changes: 2 additions & 3 deletions freesprite/Brush1x1ArcY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#include "maineditor.h"

void Brush1x1ArcY::clickPress(MainEditor* editor, XY pos) {
editor->SetPixel(pos, 0xFF000000 | editor->pickedColor);
editor->SetPixel(pos, editor->getActiveColor());
}

void Brush1x1ArcY::clickDrag(MainEditor* editor, XY from, XY to) {
//editor->DrawLine(from, to, 0xFF000000 | editor->pickedColor);
rasterizeLine(from, to, [&](XY a)->void {
editor->SetPixel(a, editor->pickedColor);
editor->SetPixel(a, editor->getActiveColor());
}, 2);
}
20 changes: 10 additions & 10 deletions freesprite/Brush3pxCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

void Brush3pxCircle::clickPress(MainEditor* editor, XY pos)
{
editor->SetPixel(xyAdd(pos, XY{-1,0}), 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{1,0}), 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{0,-1}), 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{0,1}), 0xFF000000 | editor->pickedColor);
editor->SetPixel(pos, 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{-1,0}), editor->getActiveColor());
editor->SetPixel(xyAdd(pos, XY{1,0}), editor->getActiveColor());
editor->SetPixel(xyAdd(pos, XY{0,-1}), editor->getActiveColor());
editor->SetPixel(xyAdd(pos, XY{0,1}), editor->getActiveColor());
editor->SetPixel(pos, editor->getActiveColor());
}

void Brush3pxCircle::clickDrag(MainEditor* editor, XY from, XY to)
{
rasterizeLine(from, to, [editor](XY pos) {
editor->SetPixel(xyAdd(pos, XY{ -1,0 }), 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{ 1,0 }), 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{ 0,-1 }), 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{ 0,1 }), 0xFF000000 | editor->pickedColor);
editor->SetPixel(pos, 0xFF000000 | editor->pickedColor);
editor->SetPixel(xyAdd(pos, XY{ -1,0 }), editor->getActiveColor());
editor->SetPixel(xyAdd(pos, XY{ 1,0 }), editor->getActiveColor());
editor->SetPixel(xyAdd(pos, XY{ 0,-1 }), editor->getActiveColor());
editor->SetPixel(xyAdd(pos, XY{ 0,1 }), editor->getActiveColor());
editor->SetPixel(pos, editor->getActiveColor());
});
//editor->DrawLine(from, to, 0xFF000000 | editor->pickedColor);
}
Expand Down
2 changes: 1 addition & 1 deletion freesprite/BrushCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void BrushCircle::clickRelease(MainEditor* editor, XY pos)
editor->getCurrentLayer()->setPixel({posMin.x, posMax.y}, editor->pickedColor);
editor->getCurrentLayer()->setPixel({posMax.x, posMin.y}, editor->pickedColor);*/
rasterizeEllipse(posMin, posMax, [&](XY a) {
editor->SetPixel(a, editor->pickedColor);
editor->SetPixel(a, editor->getActiveColor());
});
heldDown = false;
}
Expand Down
2 changes: 1 addition & 1 deletion freesprite/BrushReplaceColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void BrushReplaceColor::clickPress(MainEditor* editor, XY pos)
{
editor->layer_replaceColor(editor->layer_getPixelAt(pos), editor->eraserMode ? 0x00000000 : editor->pickedColor);
editor->layer_replaceColor(editor->layer_getPixelAt(pos), editor->eraserMode ? (editor->isPalettized ? -1 : 0x00000000) : editor->getActiveColor());
}

void BrushReplaceColor::renderOnCanvas(MainEditor* editor, int scale)
Expand Down
2 changes: 1 addition & 1 deletion freesprite/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class Layer
void replaceColor(uint32_t from, uint32_t to) {
uint32_t* px32 = (uint32_t*)pixelData;
for (uint64_t x = 0; x < w * h; x++) {
if (px32[x] == from || ((px32[x]&0xFF000000) == 0 && (from&0xFF000000) == 0)) {
if (px32[x] == from || (!isPalettized && (px32[x]&0xFF000000) == 0 && (from&0xFF000000) == 0)) {
px32[x] = to;
}
}
Expand Down
2 changes: 1 addition & 1 deletion freesprite/ToolRectMove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ToolRectMove::clickRelease(MainEditor* editor, XY pos)
for (int y = ymin; y < ymax; y++) {
for (int x = xmin; x < xmax; x++) {
clonedArea[copyIndex++] = editor->layer_getPixelAt(XY{ x,y });
editor->SetPixel(XY{ x,y }, 0x00000000);
editor->SetPixel(XY{ x,y }, !editor->isPalettized ? 0x00000000 : -1);
}
}
cacheClonePreview = SDL_CreateTexture(g_rd, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, clonedAreaPointAndDimensions.w, clonedAreaPointAndDimensions.h);
Expand Down
2 changes: 1 addition & 1 deletion freesprite/UtilPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool CanWalkOnMapPoint(Layer* map, int x, int y, uint32_t col1, uint32_t col2) {
return false;
}
uint32_t mapPixel = map->getPixelAt(XY{ x,y });
return mapPixel == col1 || mapPixel == col2 || (mapPixel >> 24 == 0 && (col1 >> 24 == 0 || col2 >> 24 == 0));
return mapPixel == col1 || mapPixel == col2 || (!map->isPalettized && mapPixel >> 24 == 0 && (col1 >> 24 == 0 || col2 >> 24 == 0));
}

uint64_t startTime;
Expand Down

0 comments on commit 0d9914b

Please sign in to comment.