Skip to content

Commit

Permalink
chg: Draw logic gates symbols in Logic Block Part. !minor
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Apr 21, 2024
1 parent 6003cfa commit 3b841c0
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 4 deletions.
4 changes: 2 additions & 2 deletions share/parts/Other/Logic Block/part.map
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<!-- #$-:GIMP Image Map plug-in by Maurits Rijk -->
<!-- #$-:Please do not edit lines starting with "#$" -->
<!-- #$VERSION:2.3 -->
<!-- #$AUTHOR:Luis Claudio Gamboa Lopes -->
<!-- #$AUTHOR:Luis Claudio Gamboa Lopes -->
<area shape="rect" coords="523,58,572,77" href="O_PN_9" />
<area shape="rect" coords="523,82,572,101" href="O_PN_10" />
<area shape="rect" coords="559,43,569,53" href="O_OUT" />
<area shape="rect" coords="477,20,543,39" href="O_TYPE" />
<area shape="rect" coords="469,10,551,50" href="O_TYPE" />
<area shape="rect" coords="9,82,58,101" href="O_PN_1" />
<area shape="rect" coords="14,66,24,76" href="O_IN_1" />
<area shape="rect" coords="71,82,120,101" href="O_PN_2" />
Expand Down
25 changes: 25 additions & 0 deletions src/lib/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ enum PICSimLabCanvasCmd {
CC_GETBITMAPSIZE,
CC_LOADIMAGE,
CC_CREATEIMAGE,
CC_ARC,
CC_ELLIPTICARC,
CC_LINES,
CC_LAST
};

Expand Down Expand Up @@ -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;

Expand Down
99 changes: 97 additions & 2 deletions src/parts/other_logic_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/picsimlab1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/picsimlab5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3b841c0

Please sign in to comment.