Skip to content

Commit

Permalink
rect selections visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
counter185 committed Sep 10, 2024
1 parent c2cc332 commit 29f15df
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 73 deletions.
24 changes: 24 additions & 0 deletions freesprite/BaseBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,27 @@ void BaseBrush::renderOnCanvas(MainEditor* editor, int scale)
{
renderOnCanvas(editor->canvasCenterPoint, scale);
}

void BaseBrush::drawPixelRect(XY from, XY to, XY canvasDrawPoint, int scale)
{
XY pointFrom = XY{ ixmin(from.x, to.x), ixmin(from.y, to.y) };
XY pointTo = XY{ ixmax(from.x, to.x), ixmax(from.y, to.y) };
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x20);
SDL_Rect r = { canvasDrawPoint.x + (pointFrom.x * scale), canvasDrawPoint.y + (pointFrom.y * scale), ((pointTo.x - pointFrom.x + 1) * scale), ((pointTo.y - pointFrom.y + 1) * scale) };
SDL_RenderFillRect(g_rd, &r);
SDL_SetRenderDrawColor(g_rd, 0x00, 0x00, 0x00, 0x80);
SDL_Rect r2 = r;
r2.x++;
r2.y++;
r2.w -= 2;
r2.h -= 2;
SDL_RenderDrawRect(g_rd, &r2);
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x80);
SDL_RenderDrawRect(g_rd, &r);

SDL_SetRenderDrawColor(g_rd, 0x00, 0x00, 0x00, 0x80);
SDL_RenderDrawLine(g_rd, r.x, r.y + 1, r.x + r.w - 1, r.y + r.h);
//SDL_RenderDrawLine(g_rd, r.x + 1, r.y, r.x + r.w, r.y + r.h - 1);
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x80);
SDL_RenderDrawLine(g_rd, r.x, r.y, r.x + r.w, r.y + r.h);
}
2 changes: 2 additions & 0 deletions freesprite/BaseBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ class BaseBrush
//SDL_RenderDrawLine(g_rd, r.x, r.y+scale/2, r.x + scale/2-1, r.y + scale-1);
//SDL_RenderDrawLine(g_rd, r.x+scale/2, r.y, r.x + scale-1, r.y + scale/2-1);
}

void drawPixelRect(XY from, XY to, XY canvasDrawPoint, int scale);
};

