Esempio n. 1
0
	void drawGrid(HWND hwnd, HDC hdc) {

		HFONT hf = CreateFont(8, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");
		
		HFONT oldFont = SelectFont(hdc, hf);
		
		HPEN pen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
		HPEN oldPen = (HPEN)SelectObject(hdc, pen);
				
		POINT pt;

		RECT rc;
		GetClientRect(hwnd, &rc);
		
		float y = ymin;
		while(y <= ymax) {
			char buffer[256];
			sprintf(buffer, "%1.3f", y);
			RECT r;
			r.left = 0;
			r.right = 100;
			r.bottom = toScreenY(y); 
			r.top = r.bottom - 16;
			DrawText(hdc, buffer, strlen(buffer), &r, DT_LEFT);
			MoveToEx(hdc, rc.left, toScreenY(y), &pt);
			LineTo(hdc, rc.right, toScreenY(y));
			y += yscl;
		} 

		DeleteObject(pen);
		SelectFont(hdc, oldFont);
		DeleteObject(hf);
				
	}
Esempio n. 2
0
void RS_PainterQt::fillRect ( const QRectF & rectangle, const QBrush & brush ) {
        double x1=rectangle.left();
        double x2=rectangle.right();
        double y1=rectangle.top();
        double y2=rectangle.bottom();
        QPainter::fillRect(toScreenX(x1),toScreenY(y1),toScreenX(x2),toScreenY(y2), brush);
}
Esempio n. 3
0
void RS_Painter::createEllipse(QPointArray& pa,
                             const RS_Vector& cp,
                             double radius1, double radius2,
                             double angle,
                             double angle1, double angle2,
                             bool reversed)
{


    double aStep;         // Angle Step (rad)
    double a;             // Current Angle (rad)

    aStep=0.01;

    RS_Vector vp;
    RS_Vector vc(cp.x, cp.y);
    vp.set(cp.x+cos(angle1)*radius1,
           cp.y-sin(angle1)*radius2);
    vp.rotate(vc, -angle);

    int i=0;
    pa.resize(i+1);
    pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));

    if(!reversed) {
        // Arc Counterclockwise:
        if(angle1>angle2-RS_TOLERANCE) {
            angle2+=2*M_PI;
        }
        for(a=angle1+aStep; a<=angle2; a+=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y-sin(a)*radius2);
            vp.rotate(vc, -angle);

	    pa.resize(i+1);
            pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));
        }
    } else {
        // Arc Clockwise:
        if(angle1<angle2+RS_TOLERANCE) {
            angle2-=2*M_PI;
        }
        for(a=angle1-aStep; a>=angle2; a-=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y-sin(a)*radius2);
            vp.rotate(vc, -angle);

	    pa.resize(i+1);
            pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));
        }
    }
    vp.set(cp.x+cos(angle2)*radius1,
           cp.y-sin(angle2)*radius2);
    vp.rotate(vc, -angle);

    pa.resize(i+1);
    pa.setPoint(i++, toScreenX(vp.x),toScreenY(vp.y));

}
Esempio n. 4
0
void RS_PainterQt::fillRect ( const QRectF & rectangle, const RS_Color & color ) {

        double x1=rectangle.left();
        double x2=rectangle.right();
        double y1=rectangle.top();
        double y2=rectangle.bottom();

        QPainter::fillRect(toScreenX(x1),toScreenY(y1),toScreenX(x2)-toScreenX(x1),toScreenY(y2)-toScreenX(y1), color);
}
Esempio n. 5
0
/**
 * Draws a line from (x1, y1) to (x2, y2).
 */
void RS_PainterQt::drawLine(const RS_Vector& p1, const RS_Vector& p2) {
#ifdef __APPLE1__
        int w2 = (int)getPen().getScreenWidth()/2;
    QPainter::drawLine(toScreenX(p1.x-w2), toScreenY(p1.y-w2),
                       toScreenX(p2.x-w2), toScreenY(p2.y-w2));
#else
    QPainter::drawLine(toScreenX(p1.x), toScreenY(p1.y),
                       toScreenX(p2.x), toScreenY(p2.y));
#endif
}
Esempio n. 6
0
void RS_PainterQt::fillTriangle(const RS_Vector& p1,
                                const RS_Vector& p2,
                                const RS_Vector& p3) {

    QPolygon arr(3);
    arr.putPoints(0, 3,
                  toScreenX(p1.x),toScreenY(p1.y),
                  toScreenX(p2.x),toScreenY(p2.y),
                  toScreenX(p3.x),toScreenY(p3.y));
    setBrush(pen().color());
    drawPolygon(arr);
}
Esempio n. 7
0
/**
 * Draws a circle.
 * @param cx center in x
 * @param cy center in y
 * @param radius Radius
 */
