Пример #1
0
void LineScatterer::setFormAngle( double deltaAngle ) {

    //QLOG_INFO() << "deltaAngle = " << deltaAngle;
    //state->boundingRectBeforeDrag = sceneBoundingRect();
    double pi = 3.14159265358979323846  ;
    state->rotationAngle += deltaAngle;
    double alpha = deltaAngle * pi / 180;
    double xC = ( innerState->x1 + innerState->x2 ) / 2;
    double yC = ( innerState->y1 + innerState->y2 ) / 2;
    double oldX = innerState->x1 - xC;
    double oldY = innerState->y1 - yC;
    double x = oldX * cos( alpha ) + oldY * sin( alpha );
    double y = -oldX * sin( alpha ) + oldY * cos( alpha );
    innerState->x1 = xC + x;
    innerState->y1 = yC + y;
    innerState->x2 = xC - x;
    innerState->y2 = yC - y;
    state->rect = getLineRect( innerState->x1, innerState->y1, innerState->x2, innerState->y2 );
    innerState->form.setParam( innerState->x1, innerState->y1, innerState->x2, innerState->y2 );
    paint( state->scene, state->xMin, state->xMax, state->yMin, state->yMax );



    ////QLOG_INFO() << "angle after rotation = " << prevAngle + deltaAngle;
   // innerState->form.setRotationAngle( state->rotationAngle );
}
Пример #2
0
void ScriptEditorItem::highlightError(QPainter* p, int lineno)
{
    // Fill in the entire line with an error bar
    QColor err = Colors::red;
    err.setAlpha(100);
    p->setBrush(QBrush(err));
    p->setPen(Qt::NoPen);
    p->drawRect(getLineRect(lineno));
}
Пример #3
0
Vector<Rect> Label::getLabelRects(uint16_t firstCharId, uint16_t lastCharId, float density, const Vec2 &origin, const Padding &p) {
	auto &l = *this;
	Vector<cocos2d::Rect> ret;

	auto firstLine = getLineForCharId(firstCharId);
	auto lastLine = getLineForCharId(lastCharId);

	if (firstLine == lastLine) {
		auto rect = getCharsRect(l, firstLine, firstCharId, lastCharId, density);
		rect.origin.x += origin.x - p.left;
		rect.origin.y += origin.y - p.top;
		rect.size.width += p.left + p.right;
		rect.size.height += p.bottom + p.top;
		if (!rect.equals(cocos2d::Rect::ZERO)) {
			ret.push_back(rect);
		}
	} else {
		auto first = getLabelLineStartRect(l, firstLine, density, firstCharId);
		if (!first.equals(cocos2d::Rect::ZERO)) {
			first.origin.x += origin.x;
			first.origin.y += origin.y;
			if (first.origin.x - p.left < 0.0f) {
				first.size.width += (first.origin.x);
				first.origin.x = 0.0f;
			} else {
				first.origin.x -= p.left;
				first.size.width += p.left;
			}
			first.origin.y -= p.top;
			first.size.height += p.bottom + p.top;
			ret.push_back(first);
		}

		for (auto i = firstLine + 1; i < lastLine; i++) {
			auto rect = getLineRect(i, density);
			rect.origin.x += origin.x;
			rect.origin.y += origin.y - p.top;
			rect.size.height += p.bottom + p.top;
			if (!rect.equals(cocos2d::Rect::ZERO)) {
				ret.push_back(rect);
			}
		}

		auto last = getLabelLineEndRect(l, lastLine, density, lastCharId);
		if (!last.equals(cocos2d::Rect::ZERO)) {
			last.origin.x += origin.x;
			last.origin.y += origin.y - p.top;
			last.size.width += p.right;
			last.size.height += p.bottom + p.top;
			ret.push_back(last);
		}
	}
	return ret;
}
Пример #4
0
LineScatterer::LineScatterer( QString name, double x1, double y1, double x2, double y2 ) : BasicScatterer( name ), innerState( new InnerState ) {
    //QLOG_DEBUG() << "LineScatterer constructor";
    innerState->form.setWindowFlags( Qt::WindowStaysOnTopHint );
    innerState->x1 = x1;
    innerState->y1 = y1;
    innerState->x2 = x2;
    innerState->y2 = y2;
    innerState->form.setParam( x1, y1, x2, y2 );
    innerState->form.setName( name );
    state->rect = getLineRect( x1, y1, x2, y2 );
    QObject::connect( &innerState->form, SIGNAL( paramIsChanged() ), this, SLOT( setParamFromWidget() ) );
}
Пример #5
0
void LineScatterer::setParamFromWidget( ) {
    //QLOG_DEBUG() << "EllipseScatterer::setParamFromWidget";
    LineParam param = innerState->form.getParam();
    innerState->x1 = param.x1;
    innerState->y1 = param.y1;
    innerState->x2 = param.x2;
    innerState->y2 = param.y2;
    state->rect = getLineRect( param.x1, param.y1, param.x2, param.y2 );

    //setRect()
//    setRect( param.rect );
//    setRotationAngle( param.rotationAngle );
    paint( state->scene, state->xMin, state->xMax, state->yMin, state->yMax );
}
Пример #6
0
void LineScatterer::setFormXY( double x, double y ) {  //in addition we change innerState->x1,x2,,y1,y2 here
    LineParam param = innerState->form.getParam();
    QRectF oldRect = getLineRect( param.x1, param.y1, param.x2, param.y2 );
    double xDelta = x - oldRect.x();
    double yDelta = y - oldRect.y();
    double newX1 =  param.x1 + xDelta;
    double newY1 = param.y1 + yDelta;
    double newX2 = param.x2 + xDelta;
    double newY2 =  param.y2 + yDelta;
    innerState->form.setX1(  newX1 );
    innerState->form.setY1( newY1 );
    innerState->form.setX2(  newX2 );
    innerState->form.setY2( newY2 );
    innerState->x1 = newX1;
    innerState->y1 = newY1;
    innerState->x2 = newX2;
    innerState->y2 = newY2;
    //QLOG_INFO() << "LineScatterer innerState->x1 = " << innerState->x1;
    //QLOG_INFO() << "LineScatterer innerState->y1 = " << innerState->y1;
}
Пример #7
0
Rect Label::getLineRect(uint16_t lineId, float density, const Vec2 &origin) {
	if (lineId >= _format.lines.size()) {
		return Rect::ZERO;
	}
	return getLineRect(_format.lines[lineId], density, origin);
}