Пример #1
0
/**
 * @brief Called when the mouse is moved for this stage.
 *
*/
void BoxesStage::mouseMove(float wx, float wy)
{
	//Calculate percentage from starting position
	float sliderPercent = (wx - startX) / sliderSensitivity;

	//Blue box, so set blue
	if (inArea(startX, startY, 348, 483, 100, 176))
		a[2] = clamp(a[2] + sliderPercent, 0.0f, 1.0f),
		glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
	
	//Green box, so set green
	else if (inArea(startX, startY, 221, 325, 100, 176))
		a[1] = clamp(a[1] + sliderPercent, 0.0f, 1.0f),
		glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
	
	//Red box, so set red
	else if (inArea(startX, startY, 105, 205, 100, 176))
		a[0] = clamp(a[0] + sliderPercent, 0.0f, 1.0f),
		glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
}
Пример #2
0
/* Kliknutí myší */
bool Keyboard::click(int x, int y, int& action) {
    /* Klávesnice je schovaná, konec */
    if(flags & HIDDEN) return false;

    /* Oblast klávesnice */
    SDL_Rect area = Effects::align(screen, *align, keyboardW, keyboardH, *keyboardX, *keyboardY);

    if(!inArea(x, y, area)) return false;

    /* Procházení jednotlivých kláves */
    for(vector<KeyboardKey>::const_iterator it = items.begin(); it != items.end(); it++) {
        /* Nalezeno */
        if(!((*it).flags & DISABLED) && inArea(x, y, Effects::align(area, ALIGN_DEFAULT, (*it).position))) {
            actualItem = it;
            select();
            return true;
        }
    }

    return true;
}
Пример #3
0
status
pointInArea(Area a, Point p)
{ return inArea(a, p->x, p->y);
}
Пример #4
0
void RS_Line::draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset) {
	if (! (painter && view)) {
        return;
    }

    auto viewportRect = view->getViewRect();
    RS_VectorSolutions endPoints(0);
    endPoints.push_back(getStartpoint());
    endPoints.push_back(getEndpoint());

    RS_EntityContainer ec(nullptr);
    ec.addRectangle(viewportRect.minP(), viewportRect.maxP());

//    if (viewportRect.inArea(getStartpoint(), RS_TOLERANCE))
//         endPoints.push_back(getStartpoint());
//    if (viewportRect.inArea(getEndpoint(), RS_TOLERANCE))
//         endPoints.push_back(getEndpoint());

//    if (endPoints.size() < 2){
//        RS_VectorSolutions vpIts;
//        for(auto p: ec) {
//            auto const sol=RS_Information::getIntersection(this, p, true);
//            for (auto const& vp: sol) {
//                if (vpIts.getClosestDistance(vp) <= RS_TOLERANCE * 10.)
//                    continue;
//                vpIts.push_back(vp);
//            }
//        }
//        for (auto const& vp: vpIts) {
//            if (endPoints.getClosestDistance(vp) <= RS_TOLERANCE * 10.)
//                continue;
//            endPoints.push_back(vp);
//        }
//    }

//    if (endPoints.size()<2) return;

    if ((endPoints[0] - getStartpoint()).squared() >
            (endPoints[1] - getStartpoint()).squared() )
    {
        std::swap(endPoints[0],endPoints[1]);
    }

	RS_Vector pStart{view->toGui(endPoints.at(0))};
	RS_Vector pEnd{view->toGui(endPoints.at(1))};
    //    std::cout<<"draw line: "<<pStart<<" to "<<pEnd<<std::endl;
	RS_Vector direction = pEnd-pStart;

	if (isConstruction(true) && direction.squared() > RS_TOLERANCE){
        //extend line on a construction layer to fill the whole view
		RS_VectorSolutions vpIts;
		for(auto p: ec) {
            auto const sol=RS_Information::getIntersection(this, p, true);
			for (auto const& vp: sol) {
				if (vpIts.getClosestDistance(vp) <= RS_TOLERANCE * 10.)
					continue;
				vpIts.push_back(vp);
			}
		}

		//draw construction lines up to viewport border
		switch (vpIts.size()) {
		case 2:
			// no need to sort intersections
			break;
		case 3:
		case 4: {
			// will use the inner two points
			size_t i{0};
			for (size_t j = 0; j < vpIts.size(); ++j)
				if (viewportRect.inArea(vpIts.at(j), RS_TOLERANCE * 10.))
					std::swap(vpIts[j], vpIts[i++]);

		}
			break;
		default:
			//should not happen
			return;
		}
		pStart=view->toGui(vpIts.get(0));
		pEnd=view->toGui(vpIts.get(1));
		direction=pEnd-pStart;
    }
    double  length=direction.magnitude();
    patternOffset -= length;
    if (( !isSelected() && (
              getPen().getLineType()==RS2::SolidLine ||
              view->getDrawingMode()==RS2::ModePreview)) ) {
        //if length is too small, attempt to draw the line, could be a potential bug
        painter->drawLine(pStart,pEnd);
        return;
    }
    //    double styleFactor = getStyleFactor(view);


    // Pattern:
    const RS_LineTypePattern* pat;
    if (isSelected()) {
//        styleFactor=1.;
        pat = &RS_LineTypePattern::patternSelected;
    } else {
        pat = view->getPattern(getPen().getLineType());
    }
	if (!pat) {
//        patternOffset -= length;
        RS_DEBUG->print(RS_Debug::D_WARNING,
                        "RS_Line::draw: Invalid line pattern");
        painter->drawLine(pStart,pEnd);
        return;
    }
//    patternOffset = remainder(patternOffset - length-0.5*pat->totalLength,pat->totalLength)+0.5*pat->totalLength;
    if(length<=RS_TOLERANCE){
        painter->drawLine(pStart,pEnd);
        return; //avoid division by zero
    }
    direction/=length; //cos(angle), sin(angle)
    // Pen to draw pattern is always solid:
    RS_Pen pen = painter->getPen();

    pen.setLineType(RS2::SolidLine);
    painter->setPen(pen);

	if (pat->num <= 0) {
		RS_DEBUG->print(RS_Debug::D_WARNING,"invalid line pattern for line, draw solid line instead");
		painter->drawLine(view->toGui(getStartpoint()),
						  view->toGui(getEndpoint()));
		return;
	}

	// pattern segment length:
	double patternSegmentLength = pat->totalLength;

	// create pattern:
	std::vector<RS_Vector> dp(pat->num);
	std::vector<double> ds(pat->num);
	double dpmm=static_cast<RS_PainterQt*>(painter)->getDpmm();
	for (size_t i=0; i < pat->num; ++i) {
		//        ds[j]=pat->pattern[i] * styleFactor;
		//fixme, styleFactor support needed

		ds[i]=dpmm*pat->pattern[i];
		if (fabs(ds[i]) < 1. ) ds[i] = copysign(1., ds[i]);
		dp[i] = direction*fabs(ds[i]);
	}
	double total= remainder(patternOffset-0.5*patternSegmentLength,patternSegmentLength) -0.5*patternSegmentLength;
    //    double total= patternOffset-patternSegmentLength;

	RS_Vector curP{pStart+direction*total};
	for (int j=0; total<length; j=(j+1)%pat->num) {

        // line segment (otherwise space segment)
		double const t2=total+fabs(ds[j]);
		RS_Vector const& p3=curP+dp[j];
        if (ds[j]>0.0 && t2 > 0.0) {
            // drop the whole pattern segment line, for ds[i]<0:
            // trim end points of pattern segment line to line
			RS_Vector const& p1 =(total > -0.5)?curP:pStart;
			RS_Vector const& p2 =(t2 < length+0.5)?p3:pEnd;
            painter->drawLine(p1,p2);
        }
        total=t2;
        curP=p3;
	}

}