121 lines
2.7 KiB
C++
121 lines
2.7 KiB
C++
//## begin module.cm preserve=no
|
|
|
|
// %X% %Q% %Z% %W%
|
|
|
|
//## end module.cm
|
|
|
|
|
|
|
|
//## begin module.cp preserve=no
|
|
|
|
//## end module.cp
|
|
|
|
|
|
|
|
//## Module: Line; Pseudo Package body
|
|
|
|
//## Subsystem: Figures
|
|
|
|
//## Source file: Line.cpp
|
|
|
|
|
|
|
|
//## begin module.additionalIncludes preserve=no
|
|
|
|
//## end module.additionalIncludes
|
|
|
|
|
|
|
|
//## begin module.includes preserve=yes
|
|
|
|
//## end module.includes
|
|
|
|
|
|
|
|
// Line
|
|
|
|
#include "Line.h"
|
|
|
|
//## begin module.additionalDeclarations preserve=yes
|
|
|
|
#include <iostream.h>
|
|
|
|
//## end module.additionalDeclarations
|
|
|
|
|
|
|
|
|
|
|
|
// Class Line
|
|
|
|
|
|
|
|
|
|
|
|
Line::Line (int x1, int y1, int x2, int y2, Color color)
|
|
|
|
//## begin Line::Line%939623930.hasinit preserve=no
|
|
|
|
//## end Line::Line%939623930.hasinit
|
|
|
|
//## begin Line::Line%939623930.initialization preserve=yes
|
|
|
|
//## end Line::Line%939623930.initialization
|
|
|
|
{
|
|
|
|
//## begin Line::Line%939623930.body preserve=yes
|
|
|
|
setColor(color);
|
|
|
|
|
|
|
|
Point start, end;
|
|
|
|
start.setx(x1);
|
|
|
|
start.sety(y1);
|
|
|
|
end.setx(x2);
|
|
|
|
end.sety(y2);
|
|
|
|
myPoints.add(myPoints.getSize(), start);
|
|
|
|
myPoints.add(myPoints.getSize(), end);
|
|
|
|
//## end Line::Line%939623930.body
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Line::~Line()
|
|
|
|
{
|
|
|
|
//## begin Line::~Line%.body preserve=yes
|
|
|
|
//## end Line::~Line%.body
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//## Other Operations (implementation)
|
|
|
|
void Line::draw (Graphics &g)
|
|
|
|
{
|
|
|
|
//## begin Line::draw%937398668.body preserve=yes
|
|
|
|
Point start,end;
|
|
|
|
int i = 0;
|
|
|
|
if(!myPoints.isEmpty())
|
|
|
|
start = myPoints.getItem(i++);
|
|
|
|
while(i < myPoints.getSize())
|
|
|
|
{
|
|
|
|
end = myPoints.getItem(i++);
|
|
|
|
g.drawLine(start.getx(),start.gety(),end.getx(),end.gety(),getColor());
|
|
|
|
start = end;
|
|
|
|
}
|
|
|
|
//## end Line::draw%937398668.body
|
|
|
|
}
|
|
|
|
|
|
|
|
void Line::erase (Graphics &g)
|
|
|
|
{
|
|
|
|
//## begin Line::erase%937398669.body preserve=yes
|
|
|
|
setColor(g.getBGColor());
|
|
|
|
draw(g);
|
|
|
|
//## end Line::erase%937398669.body
|
|
|
|
}
|
|
|
|
|
|
|
|
Figure * Line::clone ()
|
|
|
|
{
|
|
|
|
//## begin Line::clone%937398682.body preserve=yes
|
|
|
|
return new Line(*this);
|
|
|
|
//## end Line::clone%937398682.body
|
|
|
|
}
|
|
|
|
|
|
|
|
void Line::add (int x, int y)
|
|
|
|
{
|
|
|
|
//## begin Line::add%939734504.body preserve=yes
|
|
|
|
Point start;
|
|
|
|
start.setx(x);
|
|
|
|
start.sety(y);
|
|
|
|
myPoints.add(myPoints.getSize(), start);
|
|
|
|
//## end Line::add%939734504.body
|
|
|
|
}
|
|
|
|
|
|
|
|
// Additional Declarations
|
|
|
|
//## begin Line.declarations preserve=yes
|
|
|
|
//## end Line.declarations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//## begin module.epilog preserve=yes
|
|
|
|
//## end module.epilog
|
|
|
|
|
|
|
|
|
|
|
|
// Detached code regions:
|
|
|
|
// WARNING: this code will be lost if code is regenerated.
|
|
|
|
#if 0
|
|
|
|
//## begin Line::setColor%939797857.body preserve=no
|
|
|
|
color=src;
|
|
|
|
|
|
|
|
//## end Line::setColor%939797857.body
|
|
|
|
|
|
|
|
//## begin Line::getColor%939797858.body preserve=no
|
|
|
|
return color;
|
|
|
|
//## end Line::getColor%939797858.body
|
|
|
|
|
|
|
|
#endif
|
|
|