void RS_PainterQt::drawCircle(const RS_Vector& cp, double radius) {

// RVT_PORT    if (drawingMode==RS2::ModeXOR && radius<500) {
                if (radius<500) {
        // This is _very_ slow for large arcs:
        QPainter::drawEllipse(toScreenX(cp.x-radius),
                              toScreenY(cp.y-radius),
                              RS_Math::round(2.0*radius),
                              RS_Math::round(2.0*radius));
    } else {
#ifdef __APPLE1__
        drawArcMac(cp,
                radius,
                0.0, 2*M_PI,
                false);
#else
        drawArc(cp,
                radius,
                0.0, 2*M_PI,
                cp + RS_Vector(radius, 0.0),
                cp + RS_Vector(radius, 0.0),
                false);
#endif
        }
}
Esempio n. 8
0
	void drawGraph(HWND hwnd, HDC hdc) {
	
		HPEN oldPen = NULL;
		
		POINT pt;
		
		for(int i = 0; i < mChannels.size(); i++) {

			Channel* c = &mChannels[i];

			HPEN pen = CreatePen(PS_SOLID, 2, c->getColor());
			if(i == 0) {
				oldPen = (HPEN)SelectObject(hdc, pen);
			} else {
				SelectObject(hdc, pen);
			}

			for(int j = 1; j < c->getNumKeys(); j++) {
				Key* k1 = c->getKey(j-1);
				Key* k2 = c->getKey(j);
				int x1 = toScreenX(k1->x);
				int y1 = toScreenY(k1->y);
				int x2 = toScreenX(k2->x);
				int y2 = toScreenY(k2->y);
				MoveToEx(hdc, x1, y1, &pt);
				LineTo(hdc, x2, y2);
				Rectangle(hdc, x1-3, y1-3, x1+3, y1+3);
				Rectangle(hdc, x2-3, y2-3, x2+3, y2+3);
			}

			DeleteObject(pen);
	
		}

		SelectObject(hdc, oldPen);

		RECT r;
		GetClientRect(hwnd, &r);
		ValidateRect(hwnd, &r);

	}
Esempio n. 9
0
	void drawAxes(HWND hwnd, HDC hdc) {

		RECT r;
		GetClientRect(hwnd, &r);

		HPEN pen1 = CreatePen(PS_SOLID, 3, RGB(64, 64, 64));
		HPEN oldPen = (HPEN)SelectObject(hdc, pen1);
		POINT pt;
		
		// x-axis
		MoveToEx(hdc, r.left, toScreenY(0), &pt);
		LineTo(hdc, r.right, toScreenY(0));			
		
		// y-axis		
		MoveToEx(hdc, toScreenX(0), r.top, &pt);
		LineTo(hdc, toScreenX(0), r.bottom);			

		SelectObject(hdc, oldPen);
		DeleteObject(pen1);

	}
Esempio n. 10
0
/**
 * Draws a point at (x1, y1).
 */
void RS_PainterQt::drawPoint(const RS_Vector& p) {
    QPainter::drawLine(toScreenX(p.x-1), toScreenY(p.y),
                       toScreenX(p.x+1), toScreenY(p.y));
    QPainter::drawLine(toScreenX(p.x), toScreenY(p.y-1),
                       toScreenX(p.x), toScreenY(p.y+1));
}
Esempio n. 11
0
/**
 * Draws a grid point at (x1, y1).
 */
void RS_PainterQt::drawGridPoint(const RS_Vector& p) {
    QPainter::drawPoint(toScreenX(p.x), toScreenY(p.y));
}
Esempio n. 12
0
/**
 * Draws an arc which starts / ends exactly at the given coordinates.
 *
 * @param cx center in x
 * @param cy center in y
 * @param radius Radius
 * @param a1 Angle 1 in rad
 * @param a2 Angle 2 in rad
 * @param x1 startpoint x
 * @param y1 startpoint y
 * @param x2 endpoint x
 * @param y2 endpoint y
 * @param reversed true: clockwise, false: counterclockwise
 */
