From 3b841c0e3f32fe57aef78353d4328d1b4fd642e9 Mon Sep 17 00:00:00 2001 From: lcgamboa Date: Sun, 21 Apr 2024 14:42:53 -0300 Subject: [PATCH] chg: Draw logic gates symbols in Logic Block Part. !minor --- share/parts/Other/Logic Block/part.map | 4 +- src/lib/draw.h | 25 +++++++ src/parts/other_logic_block.cc | 99 +++++++++++++++++++++++++- src/picsimlab1.cc | 12 ++++ src/picsimlab5.cc | 12 ++++ 5 files changed, 148 insertions(+), 4 deletions(-) diff --git a/share/parts/Other/Logic Block/part.map b/share/parts/Other/Logic Block/part.map index 9a78be7d..4fe42a0b 100644 --- a/share/parts/Other/Logic Block/part.map +++ b/share/parts/Other/Logic Block/part.map @@ -5,11 +5,11 @@ - + - + diff --git a/src/lib/draw.h b/src/lib/draw.h index 02f80b07..87cdb101 100644 --- a/src/lib/draw.h +++ b/src/lib/draw.h @@ -52,6 +52,9 @@ enum PICSimLabCanvasCmd { CC_GETBITMAPSIZE, CC_LOADIMAGE, CC_CREATEIMAGE, + CC_ARC, + CC_ELLIPTICARC, + CC_LINES, CC_LAST }; @@ -192,6 +195,28 @@ typedef struct { const int usealpha; const int orientation; } CreateImage; + struct { + bool filled; + float x1; + float y1; + float x2; + float y2; + float xc; + float yc; + } Arc; + struct { + bool filled; + float x; + float y; + float width; + float height; + double start; + double end; + } EllipticArc; + struct { + const Point_t* points; + const int npoints; + } Lines; }; } CanvasCmd_t; diff --git a/src/parts/other_logic_block.cc b/src/parts/other_logic_block.cc index f6c486cc..8cf31abe 100644 --- a/src/parts/other_logic_block.cc +++ b/src/parts/other_logic_block.cc @@ -183,9 +183,104 @@ void cpart_lblock::DrawOutput(const unsigned int i) { SpareParts.CanvasCmd({.cmd = CC_RECTANGLE, .Rectangle{1, output[i].x1 - xoff, output[i].y1, output[i].x2 - output[i].x1, output[i].y2 - output[i].y1}}); + SpareParts.CanvasCmd({.cmd = CC_SETFGCOLOR, .SetFgColor{0, 0, 0}}); - SpareParts.CanvasCmd( - {.cmd = CC_ROTATEDTEXT, .RotatedText{logicgate_name[gatetype], output[i].x1 - xoff, output[i].y1, 0}}); + SpareParts.CanvasCmd({.cmd = CC_SETBGCOLOR, .SetFgColor{250, 250, 180}}); + + switch (gatetype) { + case LG_NOT: + SpareParts.CanvasCmd({.cmd = CC_CIRCLE, .Circle{1, output[i].cx + 16 - xoff, output[i].cy + 0, 3}}); + case LG_BUFFER: { + Point_t pts[] = {{-10, -13}, {-10, 13}, {13, 0}}; + for (int p = 0; p < 3; p++) { + // offset + pts[p].x += output[i].cx - xoff; + pts[p].y += output[i].cy; + } + SpareParts.CanvasCmd({.cmd = CC_POLYGON, .Polygon{1, pts, 3}}); + + } break; + + case LG_NAND: + SpareParts.CanvasCmd({.cmd = CC_CIRCLE, .Circle{1, output[i].cx + 19 - xoff, output[i].cy + 0, 3}}); + case LG_AND: { + Point_t pts[] = {{0, -16}, {-21, -16}, {-21, 16}, {0, 16}}; + for (int p = 0; p < 4; p++) { + // offset + pts[p].x += output[i].cx - xoff; + pts[p].y += output[i].cy; + } + SpareParts.CanvasCmd({.cmd = CC_SETCOLOR, .SetColor{250, 250, 180}}); + SpareParts.CanvasCmd( + {.cmd = CC_RECTANGLE, .Rectangle{1, (float)pts[0].x, (float)pts[0].y, -21, 32}}); + SpareParts.CanvasCmd({.cmd = CC_SETFGCOLOR, .SetFgColor{0, 0, 0}}); + SpareParts.CanvasCmd({.cmd = CC_LINES, .Lines{pts, 4}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx + 0 - 16 - xoff, output[i].cy + 0 - 16, 32, 32, -90, 90}}); + } break; + case LG_NOR: + SpareParts.CanvasCmd({.cmd = CC_CIRCLE, .Circle{1, output[i].cx + 25 - xoff, output[i].cy + 0, 3}}); + case LG_OR: { + Point_t pts[] = {{-16, 16}, {-6, 16}, {-6, -16}, {-16, -16}}; + for (int p = 0; p < 4; p++) { + // offset + pts[p].x += output[i].cx - xoff; + pts[p].y += output[i].cy; + } + SpareParts.CanvasCmd({.cmd = CC_SETFGCOLOR, .SetFgColor{250, 255, 0}}); + SpareParts.CanvasCmd( + {.cmd = CC_RECTANGLE, .Rectangle{1, (float)pts[0].x, (float)pts[0].y, 14, -32}}); + SpareParts.CanvasCmd({.cmd = CC_SETFGCOLOR, .SetFgColor{0, 0, 0}}); + SpareParts.CanvasCmd({.cmd = CC_LINES, .Lines{pts, 2}}); + + SpareParts.CanvasCmd({.cmd = CC_LINES, .Lines{&pts[2], 2}}); + + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 6 - 32 - xoff, output[i].cy + 16 - 32, 64, 64, 30, 90}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 6 - 32 - xoff, output[i].cy - 16 - 32, 64, 64, 270, 330}}); + SpareParts.CanvasCmd({.cmd = CC_SETBGCOLOR, .SetBgColor{255, 255, 255}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 37 - 26 - xoff, output[i].cy - 0 - 26, 52, 52, -37, 37}}); + + } break; + case LG_XNOR: + SpareParts.CanvasCmd({.cmd = CC_CIRCLE, .Circle{1, output[i].cx + 25 - xoff, output[i].cy + 0, 3}}); + case LG_XOR: { + Point_t pts[] = {{-16, 16}, {-6, 16}, {-6, -16}, {-16, -16}}; + for (int p = 0; p < 4; p++) { + // offset + pts[p].x += output[i].cx - xoff; + pts[p].y += output[i].cy; + } + SpareParts.CanvasCmd({.cmd = CC_SETFGCOLOR, .SetFgColor{250, 255, 0}}); + SpareParts.CanvasCmd( + {.cmd = CC_RECTANGLE, .Rectangle{1, (float)pts[0].x, (float)pts[0].y, 14, -32}}); + SpareParts.CanvasCmd({.cmd = CC_SETFGCOLOR, .SetFgColor{0, 0, 0}}); + SpareParts.CanvasCmd({.cmd = CC_LINES, .Lines{pts, 2}}); + SpareParts.CanvasCmd({.cmd = CC_LINES, .Lines{&pts[2], 2}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 6 - 32 - xoff, output[i].cy + 16 - 32, 64, 64, 30, 90}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 6 - 32 - xoff, output[i].cy - 16 - 32, 64, 64, 270, 330}}); + SpareParts.CanvasCmd({.cmd = CC_SETBGCOLOR, .SetBgColor{255, 255, 255}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 37 - 26 - xoff, output[i].cy - 0 - 26, 52, 52, -37, 37}}); + SpareParts.CanvasCmd( + {.cmd = CC_ELLIPTICARC, + .EllipticArc{1, output[i].cx - 42 - 26 - xoff, output[i].cy - 0 - 26, 52, 52, -37, 37}}); + + } break; + default: + break; + } break; } } diff --git a/src/picsimlab1.cc b/src/picsimlab1.cc index b64bdf45..1a9b3802 100644 --- a/src/picsimlab1.cc +++ b/src/picsimlab1.cc @@ -1558,6 +1558,18 @@ int CPWindow1::OnCanvasCmd(const CanvasCmd_t cmd) { } return -1; } break; + case CC_ARC: + Window1.draw1.Canvas.Arc(cmd.Arc.filled, cmd.Arc.x1, cmd.Arc.y1, cmd.Arc.x2, cmd.Arc.y2, cmd.Arc.xc, + cmd.Arc.yc); + break; + case CC_ELLIPTICARC: + Window1.draw1.Canvas.EllipticArc(cmd.EllipticArc.filled, cmd.EllipticArc.x, cmd.EllipticArc.y, + cmd.EllipticArc.width, cmd.EllipticArc.height, cmd.EllipticArc.start, + cmd.EllipticArc.end); + break; + case CC_LINES: + Window1.draw1.Canvas.Lines((lxPoint*)cmd.Lines.points, cmd.Lines.npoints); + break; case CC_LAST: default: break; diff --git a/src/picsimlab5.cc b/src/picsimlab5.cc index 4f23a86c..cdff1c05 100644 --- a/src/picsimlab5.cc +++ b/src/picsimlab5.cc @@ -1077,6 +1077,18 @@ int CPWindow5::OnCanvasCmd(const CanvasCmd_t cmd) { } return -1; } break; + case CC_ARC: + Window5.Canvas[partn].Arc(cmd.Arc.filled, cmd.Arc.x1, cmd.Arc.y1, cmd.Arc.x2, cmd.Arc.y2, cmd.Arc.xc, + cmd.Arc.yc); + break; + case CC_ELLIPTICARC: + Window5.Canvas[partn].EllipticArc(cmd.EllipticArc.filled, cmd.EllipticArc.x, cmd.EllipticArc.y, + cmd.EllipticArc.width, cmd.EllipticArc.height, cmd.EllipticArc.start, + cmd.EllipticArc.end); + break; + case CC_LINES: + Window5.Canvas[partn].Lines((lxPoint*)cmd.Lines.points, cmd.Lines.npoints); + break; case CC_LAST: default: break;