Ejemplo n.º 1
0
static void handleTimeout(XiTimerListener* __thisPtr, XiQTimer* timer)
{
    XiQRect* oldRect = ballRect();

    x += dx;
    y += dy;

    if (x + R >= DIM || (x - R)<= 0)
        dx = -dx;

    if (y + R >= DIM || (y - R) <= 0)
        dy = -dy;

    XiQRect* newRect = ballRect();
    XiQRect* both    = newRect->vtable()->united(newRect, oldRect);

    mainWidget->vtable()->repaint(mainWidget,
                                  both->vtable()->adjusted(both, -5, -5, 5, 5));
}
Ejemplo n.º 2
0
void render() {
    glClear(GL_COLOR_BUFFER_BIT);

    std::vector<Rect> rectangles;

    Rect ballRect(0, 0, BALL_SIZE, BALL_SIZE);
    ball.getCoordinates(ballRect.x, ballRect.y);

    rectangles.push_back(ballRect);

    rectangles.push_back(leftPlayer.getCoords());
    rectangles.push_back(rightPlayer.getCoords());

    std::vector<Color> colors;
    colors.push_back(Color(1.0f, 1.0f, 1.0f));
    colors.push_back(Color(1.0f, 0.0f, 0.0f));
    colors.push_back(Color(0.0f, 0.0f, 1.0f));

    drawRectangles(rectangles, colors);
}
Ejemplo n.º 3
0
static void handlePaintEvent(XiQWidget* __thisPtr, XiQPaintEvent* pe)
{
    // draw scene on backBuffer
    backBuffer->vtable()->fill(backBuffer, XI(qcolor_o6QColoriii)(255, 255, 192));
    XiQPainter* p = XI(qpainter_o8QPaintero12QPaintDevice)(backBuffer);
    p->vtable()->setHighQuality(p, true);

    XiQPen* pen = XI(qpen_o4QPeno6QColor)(XI(qcolor_o6QColoriii)(0, 0, 255));
    pen->vtable()->setWidth(pen, 5);
    p->vtable()->setPen(p, pen);
    p->vtable()->setBrush(p, XI(qbrush_o6QBrusho6QColor)(XI(qcolor_o6QColoriii)(255, 0, 0)));
    p->vtable()->drawEllipse(p, ballRect());
    p->vtable()->end(p);

    // paint the backbuffer
    XiQRect* dirty = pe->vtable()->rect(pe);
    XiQPainter* pw = XI(qpainter_o8QPaintero12QPaintDevice)(__thisPtr);
    pw->vtable()->drawPixmapPortion(pw, dirty->vtable()->topLeft(dirty),
                                    backBuffer, dirty);
    pw->vtable()->end(pw);
}
Ejemplo n.º 4
0
void PixmapDial::paintEvent(QPaintEvent*)
{
    QPainter painter(this);

    if (! m_label.isEmpty())
    {
        painter.setPen(m_color2);
        painter.setBrush(m_label_gradient);
        painter.drawRect(m_label_gradient_rect);

        painter.setPen(m_colorT[isEnabled() ? 0 : 1]);
        painter.drawText(m_label_pos, m_label);
    }

    if (isEnabled())
    {
        float current = value()-minimum();
        float divider = maximum()-minimum();

        if (divider == 0.0f)
            return;

        float value = current/divider;
        QRectF source, target(0.0f, 0.0f, p_size, p_size);

        int xpos, ypos, per = (p_count-1)*value;

        if (m_orientation == HORIZONTAL)
        {
            xpos = p_size*per;
            ypos = 0.0f;
        }
        else
        {
            xpos = 0.0f;
            ypos = p_size*per;
        }

        source = QRectF(xpos, ypos, p_size, p_size);
        painter.drawPixmap(target, m_pixmap, source);

        // Custom knobs (Dry/Wet and Volume)
        if (m_custom_paint == CUSTOM_PAINT_CARLA_WET || m_custom_paint == CUSTOM_PAINT_CARLA_VOL)
        {
            // knob color
            QColor colorGreen(0x5D, 0xE7, 0x3D, 191 + m_hover_step*7);
            QColor colorBlue(0x3E, 0xB8, 0xBE, 191 + m_hover_step*7);

            // draw small circle
            QRectF ballRect(8.0, 8.0, 15.0, 15.0);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - floorf(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            // draw arc
            int startAngle = 216*16;
            int spanAngle  = -252*16*value;

            if (m_custom_paint == CUSTOM_PAINT_CARLA_WET)
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2));

                QConicalGradient gradient(15.5, 15.5, -45);
                gradient.setColorAt(0.0,   colorBlue);
                gradient.setColorAt(0.125, colorBlue);
                gradient.setColorAt(0.625, colorGreen);
                gradient.setColorAt(0.75,  colorGreen);
                gradient.setColorAt(0.76,  colorGreen);
                gradient.setColorAt(1.0,   colorGreen);
                painter.setBrush(gradient);
                painter.setPen(QPen(gradient, 3));
            }
            else
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2));

                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 3));
            }

            painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle);
        }
        // Custom knobs (L and R)
        else if (m_custom_paint == CUSTOM_PAINT_CARLA_L || m_custom_paint == CUSTOM_PAINT_CARLA_R)
        {
            // knob color
            QColor color(0xAD + m_hover_step*5, 0xD5 + m_hover_step*4, 0x4B + m_hover_step*5);

            // draw small circle
            QRectF ballRect(7.0, 8.0, 11.0, 12.0);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - floorf(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            painter.setBrush(color);
            painter.setPen(QPen(color, 0));
            painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0f, 2.0f));

            int startAngle, spanAngle;

            // draw arc
            if (m_custom_paint == CUSTOM_PAINT_CARLA_L)
            {
                startAngle = 216*16;
                spanAngle  = -252.0*16*value;
            }
            else if (m_custom_paint == CUSTOM_PAINT_CARLA_R)
            {
                startAngle = 324.0*16;
                spanAngle  = 252.0*16*(1.0-value);
            }
            else
                return;

            painter.setPen(QPen(color, 2));
            painter.drawArc(3.5, 4.5, 22.0, 22.0, startAngle, spanAngle);

            if (HOVER_MIN < m_hover_step && m_hover_step < HOVER_MAX)
            {
                m_hover_step += m_hovered ? 1 : -1;
                QTimer::singleShot(20, this, SLOT(update()));
            }
        }

        if (HOVER_MIN < m_hover_step && m_hover_step < HOVER_MAX)
        {
            m_hover_step += m_hovered ? 1 : -1;
            QTimer::singleShot(20, this, SLOT(update()));
        }
    }
    else
    {
        QRectF target(0.0, 0.0, p_size, p_size);
        painter.drawPixmap(target, m_pixmap, target);
    }
}
Ejemplo n.º 5
0
void PixmapDial::paintEvent(QPaintEvent* event)
{
    event->accept();

    QPainter painter(this);
    painter.save();
    painter.setRenderHint(QPainter::Antialiasing, true);

    if (! fLabel.isEmpty())
    {
        if (fCustomPaint == CUSTOM_PAINT_NULL)
        {
            painter.setPen(fColor2);
            painter.setBrush(fLabelGradient);
            painter.drawRect(fLabelGradientRect);
        }

        painter.setFont(fLabelFont);
        painter.setPen(fColorT[isEnabled() ? 0 : 1]);
        painter.drawText(fLabelPos, fLabel);
    }

    if (isEnabled())
    {
        float current = value()-minimum();
        float divider = maximum()-minimum();

        if (divider == 0.0f)
            return;

        float value = current/divider;
        QRectF source, target(0.0f, 0.0f, fSize, fSize);

        int xpos, ypos, per = (fCount-1)*value;

        if (fOrientation == HORIZONTAL)
        {
            xpos = fSize*per;
            ypos = 0.0f;
        }
        else
        {
            xpos = 0.0f;
            ypos = fSize*per;
        }

        source = QRectF(xpos, ypos, fSize, fSize);
        painter.drawPixmap(target, fPixmap, source);

        // Custom knobs (Dry/Wet and Volume)
        if (fCustomPaint == CUSTOM_PAINT_CARLA_WET || fCustomPaint == CUSTOM_PAINT_CARLA_VOL)
        {
            // knob color
            QColor colorGreen(0x5D, 0xE7, 0x3D, 191 + fHoverStep*7);
            QColor colorBlue(0x3E, 0xB8, 0xBE, 191 + fHoverStep*7);

            // draw small circle
            QRectF ballRect(8.0f, 8.0f, 15.0f, 15.0f);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - std::floor(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            // draw arc
            int startAngle = 216*16;
            int spanAngle  = -252*16*value;

            if (fCustomPaint == CUSTOM_PAINT_CARLA_WET)
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2f, 2.2f));

                QConicalGradient gradient(15.5f, 15.5f, -45);
                gradient.setColorAt(0.0f,   colorBlue);
                gradient.setColorAt(0.125f, colorBlue);
                gradient.setColorAt(0.625f, colorGreen);
                gradient.setColorAt(0.75f,  colorGreen);
                gradient.setColorAt(0.76f,  colorGreen);
                gradient.setColorAt(1.0f,   colorGreen);
                painter.setBrush(gradient);
                painter.setPen(QPen(gradient, 3));
            }
            else
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2f, 2.2f));

                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 3));
            }

            painter.drawArc(4.0f, 4.0f, 26.0f, 26.0f, startAngle, spanAngle);
        }
        // Custom knobs (L and R)
        else if (fCustomPaint == CUSTOM_PAINT_CARLA_L || fCustomPaint == CUSTOM_PAINT_CARLA_R)
        {
            // knob color
            QColor color(0xAD + fHoverStep*5, 0xD5 + fHoverStep*4, 0x4B + fHoverStep*5);

            // draw small circle
            QRectF ballRect(7.0f, 8.0f, 11.0f, 12.0f);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - std::floor(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            painter.setBrush(color);
            painter.setPen(QPen(color, 0));
            painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0f, 2.0f));

            int startAngle, spanAngle;

            // draw arc
            if (fCustomPaint == CUSTOM_PAINT_CARLA_L)
            {
                startAngle = 216*16;
                spanAngle  = -252.0*16*value;
            }
            else if (fCustomPaint == CUSTOM_PAINT_CARLA_R)
            {
                startAngle = 324.0*16;
                spanAngle  = 252.0*16*(1.0-value);
            }
            else
                return;

            painter.setPen(QPen(color, 2));
            painter.drawArc(3.5f, 4.5f, 22.0f, 22.0f, startAngle, spanAngle);

            if (HOVER_MIN < fHoverStep && fHoverStep < HOVER_MAX)
            {
                fHoverStep += fHovered ? 1 : -1;
                QTimer::singleShot(20, this, SLOT(update()));
            }
        }

        if (HOVER_MIN < fHoverStep && fHoverStep < HOVER_MAX)
        {
            fHoverStep += fHovered ? 1 : -1;
            QTimer::singleShot(20, this, SLOT(update()));
        }
    }
    else
    {
        QRectF target(0.0f, 0.0f, fSize, fSize);
        painter.drawPixmap(target, fPixmap, target);
    }

    painter.restore();
}
Ejemplo n.º 6
0
void RenderManagerSDL::draw()
{
    if (!mDrawGame)
        return;

    SDL_RenderCopy(mRenderer,
                   mBackground,
                   NULL,
                   NULL);

    int animationState;
    SDL_Rect position;

    // Ball marker
    position.y = 5;
    position.x = (int)lround(mBallPosition.x - 2.5);
    position.w = 5;
    position.h = 5;
    SDL_RenderCopy(mRenderer, mMarker[(int)SDL_GetTicks() % 1000 >= 500], 0, &position);

    // Mouse marker
    position.y = 590;
    position.x = (int)lround(mMouseMarkerPosition - 2.5);
    position.w = 5;
    position.h = 5;
    SDL_RenderCopy(mRenderer, mMarker[(int)SDL_GetTicks() % 1000 >= 500], 0, &position);

    if(mShowShadow)
    {
        // Ball Shadow
        position = ballShadowRect(ballShadowPosition(mBallPosition));
        SDL_RenderCopy(mRenderer, mBallShadow, 0, &position);

        // Left blob shadow
        position = blobShadowRect(blobShadowPosition(mLeftBlobPosition));
        animationState = int(mLeftBlobAnimationState) % 5;
        SDL_RenderCopy(mRenderer, mLeftBlobShadow[animationState].mSDLsf, 0, &position);

        // Right blob shadow
        position = blobShadowRect(blobShadowPosition(mRightBlobPosition));
        animationState = int(mRightBlobAnimationState) % 5;
        SDL_RenderCopy(mRenderer, mRightBlobShadow[animationState].mSDLsf, 0, &position);
    }

    // Restore the rod
    position.x = 400 - 7;
    position.y = 300;
    SDL_Rect rodPosition;
    rodPosition.x = 400 - 7;
    rodPosition.y = 300;
    rodPosition.w = 14;
    rodPosition.h = 300;
    SDL_RenderCopy(mRenderer, mBackground, &rodPosition, &rodPosition);

#ifdef __APPLE__
#if !MAC_OS_X
    position.x = 400 - 35;
    position.y = 70;
    position.w = 70;
    position.h = 82;
    SDL_RenderCopy(mRenderer, mBackFlag, 0, &position);
#endif
#endif

    // Drawing the Ball
    position = ballRect(mBallPosition);
    animationState = int(mBallRotation / M_PI / 2 * 16) % 16;
    SDL_RenderCopy(mRenderer, mBall[animationState], 0, &position);

    // update blob colors
    colorizeBlobs(LEFT_PLAYER);
    colorizeBlobs(RIGHT_PLAYER);

    // Drawing left blob
    position = blobRect(mLeftBlobPosition);
    animationState = int(mLeftBlobAnimationState) % 5;
    SDL_RenderCopy(mRenderer, mLeftBlob[animationState].mSDLsf, 0, &position);

    // Drawing right blob
    position = blobRect(mRightBlobPosition);
    animationState = int(mRightBlobAnimationState) % 5;
    SDL_RenderCopy(mRenderer, mRightBlob[animationState].mSDLsf, 0, &position);
}