void RS_PainterQt::drawArc(const RS_Vector& cp, double radius,
                           double a1, double a2,
                           const RS_Vector& p1, const RS_Vector& p2,
                           bool reversed) {
    /*
    QPainter::drawArc(cx-radius, cy-radius,
                      2*radius, 2*radius,
                      a1*16, (a2-a1)*16);
    */

    if(radius<=0.5) {
        drawGridPoint(cp);
    } else {
#ifdef __APPLE1__
                drawArcMac(cp, radius, a1, a2, reversed);
#else
        int   cix;            // Next point on circle
        int   ciy;            //
        double aStep;         // Angle Step (rad)
        double a;             // Current Angle (rad)
        double linStep;       // linear step (pixels)

        if (drawingMode==RS2::ModePreview) {
            linStep = 20.0;
        } else {
            linStep = 6.0;
        }

        if (fabs(linStep/radius)<=1.0) {
            aStep=asin(linStep/radius);
        } else {
            aStep=1.0;
        }

        if (aStep<0.05) {
            aStep = 0.05;
        }

        if(!reversed) {
            // Arc Counterclockwise:
            if(a1>a2-1.0e-10) {
                a2+=2*M_PI;
            }
            //moveTo(toScreenX(p1.x), toScreenY(p1.y));
            QPolygon pa;
            int i=0;
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));
            for(a=a1+aStep; a<=a2; a+=aStep) {
                cix = toScreenX(cp.x+cos(a)*radius);
                ciy = toScreenY(cp.y-sin(a)*radius);
                //lineTo(cix, ciy);
                pa.resize(i+1);
                pa.setPoint(i++, cix, ciy);
            }
            //lineTo(toScreenX(p2.x), toScreenY(p2.y));
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));
            drawPolyline(pa);
        } else {
            // Arc Clockwise:
            if(a1<a2+1.0e-10) {
                a2-=2*M_PI;
            }
            QPolygon pa;
            int i=0;
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));
            //moveTo(toScreenX(p1.x), toScreenY(p1.y));
            for(a=a1-aStep; a>=a2; a-=aStep) {
                cix = toScreenX(cp.x+cos(a)*radius);
                ciy = toScreenY(cp.y-sin(a)*radius);
                //lineTo(cix, ciy);
                pa.resize(i+1);
                pa.setPoint(i++, cix, ciy);
            }
            //lineTo(toScreenX(p2.x), toScreenY(p2.y));
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));
            drawPolyline(pa);
        }
#endif
    }
}
Esempio n. 13
0
void RS_Painter::createArc(QPolygon& pa,
                             const RS_Vector& cp, double radius,
                             double a1, double a2,
                             bool reversed) {

	if (radius<1.0e-6) {
        RS_DEBUG->print(RS_Debug::D_WARNING,
			"RS_Painter::createArc: invalid radius: %f", radius);
		return;
	}

    int   cix;            // Next point on circle
    int   ciy;            //
    double aStep;         // Angle Step (rad)
    double a;             // Current Angle (rad)

    if(fabs(2.0/radius)<=1.0) {
        aStep=asin(2.0/radius);
    } else {
        aStep=1.0;
    }

    aStep=aStep/2.0;
    //if (aStep<0.05) {
    //    aStep = 0.05;
    //}
	
	// less than a pixel long lines:
	//if (radius*aStep<1.0) {
	//	aStep = 
	//}

    //QPointArray pa;
    int i=0;
    pa.resize(i+1);
    pa.setPoint(i++, toScreenX(cp.x+cos(a1)*radius),
                toScreenY(cp.y-sin(a1)*radius));
    //moveTo(toScreenX(cp.x+cos(a1)*radius),
    //       toScreenY(cp.y-sin(a1)*radius));
    if(!reversed) {
        // Arc Counterclockwise:
        if(a1>a2-1.0e-10) {
            a2+=2*M_PI;
        }
        for(a=a1+aStep; a<=a2; a+=aStep) {
            cix = toScreenX(cp.x+cos(a)*radius);
            ciy = toScreenY(cp.y-sin(a)*radius);
            //lineTo(cix, ciy);
            pa.resize(i+1);
            pa.setPoint(i++, cix, ciy);
        }
    } else {
        // Arc Clockwise:
        if(a1<a2+1.0e-10) {
            a2-=2*M_PI;
        }
        for(a=a1-aStep; a>=a2; a-=aStep) {
            cix = toScreenX(cp.x+cos(a)*radius);
            ciy = toScreenY(cp.y-sin(a)*radius);
            //lineTo(cix, ciy);
            pa.resize(i+1);
            pa.setPoint(i++, cix, ciy);
        }
    }
    //lineTo(toScreenX(cp.x+cos(a2)*radius),
    //       toScreenY(cp.y-sin(a2)*radius));
    pa.resize(i+1);
    pa.setPoint(i++,
                toScreenX(cp.x+cos(a2)*radius),
                toScreenY(cp.y-sin(a2)*radius));
    //drawPolyline(pa);
}
Esempio n. 14
0
/**
 * Draws a rotated ellipse arc.
 */
