Beispiel #1
0
void Window::keyReleaseEvent(QKeyEvent* evt)
{
    switch (evt->key()) {
        case Qt::Key_Return: {
            Resynthesizer r;

            QImage result = r.inpaintHier(*pictureImage_, *overlayImage_);
            resultItem_->setPixmap(QPixmap::fromImage(result));

            offsetMapItem_->setPixmap(QPixmap::fromImage(visualizeOffsetMap(r.offsetMap())));
            scoreMapItem_->setPixmap(QPixmap::fromImage(visualizeReliabilityMap(r.reliabilityMap())));
            break;
        }
        case Qt::Key_Space:
            overlayImage_->fill(0);
            overlayItem_->setPixmap(QPixmap::fromImage(*overlayImage_));
            break;
        case Qt::Key_Plus:
            if (paintSize_ < MAX_PAINT_SIZE)
                ++paintSize_;
            updateBrush();
            break;
        case Qt::Key_Minus:
            if (paintSize_ > MIN_PAINT_SIZE)
                --paintSize_;
            updateBrush();
            break;
        case Qt::Key_Q:
            if (evt->modifiers() & Qt::ControlModifier)
                qApp->exit(0);
            break;
    }
}
Beispiel #2
0
Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
    : position(position), vel(velocity), radius(radius)
{
    innerColor = randomColor();
    outerColor = randomColor();
    updateBrush();
}
Beispiel #3
0
void setBrushStyle(ACL_Brush_Style newStyle)
{
	ACL_ASSERT_BEGIN_PAINT;
	
	switch(newStyle)
	{
	case BRUSH_STYLE_SOLID:
		g_brushStyle = BRUSH_STYLE_SOLID; break;
	case BRUSH_STYLE_HORIZONTAL:	
		g_brushStyle = HS_HORIZONTAL; break;
	case BRUSH_STYLE_VERTICAL:		
		g_brushStyle = HS_VERTICAL; break;
	case BRUSH_STYLE_FDIAGONAL:		
		g_brushStyle = HS_FDIAGONAL; break;
	case BRUSH_STYLE_BDIAGONAL:		
		g_brushStyle = HS_BDIAGONAL; break;
	case BRUSH_STYLE_CROSS:			
		g_brushStyle = HS_CROSS; break;
	case BRUSH_STYLE_DIAGCROSS:		
		g_brushStyle = HS_DIAGCROSS; break;
	case BRUSH_STYLE_NULL:
		g_brushStyle = BRUSH_STYLE_SOLID;
		setBrushColor(EMPTY);
		return;
	default:
		break;
	}
	updateBrush();
}
Beispiel #4
0
//! [3]
void TabletCanvas::tabletEvent(QTabletEvent *event)
{
  qDebug()<< event;
    switch (event->type()) {
        case QEvent::TabletPress:
            if (!deviceDown) {
                deviceDown = true;
                polyLine[0] = polyLine[1] = polyLine[2] = event->pos();
            }
            break;
        case QEvent::TabletRelease:
            if (deviceDown)
                deviceDown = false;
            break;
        case QEvent::TabletMove:
            polyLine[2] = polyLine[1];
            polyLine[1] = polyLine[0];
            polyLine[0] = event->pos();

            if (deviceDown) {
                updateBrush(event);
                QPainter painter(&pixmap);
                painter.setRenderHint(QPainter::Antialiasing);
                painter.setRenderHint(QPainter::SmoothPixmapTransform);
                paintPixmap(painter, event);
            }
            break;
        default:
            break;
    }
    update();
}
//! [3]
void TabletCanvas::tabletEvent(QTabletEvent *event)
{

    switch (event->type()) {
        case QEvent::TabletPress:
            if (!deviceDown) {
                deviceDown = true;
                polyLine[0] = polyLine[1] = polyLine[2] = event->pos();
            }
            break;
        case QEvent::TabletRelease:
            if (deviceDown)
                deviceDown = false;
            break;
        case QEvent::TabletMove:
            polyLine[2] = polyLine[1];
            polyLine[1] = polyLine[0];
            polyLine[0] = event->pos();

            if (deviceDown) {
                updateBrush(event);
                QPainter painter(&pixmap);
                paintPixmap(painter, event);
            }
            break;
        default:
            break;
    }
    update();
}
Beispiel #6
0
PainterWidget::PainterWidget(QWidget * parent)
    : QWidget(parent), brush_size(10), brush_color(Qt::black),
    last_pos(-1,-1), image(256,256,QImage::Format_RGB32),soft_brush(32, 32,QImage::Format_RGB32)
{
    clear();
    updateBrush();
    cutoffData = new float[256*256*4];
}
void QCairoPaintEngine::drawPolygon(const QPointF *points, int pointCount, QPaintEngine::PolygonDrawMode mode)
{
    if (!cr || !surface) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPolygon]: no cairo or no surface!";
        return;
    }
    /*if (cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPolygon]: no pen set!";
        return;
    }*/
    if (mode!=QPaintEngine::PolylineMode && cbrush.style()==Qt::NoBrush && cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPolygon]: no pen and no brush set!";
        return;
    }
    //updatePen();

    //qDebug()<<"drawPolygon n="<<pointCount;
    if (pointCount>1) {
        cairo_new_path(cr);
        cairo_move_to(cr, points[0].x(), points[0].y());
        for (int i=1; i<pointCount; i++) {
            cairo_line_to(cr, points[i].x(), points[i].y());
        }
        if (points[0].x()==points[pointCount-1].x() && points[0].y()==points[pointCount-1].y()){
            cairo_close_path(cr);
        } else if (mode!=QPaintEngine::PolylineMode) {
            cairo_close_path(cr);
        }
        if (mode==QPaintEngine::PolylineMode) {
            updatePen();
            cairo_stroke(cr);
        } else {
            switch (mode) {
                case QPaintEngine::WindingMode:
                    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
                    break;
                default:
                case QPaintEngine::OddEvenMode:
                    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
                    break;
            }


            updateBrush();
            if (cpen.style()!=Qt::NoPen) {
                cairo_fill_preserve(cr);
                updatePen();
                cairo_stroke(cr);
            } else cairo_fill(cr);
        }
    }

}
Beispiel #8
0
void Window::wheelEvent(QWheelEvent* evt)
{
    if (evt->modifiers() & Qt::ControlModifier) {
        // zoom workspace
        qreal dscale = pow((double)2, evt->delta()/480.0);
        scale(dscale, dscale);
    } else {
        // scale brush
        paintSize_ = qBound(MIN_PAINT_SIZE, paintSize_+(evt->delta()/120), MAX_PAINT_SIZE);
        updateBrush();
    }
}
void beginPaint() {
  HDC hdc;

  ACL_ASSERT_HWND;

  hdc = GetDC(g_hWnd);
  g_hmemdc = CreateCompatibleDC(hdc);
  SelectObject(g_hmemdc, g_HBITMAP);

  updatePen();
  updateBrush();
  updateFont();
  setTextColor(g_textColor);
  setTextBkColor(g_textBkColor);
}
void QPicturePaintEngine::updateState(const QPaintEngineState &state)
{
    QPaintEngine::DirtyFlags flags = state.state();
    if (flags & DirtyPen) updatePen(state.pen());
    if (flags & DirtyBrush) updateBrush(state.brush());
    if (flags & DirtyBrushOrigin) updateBrushOrigin(state.brushOrigin());
    if (flags & DirtyFont) updateFont(state.font());
    if (flags & DirtyBackground) updateBackground(state.backgroundMode(), state.backgroundBrush());
    if (flags & DirtyTransform) updateMatrix(state.transform());
    if (flags & DirtyClipEnabled) updateClipEnabled(state.isClipEnabled());
    if (flags & DirtyClipRegion) updateClipRegion(state.clipRegion(), state.clipOperation());
    if (flags & DirtyClipPath) updateClipPath(state.clipPath(), state.clipOperation());
    if (flags & DirtyHints) updateRenderHints(state.renderHints());
    if (flags & DirtyCompositionMode) updateCompositionMode(state.compositionMode());
    if (flags & DirtyOpacity) updateOpacity(state.opacity());
}
Beispiel #11
0
void SunMenuItemView::initialize()
{
    Q_ASSERT_X(mItemModel != 0 && mItemModel->displayedItem() != 0,
               "MenuItemView::initialize()",
               "You should pass a valid MenuItemModel pointer");

    Q_ASSERT_X(mParentLayer != 0, "MenuItemView::initialize()",
               "Parent layer for item MUST be specified.");

    connect(representation(),SIGNAL(brushChanged(const QBrush&)), this, SLOT(updateBrush(const QBrush&)));
    updateBrush(representation()->brush());

    setAcceptHoverEvents(true);
    setParent(mItemModel);
    setParentItem(mParentItemView);

    // Cache useless in this situation because we don't use transformation and menu doesn't change it's position.
    //It's increases memory usage and greatly reduces the animation performance.
    setCacheMode(QGraphicsItem::NoCache);
    //	setFlag(QGraphicsItem::ItemStacksBehindParent, true);

    if (mItemModel->displayedItem()->graphicsItem())
        mItemModel->displayedItem()->graphicsItem()->setParentItem(this);

    connect(mItemModel, SIGNAL(childAdded(MenuItemModel*)), this,
            SLOT(childItemAdded(MenuItemModel*)));

    mSubLayer = 0;

    mStartAngle = 0;
    mSweepLength = 0;
    mWidth = 0;
    mInnerRadius = 0;

    if (!mItemModel->childMenus().isEmpty())
    {
        foreach(MenuItemModel* mc, mItemModel->childMenus())
            addChildItem(mc);
    }

    updateShape();
    recalculateChildMenusAngles();
}
Beispiel #12
0
void MindPaint::draw(){
    // This is for debug purpose, when the headset is not available
    // usually updatebrush is called inside MindPaint::update()
    if (useMouse && tgState != READY && appState == READY){
        updateFoes();
        updateBrush();
    }

    ofBackground(0);
    switch (appState){
        case SELECT_BG:
            buffer.begin();
            ofSetColor((int)back.r, (int)back.g, (int)back.b);
            ofFill();
            ofRect(0, 0, buffer.getWidth(), buffer.getHeight());
            buffer.end();
            Buffer::draw(buffer);

            ofSetColor((int)mood.r, (int)mood.g, (int)mood.b, 255);
            ofCircle(ofGetWidth()/2, ofGetHeight()/2, 50);
            break;

        case DRAW:
            buffer.begin();
            brush->draw();
            buffer.end();
            Buffer::draw(buffer);
            moverControl->debugDraw();
            break;

        case PAUSE:
            Buffer::draw(buffer);
            break;
    }

    drawMindsetStatus(useMouse ? tgEmu.args : tg.values);
    tgEmu.draw();
}
Beispiel #13
0
void Window::loadImage(const QString& filename)
{
    delete pictureImage_;
    pictureImage_ = new QImage(QImage(filename).convertToFormat(QImage::Format_ARGB32));
    if (!pictureImage_) {
        qDebug() << "loading image failed";
    }
    qDebug() << "format:" << pictureImage_->format();
    imageItem_->setPixmap(QPixmap::fromImage(*pictureImage_));

    delete overlayImage_;
    overlayImage_ = new QImage(pictureImage_->size(), QImage::Format_ARGB32);
    overlayImage_->fill(0);

    QRect frame = pictureImage_->rect();
    imageItem_->setPos(0, 0);
    overlayItem_->setPos(0, 0);
    resultItem_->setPos(frame.width(), 0);
    offsetMapItem_->setPos(frame.width(), frame.height());
    scoreMapItem_->setPos(0, frame.height());
    scene_->setSceneRect(0, 0, frame.width()*2, frame.height()*2);

    updateBrush();
}
void QCairoPaintEngine::drawPath(const QPainterPath &path)
{
    if (!cr || !surface) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPath]: no cairo or no surface!";
        return;
    }
    if (cbrush.style()==Qt::NoBrush && cpen.style()==Qt::NoPen) {
        qDebug()<<"Cairo Error [QCairoPaintEngine::drawPath]: no pen and no brush set!";
        return;
    }
    //qDebug()<<"drawPath n="<<path;

    bool fill;
    updatePath(path, fill);
    /*cairo_new_path(cr);

    int start = -1, elmCount = path.elementCount();
    for (int index = 0; index < elmCount; index++)
    {
      const QPainterPath::Element elm = path.elementAt(index);
      switch (elm.type)
      {
        case QPainterPath::MoveToElement:
          cairo_move_to(cr, elm.x, elm.y);
          start = index;
          break;

        case QPainterPath::LineToElement:
          cairo_line_to(cr, elm.x, elm.y);
          break;

        case QPainterPath::CurveToElement:
          cairo_curve_to(cr, elm.x, elm.y,
              path.elementAt(index + 1).x, path.elementAt(index + 1).y,
              path.elementAt(index + 2).x, path.elementAt(index + 2).y);
          index += 2;
          break;

        default:
          break;
      }
    }

    bool fill=false;
    if (start != -1 && start != elmCount - 1
          && path.elementAt(start).x == path.elementAt(elmCount - 1).x
            && path.elementAt(start).y == path.elementAt(elmCount - 1).y){
        cairo_close_path(cr);
        //qDebug()<<"closing path";
        fill=cbrush.style()!=Qt::NoBrush;
    }*/
    if (fill) fill=cbrush.style()!=Qt::NoBrush;


    if (fill) {
        switch (path.fillRule()) {
            case Qt::WindingFill:
                cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
                break;
            default:
            case Qt::OddEvenFill:
                cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
                break;
        }


        updateBrush();
        if (cpen.style()!=Qt::NoPen) cairo_fill_preserve(cr);
        else cairo_fill(cr);
    }
    if (cpen.style()!=Qt::NoPen) {
        updatePen();
        cairo_stroke(cr);
    } else {

    }


}
Beispiel #15
0
void setBrushColor(ACL_Color newColor)
{
	ACL_ASSERT_BEGIN_PAINT;
    g_brushColor = newColor;
    updateBrush();
}
Beispiel #16
0
void MindPaint::update(){
    ofxThinkgearEventArgs& values = (useMouse ? tgEmu.args : tg.values);
    if (false && ++frame % 60 == 0){
        cout
            << " ATT: " << (int)values.attention
            << " MED: " << (int)values.meditation
            << " POO: " << (int)values.poorSignal
            << " RAW: " << (int)values.raw
            << endl;
        if (frame == 6000)
            frame = 0;
    }
    if (useMouse)
        tgEmu.update(*this);
    else
        tg.update();
    switch (tgState){
        case NONE:
        case CONNECTING:
            if (tg.isReady || useMouse)
                tgState = READY;
            break;

        case BAD_SIGNAL:
            if (values.poorSignal == 0)
                tgState = READY;
            else {
                score = 0;
                attBonus = 0;
                attScore = 0;
                medBonus = 0;
                medScore = 0;
            }
            break;

        case READY:
            if (values.poorSignal > 0){
                tgState = BAD_SIGNAL;
                return;
            }
            switch (appState){
                case SELECT_BG:
                    // float h, s, b, cmp;
                    // back.getHsb(h,s,b);
                    // //cout << "h=" << h << " s=" << s << " b=" << b << endl;
                    // h += 0.2;
                    // b = 250.0;
                    // // b += 0.5;
                    // // if (b > 150.0)
                    // //     b = 50.0;
                    // if (h > 255.0) h=0.0;
                    // back.setHsb(h, 255.0, b, 255.0);
                    // cmp = h + 255.0/2;
                    // if (cmp > 255.0)
                    //     cmp -= 255.0;
                    // mood.setHsb(cmp, 255.0, 255.0, 0.9);
                    //backRybAngle += 0.005;
                    // back = RYBWheel::pick(backRybAngle);
                    mood = RYBWheel::pick(backRybAngle - 0.5);
                    mood.a = 0.9;
                    break;

                case PAUSE:
                    appState = DRAW;
                    break;

                case DRAW:
                    if (values.attention < 90) attBonus = 0;
                    if (values.meditation < 90) medBonus = 0;
                    attScore = values.attention + 10*(attBonus/FPS);
                    medScore = values.meditation + 10*(medBonus/FPS);
                    if (attScore > medScore){
                        score = attScore;
                        if (!dynamic_cast<RectBrush*>(brush))
                            setBrush(new RectBrush());
                    }
                    else if (medScore > attScore){
                        score = medScore;
                        if (score > 80 && !dynamic_cast<FlowerBrush*>(brush))
                            setBrush(new FlowerBrush());
                        else if (!dynamic_cast<EllipseBrush*>(brush))
                            setBrush(new EllipseBrush());

                    }
                    else {
                        score = score * 0.98;
                    }
                    updateFoes();
                    updateBrush();
                    if (values.attention > 90) attBonus = min(10*FPS, attBonus++);
                    if (values.meditation > 90) medBonus = min(10*FPS, medBonus++);
                    break;
            }
            break;
    }
}
Beispiel #17
0
void PainterWidget::setBrushColor(QColor color)
{
    brush_color = color;
    updateBrush();
}
Beispiel #18
0
void PainterWidget::setBrushSize(int s)
{
    brush_size = s;
    updateBrush();
    qDebug() << "set brush size:" << s;
}
void Brush::Widget::setTool(Brush* tool)
{
    this->tool_ = tool;
    updateBrush();
}