Newer
Older
{
drawJoincurveControl(fillstitch->getJoincurve(), false);
drawFillstitchControl(fillstitch, false);
}
return true;
}
OE_linkstitch* linkstitch = dynamic_cast<OE_linkstitch*> (stitch);
if (linkstitch)
const float uiSize = zoom * 7;
const float uiDistance = zoom * 17;
glPushName(0); //init the controller type index as points
glPushName(0); //init the controller points index
glPointSize(4.0f);
int index = 0;
for (auto stepPt : linkstitch->stepPts)
{
glBegin(GL_POINTS);
glEnd();
glLoadName(++index);
}
glPopName();
glLoadName(1); //init the controller type index as add
glPushName(0); //init the controller points index
glPointSize(4.0f);
std::vector<vector_2d> points = linkstitch->getPoints();
vector_2d prevVert = points.at(0);
vector_2d p;
index = 0;
std::list<vector_2d>::iterator stepPt = linkstitch->stepPts.begin();
while (stepPt != linkstitch->stepPts.end())
{
p = (*stepPt + prevVert)/2;
glBegin(GL_POINTS);
glEnd();
prevVert = *stepPt;
stepPt++;
glLoadName(++index);
}
glLoadName(index);
p = (points.at(points.size()-1) + prevVert)/2;
glBegin(GL_POINTS);
glPopName();
glLoadName(2); //init the controller type index as delete
glPushName(0); //init the controller points index
index = 0;
for (auto stepPt : linkstitch->stepPts)
{
glBegin(GL_LINES);
glVertex2f(stepPt.x-uiSize+uiDistance, stepPt.y-uiDistance);
glVertex2f(stepPt.x+uiSize+uiDistance, stepPt.y-uiDistance);
glLineWidth(2.5);
glPointSize(5.0f);
glColor4fv(style->stitchStartPointColor.rgba);
for (auto stepPt : linkstitch->stepPts)
{
glColor4fv(style->stitchControlsColor.rgba);
glVertex2f(stepPt.x-uiSize+uiDistance, stepPt.y-uiDistance);
glVertex2f(stepPt.x+uiSize+uiDistance, stepPt.y-uiDistance);
glColor4fv(style->stitchStartPointColor.rgba);
glBegin(GL_LINES);
std::vector<vector_2d> points = linkstitch->getPoints();
vector_2d prevVert = points.at(0);
vector_2d p;
std::list<vector_2d>::iterator stepPt = linkstitch->stepPts.begin();
glColor4fv(style->stitchControlsColor.rgba);
while (stepPt != linkstitch->stepPts.end())
{
p = (*stepPt + prevVert)/2;
glVertex2f(p.x-uiSize, p.y);
glVertex2f(p.x+uiSize, p.y);
glVertex2f(p.x, p.y+uiSize);
glVertex2f(p.x, p.y-uiSize);
prevVert = *stepPt;
stepPt++;
}
p = (points.at(points.size()-1) + prevVert)/2;
glVertex2f(p.x-uiSize, p.y);
glVertex2f(p.x+uiSize, p.y);
glVertex2f(p.x, p.y+uiSize);
glVertex2f(p.x, p.y-uiSize);
glEnd();
}
return true;
}
}
/** \brief draw the instruction points
*
* \return true if all is ok
*
*/
bool OE_display::drawCommands()
{
float scaleRatio = document->getPulseByMm();
if (document->instPoints.size() == 0)
return false;
unsigned i;
// Points
glPointSize(style->instPointSize);
glBegin(GL_POINTS);
glColor4fv(style->instLineBeforeCurrentColor.rgba);
for (i = 1; i < document->curPoint; i++)
{
glVertex2f(document->instPoints.at(i).x/scaleRatio, document->instPoints.at(i).y/scaleRatio);
glColor4fv(style->instLineAfterCurrentColor.rgba);
for (i = document->curPoint; i < document->instPoints.size(); i++)
{
glVertex2f(document->instPoints.at(i).x/scaleRatio, document->instPoints.at(i).y/scaleRatio);
}
glEnd();
//draw lines
unsigned pt = 0;
glLineWidth(style->instLineWidth);
glBegin(GL_LINE_STRIP);
for (; pt < document->instCommand.at(i)->getIdPoint(); pt++)
glColor4fv((curcolor*OE_color(1, 1, 1, style->instLineBeforeCurrentColor.rgba[3])).rgba);
}
glVertex2f(document->instPoints.at(pt).x/scaleRatio, document->instPoints.at(pt).y/scaleRatio);
OE_waitcolor* color = dynamic_cast<OE_waitcolor*> (document->instCommand.at(i));
if (color)
{
curcolor = color->getThreadColor();
if (pt > document->curPoint)
glColor4fv((curcolor*OE_color(1, 1, 1, style->instLineBeforeCurrentColor.rgba[3])).rgba);
}
OE_start* start = dynamic_cast<OE_start*> (document->instCommand.at(i));
if (start)
{
curcolor = start->getThreadColor();
glColor4fv((curcolor*OE_color(1, 1, 1, style->instLineBeforeCurrentColor.rgba[3])).rgba);
}
}
for (; pt < document->instPoints.size(); pt++)
glColor4fv((curcolor*OE_color(1, 1, 1, style->instLineBeforeCurrentColor.rgba[3])).rgba);
}
glVertex2f(document->instPoints.at(pt).x/scaleRatio, document->instPoints.at(pt).y/scaleRatio);
glEnd();
// start point
glColor4fv(style->instStartPointColor.rgba);
glPointSize(style->instStartPointSize);
glBegin(GL_POINTS);
glVertex2f(document->instPoints.at(0).x/scaleRatio, document->instPoints.at(0).y/scaleRatio);
glEnd();
// current point
if (document->curPoint < document->instPoints.size())
{
glColor4fv(style->instCurPointColor.rgba);
glPointSize(style->instCurPointSize);
glBegin(GL_POINTS);
glVertex2f(document->instPoints.at(document->curPoint).x/scaleRatio, document->instPoints.at(document->curPoint).y/scaleRatio);
glEnd();
}
return true;
}
/** \brief draw the document on screen
*
* \return true if all is ok
*
*/
bool OE_display::draw()
{
if (!document)
return false;
float wzoom, hzoom;
glViewport(0, 0, width, height);
glClearColor(style->backgroundColor.rgba[0], style->backgroundColor.rgba[1], style->backgroundColor.rgba[2], 1.0f);
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnd();
wzoom = (float)width*zoom;
hzoom = (float)height*zoom;
glOrtho(viewPos.x-wzoom, viewPos.x+wzoom, viewPos.y+hzoom, viewPos.y-hzoom, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glColor4ub(255,255,255,255);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
vector_2d hoopSize = document->getHoopSize()/2;
vector_2d zero = document->getZeroPoint();
//draw hoop
if (style->drawHoop)
{
glLineWidth(3);
glBegin(GL_LINE_STRIP);
glColor4fv(style->hoopColor.rgba);
glVertex2f(zero.x-hoopSize.x, zero.y-hoopSize.y);
glVertex2f(zero.x-hoopSize.x, zero.y+hoopSize.y);
glVertex2f(zero.x+hoopSize.x, zero.y+hoopSize.y);
glVertex2f(zero.x+hoopSize.x, zero.y-hoopSize.y);
glVertex2f(zero.x-hoopSize.x, zero.y-hoopSize.y);
glEnd();
}
//draw grid
if (style->drawGrid)
{
glLineWidth(1.5);
glBegin(GL_LINES);
glColor4fv((style->gridColor * OE_color(1, 1, 1, std::max(0.0f, 0.2f-zoom*2))).rgba);
int offset = (int)-hoopSize.x;
while (offset<hoopSize.x)
glVertex2f(zero.x+offset, zero.y-hoopSize.y);
glVertex2f(zero.x+offset, zero.y+hoopSize.y);
offset += 1;
}
glVertex2f(zero.x-hoopSize.x, zero.y+offset);
glVertex2f(zero.x+hoopSize.x, zero.y+offset);
offset += 1;
}
glColor4fv(style->gridColor.rgba);
offset = (int)-hoopSize.x+(int)hoopSize.x%10;
while (offset<hoopSize.x)
glVertex2f(zero.x+offset, zero.y-hoopSize.y);
glVertex2f(zero.x+offset, zero.y+hoopSize.y);
offset += 10;
}
offset = (int)-hoopSize.y+(int)hoopSize.y%10;
while (offset<hoopSize.y)
glVertex2f(zero.x-hoopSize.x, zero.y+offset);
glVertex2f(zero.x+hoopSize.x, zero.y+offset);
offset += 10;
}
glEnd();
}
//draw 0
if (style->drawZero)
float zeroSize = style->zeroSize;
glLineWidth(1.5);
glBegin(GL_LINE_STRIP);
glColor4fv(style->zeroColor.rgba);
glVertex2f(zero.x-zeroSize, zero.y);
glVertex2f(zero.x, zero.y+zeroSize);
glVertex2f(zero.x+zeroSize, zero.y);
glVertex2f(zero.x, zero.y-zeroSize);
glEnd();
glBegin(GL_LINES);
glColor4fv(style->zeroColor.rgba);
glVertex2f(zero.x-zeroSize, zero.y);
glVertex2f(zero.x+zeroSize, zero.y);
glVertex2f(zero.x, zero.y-zeroSize);
glVertex2f(zero.x, zero.y+zeroSize);
glEnd();
}
refreshAll();
document->lock();
/*if (changeDpi)
selectionBounds.init = false;
{
std::list<OE_pointcurve*>::iterator curve = document->curves.begin();
while (curve != document->curves.end())
{
curve++;
}
curve = document->selectedCurves.begin();
while (curve != document->selectedCurves.end())
{
selectionBounds += (*curve)->getBound();
curve++;
}
}
{
std::list<OE_stitchs*>::iterator stitch = document->stitchs.begin();
int curpoint = document->curPoint;
while (stitch != document->stitchs.end())
{
curpoint -= (*stitch)->getPoints().size();
stitch++;
}
stitch = document->selectedStitchs.begin();
while (stitch != document->selectedStitchs.end())
{
selectionBounds += (*stitch)->getBound();
stitch++;
}
}
drawCommands();
document->unlock();
drawSelectionTools();
return true;
}
void OE_display::pick(std::list<OE_pointcurve*> selectedCurves, std::list<OE_stitchs*> selectedStitches)
{
std::list<OE_pointcurve*>::iterator curve;
std::list<OE_stitchs*>::iterator stitch;
int index;
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
glViewport(0, 0, width, height);
glClearColor(0.85f, 0.85f, 0.85f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnd();
glOrtho(absMouse.x-7*zoom, absMouse.x+7*zoom, absMouse.y+7*zoom, absMouse.y-7*zoom, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glColor4ub(255,255,255,255);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glRenderMode(GL_SELECT);
//Init of name stack
glInitNames();
glPushName(0); //id of the tools
/* glPushName(0); //id of the zero tool
//draw 0
vector_2d zero = document->getZeroPoint();
glPointSize(6);
glBegin(GL_POINT);
glEnd();
glPopName();
*/
glPushName(1); //id of the move tool
drawSelectionTools(true);
glPopName();
//if (changeDpi)
refreshAll();
// if sitches are selectables draw their controls
{
glLoadName(1); //id of the stitches
index = 0;
glPushName(index); //init the stitches index
stitch = selectedStitches.begin();
while (stitch != selectedStitches.end())
{
stitch++;
index++;
glLoadName(index);
}
glPopName();
}
// if curves are selectables draw their controls
{
glLoadName(2); //id of the curves
index = 0;
glPushName(index); //init the curves index
curve = selectedCurves.begin();
while (curve != selectedCurves.end())
{
curve++;
index++;
glLoadName(index);
}
glPopName();
}
// if sitches are selectables draw the stitch
{
glLoadName(1); //id of the stitches
index = 0;
glPushName(index); //init the stitches index
int curpoint = document->curPoint;
stitch = document->stitchs.begin();
while (stitch != document->stitchs.end())
{
curpoint -= (*stitch)->getPoints().size();
stitch++;
index++;
glLoadName(index);
}
glPopName();
}
// if curves are selectables draw them
{
glLoadName(2); //id of the curves
index = 0;
glPushName(index); //init the curves index
curve = document->curves.begin();
while (curve != document->curves.end())
{
curve++;
index++;
glLoadName(index);
}
glPopName();
}
}
/** \brief move and zoom to see the entire document
*/
void OE_display::showAll()
{
if (document)
BoundingBox bound = document->getBound();
viewPos.x = (bound.getMax().x + bound.getMin().x)/2;
viewPos.y = (bound.getMax().y + bound.getMin().y)/2;
zoom = std::max((bound.getMax().x - bound.getMin().x)/width/1.5, (bound.getMax().y - bound.getMin().y)/height/1.5);
changeDpi = true;
void OE_display::zoomSelection()
3dsman
committed
{
if (document&&controller)
{
BoundingBox bound = controller->getSelectionBoundingBox();
viewPos.x = (bound.getMax().x + bound.getMin().x)/2;
viewPos.y = (bound.getMax().y + bound.getMin().y)/2;
zoom = std::max((bound.getMax().x - bound.getMin().x)/width/1.5, (bound.getMax().y - bound.getMin().y)/height/1.5);
changeDpi = true;
3dsman
committed
}
}
viewPos = viewPos + (mouse-vector_2d(x, y))*zoom*2;
absMouse = viewPos+(mouse-vector_2d(width, height)/2)*zoom*2;
bool redraw = false;
if (event->button() == Qt::MiddleButton)
pan = event->type() == QEvent::MouseButtonPress;
if (pan)
redraw = true;
void OE_display::scroll(double /*xoffset*/, double yoffset)
changeDpi = true;
}
void OE_display::resize(int width, int height)
{
this->width = width;
this->height = height;
}
void OE_display::keyPressEvent(QKeyEvent* event)
{
if (event->isAutoRepeat()) // does not seems to work in my VM...
return;
key(event);
}
void OE_display::keyReleaseEvent(QKeyEvent* event)
{
key(event);
}
void OE_display::key(QKeyEvent* /*event*/)
//DEBUG printf("%s \"%s\"\n", event->type()==QEvent::KeyPress?"Keypress":"Keyrelease", event->text().toStdString().c_str(), event->count()); fflush(stdout);
update(); // TODO only when necessary
vector_2d OE_display::screenToDocument(vector_2d pos)
{