void RS_PainterQt::drawEllipse(const RS_Vector& cp,
                               double radius1, double radius2,
                               double angle,
                               double a1, double a2,
                               bool reversed) {

    //if(radius1<=0.5 && radius2<=0.5) {
    //    drawGridPoint((int)cp.x, (int)cp.y);
    //} else {
    //int   cix;            // Next point on arc
    //int   ciy;            //
//    double a;             // Current Angle (rad)

    // Angle step in rad
    /*
       if (radius1<radius2) {
           if (radius1<RS_TOLERANCE) {
               aStep=1.0;
           } else {
                if (fabs(2.0/radius1)<=1.0) {
                aStep=asin(2.0/radius1);
                }
                else {
                        aStep = 1.0;
                }
           }
       } else {
           if (radius2<RS_TOLERANCE) {
               aStep=1.0;
           } else {
                if (fabs(2.0/radius2)<=1.0) {
                aStep=asin(2.0/radius2);
                }
                else {
                        aStep = 1.0;
                }
           }
       }

       if(aStep<0.05) {
           aStep = 0.05;
       }
    */



    const RS_Vector vr(radius1,radius2);
    const RS_Vector rvp(radius2,radius1);
    double ea1(a1);
    double ea2(a2);
    if(reversed) std::swap(ea1,ea2);
    if(ea2<ea1+RS_TOLERANCE_ANGLE) {
        ea2 += 2.*M_PI; //potential bug
    }
    const RS_Vector angleVector(-angle);
    double aStep(0.01/(radius1*radius2));         // Angle Step (0.01 rad)
    /*
      draw a new line after tangent changes by 0.01 rad
      */
    RS_Vector vp(-ea1);
    ea1 += aStep*RS_Vector(vp.x*radius2,vp.y*radius1).squared();
    vp.scale(vr);
    vp.rotate(angleVector);
    vp.move(cp);
    //    vp.set(cp.x+cos(a1)*radius1,
    //           cp.y-sin(a1)*radius2);
    //    vp.rotate(vc, -angle);
    moveTo(toScreenX(vp.x),
           toScreenY(vp.y));
    // Arc Counterclockwise:
    while(ea1<ea2){

        RS_Vector va(-ea1);
        vp=va;
        vp.scale(vr);
        vp.rotate(angleVector);
        vp.move(cp);

        //            vp.set(cp.x+cos(a)*radius1,
        //                   cp.y-sin(a)*radius2);
        //            vp.rotate(vc, -angle);
        lineTo(toScreenX(vp.x),
               toScreenY(vp.y));
        ea1 += aStep*va.scale(rvp).squared();
    }

    vp.set(cos(ea2)*radius1,
           -sin(ea2)*radius2);
    vp.rotate(angleVector);
    vp.move(cp);
    lineTo(toScreenX(vp.x),
           toScreenY(vp.y));
    //}
}
Esempio n. 15
0
/**
 * Draws a rotated ellipse arc.
 */
void RS_PainterQt::drawEllipse(const RS_Vector& cp,
                               double radius1, double radius2,
                               double angle,
                               double a1, double a2,
                               bool reversed) {

    //if(radius1<=0.5 && radius2<=0.5) {
    //    drawGridPoint((int)cp.x, (int)cp.y);
    //} else {
    //int   cix;            // Next point on arc
    //int   ciy;            //
    double aStep;         // Angle Step (rad)
    double a;             // Current Angle (rad)

    // Angle step in rad
    /*
       if (radius1<radius2) {
           if (radius1<RS_TOLERANCE) {
               aStep=1.0;
           } else {
    		if (fabs(2.0/radius1)<=1.0) {
               	aStep=asin(2.0/radius1);
    		}
    		else {
    			aStep = 1.0;
    		}
           }
       } else {
           if (radius2<RS_TOLERANCE) {
               aStep=1.0;
           } else {
    		if (fabs(2.0/radius2)<=1.0) {
               	aStep=asin(2.0/radius2);
    		}
    		else {
    			aStep = 1.0;
    		}
           }
       }

       if(aStep<0.05) {
           aStep = 0.05;
       }
    */

    aStep=0.01;

    RS_Vector vp;
    RS_Vector vc(cp.x, cp.y);
    vp.set(cp.x+cos(a1)*radius1,
           cp.y-sin(a1)*radius2);
    vp.rotate(vc, -angle);
    moveTo(toScreenX(vp.x),
           toScreenY(vp.y));
    if(!reversed) {
        // Arc Counterclockwise:
        if(a1>a2-RS_TOLERANCE) {
            a2+=2*M_PI;
        }
        for(a=a1+aStep; a<=a2; a+=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y-sin(a)*radius2);
            vp.rotate(vc, -angle);
            lineTo(toScreenX(vp.x),
                   toScreenY(vp.y));
        }
    } else {
        // Arc Clockwise:
        if(a1<a2+RS_TOLERANCE) {
            a2-=2*M_PI;
        }
        for(a=a1-aStep; a>=a2; a-=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y-sin(a)*radius2);
            vp.rotate(vc, -angle);
            lineTo(toScreenX(vp.x),
                   toScreenY(vp.y));
        }
    }
    vp.set(cp.x+cos(a2)*radius1,
           cp.y-sin(a2)*radius2);
    vp.rotate(vc, -angle);
    lineTo(toScreenX(vp.x),
           toScreenY(vp.y));
    //}
}