void DRangeSlider::paintEvent(QPaintEvent *) { //int side = width(); int line_thikness=2; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); QColor c = this->palette().text().color(); painter.setPen( QPen(c, line_thikness, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin) ); QLineF line( x_lim_min, y_pos, x_lim_max, y_pos); painter.drawLine(line); c = this->palette().dark().color(); painter.setBrush( QBrush(c, Qt::SolidPattern) ); drawHandle(&painter, x_min, y_pos, handle_size); c = this->palette().base().color(); painter.setBrush( QBrush(c, Qt::SolidPattern) ); drawHandle(&painter, x_max, y_pos, handle_size); QString str; if (int_strings) str.sprintf("%.0f", sub_min); else str.sprintf("%.2f", sub_min); painter.drawText( QPoint(x_lim_min+handle_size, y_pos+2*handle_size), str ); if (int_strings) str.sprintf("%.0f", sub_max); else str.sprintf("%.2f", sub_max); painter.drawText( QPoint(x_lim_max-handle_size-15, y_pos+2*handle_size), str ); }
// Paint event callback void TColourScaleEditor::paintEvent(QPaintEvent *event) { QPainter painter(this); // Get the size of the textrect we need QRect masterTextRect = style()->itemTextRect(fontMetrics(), QRect(), Qt::AlignRight | Qt::AlignVCenter, true, QString::number(-0.123456, 'e', 6)); int margin = masterTextRect.height()*0.5; masterTextRect.setLeft(margin); masterTextRect.setRight(width() - gradientBarWidth_ - 3*margin - handleRadius_*2); // Set up the basic handle style option QStyleOption handleOption; handleOption.rect.setRight(width()-margin); handleOption.rect.setLeft(width()-margin-handleRadius_*2); handleOption.rect.setHeight(masterTextRect.height()); // Draw gradient bar QBrush brush(gradient_); QPen pen(Qt::black); QRect gradientRect; gradientRect.setHeight(height()-2*margin); gradientRect.setWidth(gradientBarWidth_); gradientRect.moveTop(margin); gradientRect.moveRight(width() - 2*margin - handleRadius_*2); painter.setBrush(brush); painter.setPen(pen); painter.drawRect(gradientRect); // Define regions gradientBarRegion_ = QRegion(gradientRect); // -- Handle and label region spans top to bottom of the widget (i.e. excluding margins) handleRegion_ = QRegion(QRect(width() - margin - 2*handleRadius_, 0, 2*handleRadius_, height())); labelRegion_ = QRegion(QRect(0, 0, width() - gradientRect.right() - margin, height())); // Draw text and line elements if (colourScale_.nPoints() > 0) { double zero = colourScale_.firstPoint()->value(); double span = colourScale_.lastPoint()->value() - zero; for (ColourScalePoint* csp = colourScale_.firstPoint(); csp != NULL; csp = csp->next) { int y = (1.0 - (csp->value() - zero) / span) * (height() - 2*margin) + margin; QString numberText = QString::number(csp->value(), 'e', 6); masterTextRect.moveBottom(y + 0.5*masterTextRect.height()); painter.setPen(palette().text().color()); style()->drawItemText(&painter, masterTextRect, Qt::AlignRight | Qt::AlignVCenter, palette(), true, numberText); painter.drawLine(gradientRect.left()-margin, y, gradientRect.right()+margin, y); // Draw handle for this point handleOption.rect.moveBottom(y + 0.5*masterTextRect.height()); if (csp == currentColourScalePoint_) handleOption.state = QStyle::State_Enabled; else if (csp == hoverColourScalePoint_) handleOption.state = QStyle::State_MouseOver; else handleOption.state = 0; drawHandle(handleOption, painter); } } painter.end(); }
void drawBench(void) { mvstack.push(model_view); drawWood(); model_view *= Translate (0, -2.5 ,0); drawWood(); model_view *= Translate (0, -1, 1); model_view *= RotateX(90); model_view *= Scale(1, 0.25, 2); drawWood(); model_view *= Translate(0, 2, 0); drawWood(); model_view *= Translate(0, 2, 0); drawWood(); model_view *= Translate(0, 2, 0); drawWood(); model_view *= Translate(0, 2, 0); drawWood(); model_view = mvstack.pop(); mvstack.push(model_view); set_colour(.2,.2,.2); model_view *= Translate (-6.5 , -.7 , 0.25); drawHandle(); model_view *= Translate (0, -.7, 1.25); model_view *= RotateX(90); drawHandle(); model_view *= Scale (1, 1, 1.5); model_view *= Translate (0, 1.3, 1.5); model_view *= RotateX(90); drawHandle(); model_view = mvstack.pop(); mvstack.push(model_view); model_view *= Translate(6.5, -.7, 0.25); drawHandle(); model_view *= Translate (0, -.7, 1.25); model_view *= RotateX(90); drawHandle(); model_view *= Scale (1, 1, 1.5); model_view *= Translate (0, 1.3, 1.5); model_view *= RotateX(90); drawHandle(); model_view = mvstack.pop(); mvstack.push(model_view); model_view *= Translate (6.5, -4.5, 1); drawHandle(); model_view = mvstack.pop(); mvstack.push(model_view); model_view *= Translate (-6.5, -4.5, 1); drawHandle(); model_view = mvstack.pop(); }
/*! Draw the slider into the specified rectangle. \param painter Painter \param sliderRect Bounding rectangle of the slider */ void QwtSlider::drawSlider( QPainter *painter, const QRect &sliderRect ) const { QRect innerRect( sliderRect ); if ( d_data->hasTrough ) { const int bw = d_data->borderWidth; innerRect = sliderRect.adjusted( bw, bw, -bw, -bw ); painter->fillRect( innerRect, palette().brush( QPalette::Mid ) ); qDrawShadePanel( painter, sliderRect, palette(), true, bw, NULL ); } const QSize handleSize = qwtHandleSize( d_data->handleSize, d_data->orientation, d_data->hasTrough ); if ( d_data->hasGroove ) { const int slotExtent = 4; const int slotMargin = 4; QRect slotRect; if ( orientation() == Qt::Horizontal ) { int slotOffset = qMax( 1, handleSize.width() / 2 - slotMargin ); int slotHeight = slotExtent + ( innerRect.height() % 2 ); slotRect.setWidth( innerRect.width() - 2 * slotOffset ); slotRect.setHeight( slotHeight ); } else { int slotOffset = qMax( 1, handleSize.height() / 2 - slotMargin ); int slotWidth = slotExtent + ( innerRect.width() % 2 ); slotRect.setWidth( slotWidth ); slotRect.setHeight( innerRect.height() - 2 * slotOffset ); } slotRect.moveCenter( innerRect.center() ); QBrush brush = palette().brush( QPalette::Dark ); qDrawShadePanel( painter, slotRect, palette(), true, 1 , &brush ); } if ( isValid() ) drawHandle( painter, handleRect(), transform( value() ) ); }
void CSliderMultiPos::paintEvent(QPaintEvent* event){ int currentIndex; QStyleOptionSlider opt; Q_UNUSED(event); QStylePainter painter(this); initStyleOption(&opt); // ticks opt.subControls = QStyle::SC_SliderTickmarks; painter.drawComplexControl(QStyle::CC_Slider, opt); // groove opt.sliderValue = 0; opt.sliderPosition = 0; opt.subControls = QStyle::SC_SliderGroove; painter.drawComplexControl(QStyle::CC_Slider, opt); for( currentIndex=0;currentIndex<nbValues()-1;currentIndex++ ){ if( intervals.at(currentIndex).isEnable() ){ // handle rects opt.sliderPosition = handles.at(currentIndex).getPosition(); const QRect rectHandleFirst = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); const int lrv = pick(rectHandleFirst.center()); opt.sliderPosition = handles.at(currentIndex+1).getPosition(); const QRect rectHandleSecond = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); const int urv = pick(rectHandleSecond.center()); // span const int minv = qMin(lrv, urv); const int maxv = qMax(lrv, urv); const QPoint c = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this).center(); QRect spanRect; if( orientation()==Qt::Horizontal){ spanRect = QRect(QPoint(minv, c.y() - 2), QPoint(maxv, c.y() + 1)); } else{ spanRect = QRect(QPoint(c.x() - 2, minv), QPoint(c.x() + 1, maxv)); } drawSpan(&painter, spanRect,currentIndex); } } // handles for(int index=0;index<nbValues();index++){ // Call drawHandle for all, with the last pressed index at last of call (for being on top) drawHandle( &painter, (lastPressedIndex+index+1)%nbValues() ); } }
/*! Draw the slider into the specified rectangle. \param painter Painter \param sliderRect Bounding rectangle of the slider */ void QwtSlider::drawSlider( QPainter *painter, const QRect &sliderRect ) const { QRect innerRect( sliderRect ); if ( d_data->bgStyle & QwtSlider::Trough ) { const int bw = d_data->borderWidth; qDrawShadePanel( painter, sliderRect, palette(), true, bw, NULL ); innerRect = sliderRect.adjusted( bw, bw, -bw, -bw ); painter->fillRect( innerRect, palette().brush( QPalette::Mid ) ); } if ( d_data->bgStyle & QwtSlider::Groove ) { int ws = 4; int ds = d_data->handleSize.width() / 2 - 4; if ( ds < 1 ) ds = 1; QRect rSlot; if ( orientation() == Qt::Horizontal ) { if ( innerRect.height() & 1 ) ws++; rSlot = QRect( innerRect.x() + ds, innerRect.y() + ( innerRect.height() - ws ) / 2, innerRect.width() - 2 * ds, ws ); } else { if ( innerRect.width() & 1 ) ws++; rSlot = QRect( innerRect.x() + ( innerRect.width() - ws ) / 2, innerRect.y() + ds, ws, innerRect.height() - 2 * ds ); } QBrush brush = palette().brush( QPalette::Dark ); qDrawShadePanel( painter, rSlot, palette(), true, 1 , &brush ); } if ( isValid() ) drawHandle( painter, innerRect, transform( value() ) ); }
void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& transform) { ScreenGraphics g; fixmath::fixed angle = fixmath::ftofix(128.0 * transform.angle() / PI); gfx::Transformation::Corners corners; transform.transformBox(corners); std::vector<gfx::Point> screenPoints(corners.size()); for (size_t c=0; c<corners.size(); ++c) screenPoints[c] = editor->editorToScreen( gfx::Point((int)corners[c].x, (int)corners[c].y)); // TODO DO NOT COMMIT #if 0 // Uncomment this if you want to see the bounds in red (only for debugging purposes) // ----------------------------------------------- { gfx::Point a(transform.bounds().getOrigin()), b(transform.bounds().getPoint2()); a = editor->editorToScreen(a); b = editor->editorToScreen(b); g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a, b)); a = transform.pivot(); a = editor->editorToScreen(a); g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a.x-2, a.y-2, 5, 5)); } // ----------------------------------------------- #endif // Draw corner handle for (size_t c=0; c<HANDLES; ++c) { drawHandle(&g, (screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2, (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2, angle + handles_info[c].angle); } // Draw the pivot if (visiblePivot(angle)) { gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); she::Surface* part = theme->parts.pivotHandle()->getBitmap(0); g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y); } }
void drawMandible(int bottom) { int i, j; //draw main mandible glPushMatrix(); glTranslatef(-1.25, 0, 0); glBegin(GL_QUADS); setMaterial( (bottom) ? mandLowerDiffuse : mandUpperDiffuse, (bottom) ? mandLowerSpecular : mandUpperSpecular, mandShininess); //dont draw the last face for the upper mandible (roof of mouth) for (i = 0; i < (bottom ? 6 : 5); i++) { setFaceNormal( (GLfloat*)&mandVerts[mandFaces[i][0]], &mandVerts[mandFaces[i][1]], &mandVerts[mandFaces[i][2]]); for (j = 0; j < 4; j++) glVertex3fv(&mandVerts[mandFaces[i][j]]); } glEnd(); glColor3f(1.0, 1.0, 1.0); if (bottom) { //draw 7 teeth if (robotMode == BADASS) { setMaterial(teethDiffuse, Black, 0); for (i = 1; i < 8; i++) { glPushMatrix(); glTranslatef(i*0.3125, 2.0-3*0.05, 0.0); glScalef(1.0, 1.0, -1.0); glutSolidCone(0.05, 0.1, 4, 3); glPopMatrix(); } } //draw feet setMaterial(plasticDiffuse, plasticSpecular, plasticShininess); glPushMatrix(); glTranslatef(0.45, 0.7, 0.4); gluCylinder(qobj, 0.2, 0.2, 0.1, 8, 1); glPopMatrix(); glPushMatrix(); glTranslatef(2.05, 0.7, 0.4); gluCylinder(qobj, 0.2, 0.2, 0.1, 8, 1); glPopMatrix(); glPushMatrix(); glTranslatef(0.35, 1.4, 0.4); gluCylinder(qobj, 0.1, 0.1, 0.1, 8, 1); glPopMatrix(); glPushMatrix(); glTranslatef(2.15, 1.4, 0.4); gluCylinder(qobj, 0.1, 0.1, 0.1, 8, 1); glPopMatrix(); //draw handles glPushMatrix(); glTranslatef(-0.1, 1.0, 0); glRotatef(90, -1.0, 0.0, 0.0); drawHandle(); glPopMatrix(); glPushMatrix(); glTranslatef(2.6, 1.0, 0); glRotatef(90, -1.0, 0.0, 0.0); drawHandle(); glPopMatrix(); } glPopMatrix(); }
void LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) { if(steps < 1) { return; } Geom::PathVector tmp_path; Geom::CubicBezier const *cubic = NULL; for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) { if (path_it->empty()) { continue; } Geom::Path::iterator curve_it1 = path_it->begin(); // incoming curve Geom::Path::iterator curve_it2 = ++(path_it->begin());// outgoing curve Geom::Path::iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop SPCurve *nCurve = new SPCurve(); if (path_it->closed()) { // if the path is closed, maybe we have to stop a bit earlier because the // closing line segment has zerolength. const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { // closingline.isDegenerate() did not work, because it only checks for // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! curve_endit = path_it->end_open(); } } if(helper_size > 0) { drawNode(curve_it1->initialPoint()); } nCurve->moveto(curve_it1->initialPoint()); Geom::Point start = Geom::Point(0,0); while (curve_it1 != curve_endit) { cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); Geom::Point point_at1 = curve_it1->initialPoint(); Geom::Point point_at2 = curve_it1->finalPoint(); Geom::Point point_at3 = curve_it1->finalPoint(); Geom::Point point_at4 = curve_it1->finalPoint(); if(start == Geom::Point(0,0)) { start = point_at1; } if (cubic) { point_at1 = (*cubic)[1]; point_at2 = (*cubic)[2]; } if(path_it->closed() && curve_it2 == curve_endit) { point_at4 = start; } if(curve_it2 != curve_endit) { cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it2); if (cubic) { point_at4 = (*cubic)[1]; } } Geom::Ray ray1(point_at2, point_at3); Geom::Ray ray2(point_at3, point_at4); double angle1 = Geom::deg_from_rad(ray1.angle()); double angle2 = Geom::deg_from_rad(ray2.angle()); if((smooth_angles >= std::abs(angle2 - angle1)) && !are_near(point_at4,point_at3) && !are_near(point_at2,point_at3)) { double dist = Geom::distance(point_at2,point_at3); Geom::Angle angleFixed = ray2.angle(); angleFixed -= Geom::Angle::from_degrees(180.0); point_at2 = Geom::Point::polar(angleFixed, dist) + point_at3; } nCurve->curveto(point_at1, point_at2, curve_it1->finalPoint()); cubic = dynamic_cast<Geom::CubicBezier const *>(nCurve->last_segment()); if (cubic) { point_at1 = (*cubic)[1]; point_at2 = (*cubic)[2]; if(helper_size > 0) { if(!are_near((*cubic)[0],(*cubic)[1])) { drawHandle((*cubic)[1]); drawHandleLine((*cubic)[0],(*cubic)[1]); } if(!are_near((*cubic)[3],(*cubic)[2])) { drawHandle((*cubic)[2]); drawHandleLine((*cubic)[3],(*cubic)[2]); } } } if(helper_size > 0) { drawNode(curve_it1->finalPoint()); } ++curve_it1; ++curve_it2; } if (path_it->closed()) { nCurve->closepath_current(); } tmp_path.push_back(nCurve->get_pathvector()[0]); nCurve->reset(); delete nCurve; } result = tmp_path; }