6 changes: 1 addition & 5 deletions freesprite/BrushRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ void BrushRect::clickRelease(MainEditor* editor, XY pos)
void BrushRect::renderOnCanvas(XY canvasDrawPoint, int scale)
{
if (heldDown) {
XY pointFrom = XY{ ixmin(startPos.x, lastMouseMotionPos.x), ixmin(startPos.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(startPos.x, lastMouseMotionPos.x), ixmax(startPos.y, lastMouseMotionPos.y) };
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
SDL_Rect r = { canvasDrawPoint.x + (pointFrom.x * scale), canvasDrawPoint.y + (pointFrom.y * scale), ((pointTo.x - pointFrom.x + 1) * scale), ((pointTo.y - pointFrom.y + 1) * scale) };
SDL_RenderFillRect(g_rd, &r);
drawPixelRect(startPos, lastMouseMotionPos, canvasDrawPoint, scale);
}

SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down
7 changes: 1 addition & 6 deletions freesprite/BrushRectFill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ void BrushRectFill::clickRelease(MainEditor* editor, XY pos)
void BrushRectFill::renderOnCanvas(XY canvasDrawPoint, int scale)
{
if (heldDown) {
XY pointFrom = XY{ ixmin(startPos.x, lastMouseMotionPos.x), ixmin(startPos.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(startPos.x, lastMouseMotionPos.x), ixmax(startPos.y, lastMouseMotionPos.y) };
//pointTo = xyAdd(pointTo, XY{ 1,1 });
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
SDL_Rect r = { canvasDrawPoint.x + (pointFrom.x * scale), canvasDrawPoint.y + (pointFrom.y * scale), ((pointTo.x - pointFrom.x + 1) * scale), ((pointTo.y - pointFrom.y + 1) * scale) };
SDL_RenderFillRect(g_rd, &r);
drawPixelRect(startPos, lastMouseMotionPos, canvasDrawPoint, scale);
}

SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down
8 changes: 1 addition & 7 deletions freesprite/ToolMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ void ToolMeasure::clickPress(MainEditor* editor, XY pos)
void ToolMeasure::renderOnCanvas(XY canvasDrawPoint, int scale)
{
if (heldDown) {
drawPixelRect(startPos, lastMouseMotionPos, canvasDrawPoint, scale);
XY pointFrom = XY{ ixmin(startPos.x, lastMouseMotionPos.x), ixmin(startPos.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(startPos.x, lastMouseMotionPos.x), ixmax(startPos.y, lastMouseMotionPos.y) };
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x20);
SDL_Rect r = { canvasDrawPoint.x + (pointFrom.x * scale), canvasDrawPoint.y + (pointFrom.y * scale), ((pointTo.x - pointFrom.x + 1) * scale), ((pointTo.y - pointFrom.y + 1) * scale) };
SDL_RenderFillRect(g_rd, &r);
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x80);
SDL_RenderDrawRect(g_rd, &r);

SDL_RenderDrawLine(g_rd, r.x, r.y, r.x + r.w, r.y + r.h);

g_fnt->RenderString(std::format("{}px x {}px", pointTo.x - pointFrom.x + 1, pointTo.y - pointFrom.y + 1), canvasDrawPoint.x + lastMousePos.x * scale + 25, canvasDrawPoint.y + lastMousePos.y * scale);
}
Expand Down
12 changes: 1 addition & 11 deletions freesprite/ToolRectClone.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ class ToolRectClone :
bool isReadOnly() { return true; }
void renderOnCanvas(XY canvasDrawPoint, int scale) {
if (mouseDown) {
XY pointFrom = XY{ ixmin(mouseDownPoint.x, lastMouseMotionPos.x), ixmin(mouseDownPoint.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(mouseDownPoint.x, lastMouseMotionPos.x), ixmax(mouseDownPoint.y, lastMouseMotionPos.y) };
pointTo = xyAdd(pointTo, XY{ 1,1 });
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x50);
SDL_Rect cAreaRect = SDL_Rect{
canvasDrawPoint.x + pointFrom.x * scale,
canvasDrawPoint.y + pointFrom.y * scale,
(pointTo.x - pointFrom.x) * scale,
(pointTo.y - pointFrom.y) * scale
};
SDL_RenderDrawRect(g_rd, &cAreaRect);
drawPixelRect(mouseDownPoint, lastMouseMotionPos, canvasDrawPoint, scale);
}
else if (clonedArea != NULL) {
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down
13 changes: 2 additions & 11 deletions freesprite/ToolRectFlip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,9 @@ void ToolRectFlip::rightClickRelease(MainEditor* editor, XY pos)

void ToolRectFlip::renderOnCanvas(XY canvasDrawPoint, int scale) {
if (dragging) {
drawPixelRect(dragStart, lastMouseMotionPos, canvasDrawPoint, scale);
XY pointFrom = XY{ ixmin(dragStart.x, lastMouseMotionPos.x), ixmin(dragStart.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(dragStart.x, lastMouseMotionPos.x), ixmax(dragStart.y, lastMouseMotionPos.y) };
pointTo = xyAdd(pointTo, XY{ 1,1 });
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x50);
SDL_Rect cAreaRect = SDL_Rect{
canvasDrawPoint.x + pointFrom.x * scale,
canvasDrawPoint.y + pointFrom.y * scale,
(pointTo.x - pointFrom.x) * scale,
(pointTo.y - pointFrom.y) * scale
};
SDL_RenderDrawRect(g_rd, &cAreaRect);
g_fnt->RenderString(dragRightClick ? "Flip Y" : "Flip X", cAreaRect.x, cAreaRect.y);
g_fnt->RenderString(dragRightClick ? "Flip Y" : "Flip X", canvasDrawPoint.x + pointFrom.x * scale, canvasDrawPoint.y + pointFrom.y * scale );
}

SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down
12 changes: 1 addition & 11 deletions freesprite/ToolRectMove.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ class ToolRectMove :
void rightClickPress(MainEditor* editor, XY pos) override;
void renderOnCanvas(XY canvasDrawPoint, int scale) {
if (mouseDown) {
XY pointFrom = XY{ ixmin(mouseDownPoint.x, lastMouseMotionPos.x), ixmin(mouseDownPoint.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(mouseDownPoint.x, lastMouseMotionPos.x), ixmax(mouseDownPoint.y, lastMouseMotionPos.y) };
pointTo = xyAdd(pointTo, XY{ 1,1 });
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x50);
SDL_Rect cAreaRect = SDL_Rect{
canvasDrawPoint.x + pointFrom.x * scale,
canvasDrawPoint.y + pointFrom.y * scale,
(pointTo.x - pointFrom.x) * scale,
(pointTo.y - pointFrom.y) * scale
};
SDL_RenderDrawRect(g_rd, &cAreaRect);
drawPixelRect(mouseDownPoint, lastMouseMotionPos, canvasDrawPoint, scale);
}
else if (clonedArea != NULL) {
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down
13 changes: 2 additions & 11 deletions freesprite/ToolRectRotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,8 @@ void ToolRectRotate::renderOnCanvas(XY canvasDrawPoint, int scale)
point.x = dragStart.x + xdist;
point.y = dragStart.y + xdist;
XY pointFrom = XY{ ixmin(dragStart.x, point.x), ixmin(dragStart.y, point.y) };
XY pointTo = XY{ ixmax(dragStart.x, point.x), ixmax(dragStart.y, point.y) };
pointTo = xyAdd(pointTo, XY{ 1,1 });
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x50);
SDL_Rect cAreaRect = SDL_Rect{
canvasDrawPoint.x + pointFrom.x * scale,
canvasDrawPoint.y + pointFrom.y * scale,
(pointTo.x - pointFrom.x) * scale,
(pointTo.y - pointFrom.y) * scale
};
SDL_RenderDrawRect(g_rd, &cAreaRect);
g_fnt->RenderString(dragRightClick ? "Rotate -90d" : "Rotate 90d", cAreaRect.x, cAreaRect.y);
drawPixelRect(dragStart, point, canvasDrawPoint, scale);
g_fnt->RenderString(dragRightClick ? "Rotate -90d" : "Rotate 90d", canvasDrawPoint.x + pointFrom.x * scale, canvasDrawPoint.y + pointFrom.y * scale);
}

SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down
12 changes: 1 addition & 11 deletions freesprite/ToolRectSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ class ToolRectSwap : public BaseBrush
bool isReadOnly() { return true; }
void renderOnCanvas(XY canvasDrawPoint, int scale) {
if (mouseDown) {
XY pointFrom = XY{ ixmin(mouseDownPoint.x, lastMouseMotionPos.x), ixmin(mouseDownPoint.y, lastMouseMotionPos.y) };
XY pointTo = XY{ ixmax(mouseDownPoint.x, lastMouseMotionPos.x), ixmax(mouseDownPoint.y, lastMouseMotionPos.y) };
pointTo = xyAdd(pointTo, XY{ 1,1 });
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x50);
SDL_Rect cAreaRect = SDL_Rect{
canvasDrawPoint.x + pointFrom.x * scale,
canvasDrawPoint.y + pointFrom.y * scale,
(pointTo.x - pointFrom.x) * scale,
(pointTo.y - pointFrom.y) * scale
};
SDL_RenderDrawRect(g_rd, &cAreaRect);
drawPixelRect(mouseDownPoint, lastMouseMotionPos, canvasDrawPoint, scale);
}
else if (clonedArea != NULL) {
SDL_SetRenderDrawColor(g_rd, 0xff, 0xff, 0xff, 0x30);
Expand Down

0 comments on commit 29f15df

Please sign in to comment.