void CSVGBuffer:: beginDraw(int w, int h, const CBBox2D &bbox) { renderer_->setSize(w, h); renderer_->beginDraw(); renderer_->setDataRange(bbox.getXMin(), bbox.getYMin(), bbox.getXMax(), bbox.getYMax()); }
void CSVGBuffer:: setup(const CBBox2D &bbox) { reset(); CSVGRenderer *renderer = getRenderer(); double x1 = bbox.getXMin(); double y1 = bbox.getYMin(); double x2 = bbox.getXMax(); double y2 = bbox.getYMax(); renderer->setSize(x2 - x1, y2 - y1); renderer->setDataRange(x1, y2, x2, x1); }
void CQIllustratorAlignMode:: align(CQIllustrator::AlignSide side, bool commit) { CQIllustratorSelectedShapes *selection = illustrator_->getSelection(); if (selection->empty()) return; //------ if (illustrator_->getFlipY()) { if (side == CQIllustrator::ALIGN_BOTTOM) side = CQIllustrator::ALIGN_TOP; else if (side == CQIllustrator::ALIGN_TOP ) side = CQIllustrator::ALIGN_BOTTOM; } //------ CQIllustratorShape *ashape = 0; CBBox2D abbox; CBBox2D bbbox; bool afixed = false; CQIllustratorAlignToolbar::AnchorMode anchorMode = toolbar_->getAnchorMode(); if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::SELECTION) { // get anchor shape for side CQIllustratorSelectedShapes::iterator ps1, ps2; ps1 = selection->begin(); ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); bbbox += shape->getFlatBBox(); } ps1 = selection->begin(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); const CBBox2D &bbox = shape->getFlatBBox(); if (! abbox.isSet() || (! afixed && shape->getFixed())) { ashape = shape; abbox = bbox; afixed = ashape->getFixed(); continue; } if (afixed && ! shape->getFixed()) continue; if ((side == CQIllustrator::ALIGN_LEFT && bbox.getXMin() < abbox.getXMin()) || (side == CQIllustrator::ALIGN_BOTTOM && bbox.getYMin() < abbox.getYMin()) || (side == CQIllustrator::ALIGN_RIGHT && bbox.getXMax() > abbox.getXMax()) || (side == CQIllustrator::ALIGN_TOP && bbox.getYMax() > abbox.getYMax()) || (side == CQIllustrator::ALIGN_HORIZONTAL && bbox.getYMid() < abbox.getYMid()) || (side == CQIllustrator::ALIGN_VERTICAL && bbox.getXMid() < abbox.getXMid())) { ashape = shape; abbox = bbox; afixed = ashape->getFixed(); } } } else if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::OBJECT) { CQIllustratorShape *shape = illustrator_->getShape(toolbar_->getAnchorObject().toStdString()); if (shape == 0) return; CQIllustratorAlignToolbar::ObjectEdgeType edgeType = toolbar_->getAnchorObjectEdgeType(); abbox = shape->getFlatBBox(); if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::LEFT_BOTTOM) abbox = CBBox2D(abbox.getLL(), abbox.getLR()); else if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::RIGHT_TOP) abbox = CBBox2D(abbox.getUR(), abbox.getUR()); else if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::MIDDLE) abbox = CBBox2D(abbox.getCenter(), abbox.getCenter()); bbbox = abbox; } else if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::POSITION) { QPointF pos = toolbar_->getAnchorPosition(); abbox = CBBox2D(CQUtil::fromQPoint(pos), CQUtil::fromQPoint(pos)); CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); const CBBox2D &bbox = shape->getFlatBBox(); bbbox += bbox; } } else return; // align double offset = toolbar_->getOffset(); if (commit) { illustrator_->startUndoGroup("Align"); CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); if (shape->getFixed()) continue; const CBBox2D &bbox = shape->getFlatBBox(); double dx = 0.0, dy = 0.0; if (shape != ashape) { if (side == CQIllustrator::ALIGN_LEFT ) dx = abbox.getXMin() - bbox.getXMin(); else if (side == CQIllustrator::ALIGN_BOTTOM ) dy = abbox.getYMin() - bbox.getYMin(); else if (side == CQIllustrator::ALIGN_RIGHT ) dx = abbox.getXMax() - bbox.getXMax(); else if (side == CQIllustrator::ALIGN_TOP ) dy = abbox.getYMax() - bbox.getYMax(); else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy = abbox.getYMid() - bbox.getYMid(); else if (side == CQIllustrator::ALIGN_VERTICAL ) dx = abbox.getXMid() - bbox.getXMid(); } if (side == CQIllustrator::ALIGN_LEFT ) dx += offset; else if (side == CQIllustrator::ALIGN_BOTTOM ) dy += offset; else if (side == CQIllustrator::ALIGN_RIGHT ) dx -= offset; else if (side == CQIllustrator::ALIGN_TOP ) dy -= offset; else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy += offset; else if (side == CQIllustrator::ALIGN_VERTICAL ) dx += offset; shape->moveBy(CPoint2D(dx, dy)); } illustrator_->endUndoGroup(); illustrator_->setDimmed(false); illustrator_->clearPreviewObjects(); illustrator_->redraw(); } else { illustrator_->clearPreviewObjects(); CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); if (shape->getFixed()) continue; const CBBox2D &bbox = shape->getFlatBBox(); double dx = 0.0, dy = 0.0; if (shape != ashape) { if (side == CQIllustrator::ALIGN_LEFT ) dx = abbox.getXMin() - bbox.getXMin(); else if (side == CQIllustrator::ALIGN_BOTTOM ) dy = abbox.getYMin() - bbox.getYMin(); else if (side == CQIllustrator::ALIGN_RIGHT ) dx = abbox.getXMax() - bbox.getXMax(); else if (side == CQIllustrator::ALIGN_TOP ) dy = abbox.getYMax() - bbox.getYMax(); else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy = abbox.getYMid() - bbox.getYMid(); else if (side == CQIllustrator::ALIGN_VERTICAL ) dx = abbox.getXMid() - bbox.getXMid(); } if (side == CQIllustrator::ALIGN_LEFT ) dx += offset; else if (side == CQIllustrator::ALIGN_BOTTOM ) dy += offset; else if (side == CQIllustrator::ALIGN_RIGHT ) dx -= offset; else if (side == CQIllustrator::ALIGN_TOP ) dy -= offset; else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy += offset; else if (side == CQIllustrator::ALIGN_VERTICAL ) dx += offset; illustrator_->addPreviewObject(new CQIllustrator::PreviewShape(shape, CPoint2D(dx, dy))); } double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0; if (side == CQIllustrator::ALIGN_LEFT || side == CQIllustrator::ALIGN_RIGHT) { x1 = abbox.getXMin(); x2 = abbox.getXMax(); y1 = bbbox.getYMin(); y2 = bbbox.getYMax(); } else if (side == CQIllustrator::ALIGN_BOTTOM || side == CQIllustrator::ALIGN_TOP) { y1 = abbox.getYMin(); y2 = abbox.getYMax(); x1 = bbbox.getXMin(); x2 = bbbox.getXMax(); } else if (side == CQIllustrator::ALIGN_HORIZONTAL) { x1 = bbbox.getXMin(); x2 = bbbox.getXMax(); y1 = abbox.getYMid(); y2 = y2; } else if (side == CQIllustrator::ALIGN_VERTICAL) { y1 = bbbox.getYMin(); y2 = bbbox.getYMax(); x1 = abbox.getXMid(); x2 = x1; } double dx = (x2 - x1)/8; double dy = (y2 - y1)/8; if (side == CQIllustrator::ALIGN_LEFT ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1, y1 - dy), CPoint2D(x1, y2 + dy))); else if (side == CQIllustrator::ALIGN_BOTTOM ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y1), CPoint2D(x2 + dx, y1))); else if (side == CQIllustrator::ALIGN_RIGHT ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x2, y1 - dy), CPoint2D(x2, y2 + dy))); else if (side == CQIllustrator::ALIGN_TOP ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y2), CPoint2D(x2 + dx, y2))); else if (side == CQIllustrator::ALIGN_HORIZONTAL) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y1), CPoint2D(x2 + dx, y1))); else if (side == CQIllustrator::ALIGN_VERTICAL ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1, y1 - dy), CPoint2D(x1, y2 + dy))); illustrator_->redrawOverlay(); } }
void CGnuPlotStyleBoxErrorBars:: draw2D(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotBoxErrorBarsStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotBoxErrorBarsStyleValue>(plot); if (! value) { value = plot->app()->device()->createBoxErrorBarsStyleValue(plot); value->init(); CGnuPlotStyleValueMgrInst->setValue<CGnuPlotBoxErrorBarsStyleValue>(plot, value); } //--- const CGnuPlotLineStyle &lineStyle = plot->lineStyle(); CGnuPlotFill fill (plot); CGnuPlotStroke stroke(plot); bool isCalcColor = lineStyle.isCalcColor(); CBBox2D bbox = plot->bbox2D(); double ymin = bbox.getYMin(); double y2 = std::max(0.0, ymin); double bw = value->getSpacing(); //--- if (! renderer->isPseudo()) plot->updateBoxBarCacheSize(plot->getPoints2D().size()); //--- int i = 0; for (const auto &point : plot->getPoints2D()) { std::vector<double> reals; (void) point.getReals(reals); COptReal colorVal; if (isCalcColor && ! reals.empty()) { colorVal = reals.back(); reals.pop_back(); } while (reals.size() < 3) reals.push_back(0.0); double x = reals[0]; double y = reals[1]; double dx = bw; double dy = 0.0; double yl = y; double yh = y; // x y ydelta if (reals.size() == 3) { dy = reals[2]; yl = y - dy; yh = y + dy; } else if (reals.size() == 4) { // x y ydelta xdelta if (! value->isAutoWidth()) { dx = reals[2]; dy = reals[3]; yl = y - dy; yh = y + dy; } // x y ylow yhigh else { yl = reals[2]; yh = reals[3]; } } // x y ylow yhigh xdelta else if (reals.size() >= 5) { yl = reals[2]; yh = reals[3]; dx = reals[4]; } //--- COptRGBA lc; if (colorVal.isValid()) { if (renderer->isPseudo()) renderer->setCBValue(colorVal.getValue()); else lc = lineStyle.calcColor(plot, colorVal.getValue()); } //--- CBBox2D bbox(x - dx/2, y2, x + dx/2, y); CPoint2D p1(x, yl); CPoint2D p2(x, yh); if (! renderer->isPseudo()) { CGnuPlotBoxBarObject *bar = plot->boxBarObjects()[i]; bar->setBBox(bbox); bar->setValues(x, y); bar->setVertical(true); if (! bar->testAndSetUsed()) { CGnuPlotFillP fill (bar->fill ()->dup()); CGnuPlotStrokeP stroke(bar->stroke()->dup()); bar->setFill (fill ); bar->setStroke(stroke); //--- bar->clearEndBars(); CGnuPlotEndBarP endBar = bar->addEndBar(p1, p2); endBar->setStartLine(true); endBar->setEndLine (true); endBar->setEndWidth (dx/2); CGnuPlotStrokeP endStroke(bar->stroke()->dup()); endBar->setStroke(endStroke); } } else { CGnuPlotStroke stroke; stroke.setEnabled(true); renderer->strokeRect(bbox, stroke); renderer->strokeClipLine(p1, p2, stroke); double w = dx/2; renderer->strokeClipLine(p1 - CPoint2D(w/2, 0), p1 + CPoint2D(w/2, 0), stroke); renderer->strokeClipLine(p2 - CPoint2D(w/2, 0), p2 + CPoint2D(w/2, 0), stroke); } ++i; } if (! renderer->isPseudo()) { for (const auto &bar : plot->boxBarObjects()) bar->draw(renderer); } }