예제 #1
0
void UIComponentTabView::onRender(GraphicsDevice* renderer, Widget* view)
{
	RectangleShape topRect(FloatRect(view->getPosition().x, view->getPosition().y, view->getSize().x, 20.f), Color::White);
	renderer->draw(topRect);

	RectangleShape bottomRect(FloatRect(view->getPosition().x, view->getPosition().y + 20, view->getSize().x, view->getSize().y - 20.f), Color::Orange);
	renderer->draw(bottomRect);
}
예제 #2
0
TEST(TransparencyWin, DISABLED_TranslateScaleOpaqueCompositeLayer)
{
    OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1));

    // The background is white on top with red on bottom.
    Color white(0xFFFFFFFF);
    FloatRect topRect(0, 0, 16, 8);
    src->context()->fillRect(topRect, white);
    Color red(0xFFFF0000);
    FloatRect bottomRect(0, 8, 16, 8);
    src->context()->fillRect(bottomRect, red);

    src->context()->save();

    // Translate left by one pixel.
    AffineTransform left;
    left.translate(-1, 0);

    // Scale by 2x.
    AffineTransform scale;
    scale.scale(2.0);
    src->context()->concatCTM(scale);

    // Then translate up by one pixel (which will actually be 2 due to scaling).
    AffineTransform up;
    up.translate(0, -1);
    src->context()->concatCTM(up);

    // Now draw 50% red square.
    {
        // Create a transparency helper inset one pixel in the buffer. The
        // coordinates are before transforming into this space, and maps to
        // IntRect(1, 1, 14, 14).
        TransparencyWin helper;
        helper.init(src->context(),
                    TransparencyWin::OpaqueCompositeLayer,
                    TransparencyWin::KeepTransform,
                    IntRect(1, -15, 14, 14));

        // Fill with red.
        helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000));
        clearTopLayerAlphaChannel(helper.context());
        helper.composite();
    }
}
// ImageViewDialog message handlers
void ImageViewDialog::OnPaint() {
  BufferredPaintDC dc(this);
  
  CRect rectTitle;
  GetDlgItem(IDC_PLACE_CAPTION)->GetWindowRect(&rectTitle);
  ScreenToClient(&rectTitle);
  dc.FillSolidRect(rectTitle, RGB(54, 133, 214));

  CRect imageRect;
  GetDlgItem(IDC_PLACE_IMAGE)->GetWindowRect(&imageRect);
  ScreenToClient(&imageRect);
  dc.FillSolidRect(imageRect, RGB(0, 0, 0));

  CRect topRect(imageRect.left, imageRect.top, 
      imageRect.right, imageRect.top + imageRect.Height() / 2);
  CRect bottomRect(imageRect.left, topRect.bottom, imageRect.right, imageRect.bottom);
  dc.SetStretchBltMode(HALFTONE);
  DrawImage(&dc, &topImage_, topRect);
  DrawImage(&dc, &bottomImage_, bottomRect);
}
예제 #4
0
void WinBarDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
    if(index.isValid() && index.data(ChannelData).isValid()){
        painter->save();
        painter->setRenderHint(QPainter::Antialiasing);

        /**************配置*****************/
        QRectF rect(option.rect.marginsAdded(margins));
        if(option.state & QStyle::State_Sunken && option.state & QStyle::State_HasFocus){
            rect.moveTo(rect.x() + 1, rect.y() + 1);
        }
        QRectF topRect(rect);
        topRect.setHeight(rect.height()/6);
        QFont font = option.font;
        font.setFamily(font.defaultFamily());

        /*****************色卡*****************/
        QRectF colorRect(topRect);
        colorRect.setHeight(topRect.height()/5 * 3);
        painter->setPen(QColor(0,0,0,0));
        painter->setBrush(QColor(index.data(ChannelColor).value<QColor>()));
        painter->drawRoundedRect(colorRect,5,5);

        /****************头部背景色**************/
        QRectF headRect(topRect);
        headRect.setTop(colorRect.center().y());
        painter->setBrush(QBrush(QColor(240,240,240)));
        painter->drawRect(headRect);

        /******************底部背景色*******************/
        QRectF bottomRect(rect);
        bottomRect.setTop(topRect.bottom() + 2);
        painter->setPen(QColor(0,0,0,0));
        painter->setBrush(QBrush(QColor(240,240,240)));
        painter->drawRect(bottomRect);

        /******************色柱********************/
        QRectF barRect(bottomRect);
        quint8 base = index.data(ChannelBarBase).toUInt();
        qreal mesureVal = index.data(ChannelData).toDouble();
        qreal rangeUpper = index.data(ChannelDispUpper).toDouble();
        qreal rangeDowner = index.data(ChannelDispDowner).toDouble();
        if(mesureVal >= 0){
            barRect.setTop(barRect.top() + barRect.height()/2 * (1 - mesureVal/rangeUpper));
        }else if(mesureVal < 0){
            barRect.setTop(barRect.top() + barRect.height()/2 * (1 + mesureVal/rangeDowner));
        }
        if(base == 1){
            barRect.setBottom(bottomRect.center().y());
        }else if(base == 2){
            barRect.setBottom(bottomRect.top());
        }
        painter->setPen(QColor(0,0,0,0));
        painter->setBrush(QColor(index.data(ChannelColor).value<QColor>()));
        painter->drawRect(barRect);

        /****************光泽效果*****************/
        QLinearGradient skinColor(rect.topLeft(),rect.topRight());
        skinColor.setColorAt(0,QColor(255,255,255,0));
        skinColor.setColorAt(0.09,QColor(255,255,255,0));
        skinColor.setColorAt(0.1,QColor(255,255,255,200));
        skinColor.setColorAt(0.13,QColor(255,255,255,200));
        skinColor.setColorAt(0.14,QColor(255,255,255,80));
        skinColor.setColorAt(0.50,QColor(0,0,0,20));
        skinColor.setColorAt(0.75,QColor(0,0,0,10));
        skinColor.setColorAt(0.76,QColor(255,255,255,30));
        skinColor.setColorAt(0.95,QColor(255,255,255,150));
        skinColor.setColorAt(0.96,QColor(255,255,255,0));
        skinColor.setColorAt(1,QColor(255,255,255,0));
        painter->setPen(QPen(QColor(200,230,255,0)));
        painter->setBrush(skinColor);
        painter->drawRect(rect);

        /*****************刻度*********************/
        qreal baseX = bottomRect.right();
        qreal baseY = bottomRect.top();
        qreal len = bottomRect.width()/8;
        quint8 count = index.data(ChannelBarDiv).toUInt();
        qreal span = bottomRect.height()/count;
        painter->setPen(Qt::black);
        painter->setBrush(QBrush(QColor(0,0,0,0)));
        for(quint8 i=1; i<count; ++i){
            painter->drawLine(baseX - len, baseY + i*span, baseX, baseY + i*span);
        }

        /**************量程*****************/
        QRectF valRect(bottomRect);
        valRect.setHeight(span);
        font.setPixelSize(valRect.height()/2);
        painter->setFont(font);
        painter->setPen(QPen(Qt::black,1));
        painter->drawText(valRect,QString::number(rangeUpper,'f',4));
        valRect.moveBottom(bottomRect.bottom());
        painter->drawText(valRect,Qt::AlignBottom,QString::number(rangeDowner,'f',4));

        /**************测量值*********************/
        valRect.moveBottom(barRect.top());
        if(valRect.top() < baseY + span){
            valRect.moveTop(baseY + span);
        }else if(valRect.bottom() > bottomRect.bottom() - 2 * span){
            valRect.moveBottom(bottomRect.bottom() - 2 * span);
        }
        painter->drawText(valRect,Qt::AlignBottom|Qt::AlignHCenter,QString::number(mesureVal,'f',4));

        /*******************单位***********************/
        valRect.moveTop(valRect.bottom());
        valRect.setRight(baseX - len);
        //painter->setPen(QColor(100,100,100));
        painter->drawText(valRect,Qt::AlignRight|Qt::AlignTop,index.data(ChannelUnit).toString());

        /****************标记********************/
        font.setPixelSize(headRect.height()/2);
        painter->setFont(font);
        painter->setPen(QColor(100,100,100));
        painter->drawText(headRect,Qt::AlignCenter,index.data(ChannelTag).toString());

        /*****************擦除头尾连接**********************/
        painter->setBrush(QBrush(QColor(0,0,0,0)));
        painter->setPen(QPen(Qt::black,1));
        painter->drawRect(bottomRect);
        painter->eraseRect(QRectF(topRect.bottomLeft(), bottomRect.topRight()));

        /*********************按压效果*************************/
        if(option.state & QStyle::State_Sunken && option.state & QStyle::State_HasFocus){
            painter->setPen(QPen(QColor(0,0,255,100),3));
            painter->setBrush(QBrush(QColor(180,180,180,50)));
            painter->drawRoundedRect(rect,6,6);
        }

        painter->restore();
    }
}
예제 #5
0
bool RenderThemeGtk::paintInnerSpinButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
    // We expand the painted area by 2 pixels on the top and bottom and 2 pixels on the right. This
    // is because GTK+ themes want to draw over the text box borders, but WebCore renders the inner
    // spin button inside the text box.
    IntRect expandedRect(rect);
    expandedRect.inflateY(2);
    expandedRect.setWidth(rect.width() + 2);

    WidgetRenderingContext widgetContext(paintInfo.context, expandedRect);
    GtkWidget* widget = gtkSpinButton();
    gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style().direction()));

    IntRect fullSpinButtonRect(IntPoint(), expandedRect.size());
    widgetContext.gtkPaintBox(fullSpinButtonRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "spinbutton");

    bool upPressed = isSpinUpButtonPartPressed(renderObject);
    bool upHovered = isSpinUpButtonPartHovered(renderObject);
    bool controlActive = isEnabled(renderObject) && !isReadOnlyControl(renderObject);
    GtkShadowType shadowType = upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;

    GtkStateType stateType = GTK_STATE_INSENSITIVE;
    if (controlActive) {
        if (isPressed(renderObject) && upPressed)
            stateType = GTK_STATE_ACTIVE;
        else if (isHovered(renderObject) && upHovered)
            stateType = GTK_STATE_PRELIGHT;
        else
            stateType = GTK_STATE_NORMAL;
    }
    IntRect topRect(IntPoint(), expandedRect.size());
    topRect.setHeight(expandedRect.height() / 2);
    widgetContext.gtkPaintBox(topRect, widget, stateType, shadowType, "spinbutton_up");

    // The arrow size/position calculation here is based on the arbitrary gymnastics that happen
    // in gtkspinbutton.c. It isn't pretty there and it isn't pretty here. This manages to make
    // the button look native for many themes though.
    IntRect arrowRect;
    int arrowSize = (expandedRect.width() - 3) / 2;
    arrowSize -= (arrowSize % 2) - 1; // Force odd.
    arrowRect.setWidth(arrowSize);
    arrowRect.setHeight(arrowSize);
    arrowRect.move((expandedRect.width() - arrowRect.width()) / 2,
                   (topRect.height() - arrowRect.height()) / 2 + 1);
    widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_UP, "spinbutton");

    shadowType = isPressed(renderObject) && !upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
    if (controlActive) {
        if (isPressed(renderObject) && !upPressed)
            stateType = GTK_STATE_ACTIVE;
        else if (isHovered(renderObject) && !upHovered)
            stateType = GTK_STATE_PRELIGHT;
        else
            stateType = GTK_STATE_NORMAL;
    }
    IntRect bottomRect(IntPoint(0, expandedRect.height() / 2), expandedRect.size());
    bottomRect.setHeight(expandedRect.height() - bottomRect.y());
    widgetContext.gtkPaintBox(bottomRect, widget, stateType, shadowType, "spinbutton_down");

    arrowRect.setY(arrowRect.y() + bottomRect.y() - 1);
    widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_DOWN, "spinbutton");

    return false;
}
예제 #6
0
void
TouchpadView::DrawSliders()
{
	BView* view;
	if (fOffScreenView != NULL)
		view = fOffScreenView;
	else
		view = this;

	if (!LockLooper())
		return;

	if (fOffScreenBitmap->Lock()) {
		view->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		view->FillRect(Bounds());
		view->SetHighColor(100, 100, 100);
		view->FillRoundRect(fPadRect, 4, 4);

		int32 dragSize = 3; // half drag size

		// scroll areas
		view->SetHighColor(145, 100, 100);
		BRect rightRect(fPadRect.left + fXScrollRange,  fPadRect.top,
			fPadRect.right, fPadRect.bottom);
		view->FillRoundRect(rightRect, 4, 4);

		BRect bottomRect(fPadRect.left, fPadRect.top + fYScrollRange,
			fPadRect.right, fPadRect.bottom);
		view->FillRoundRect(bottomRect, 4, 4);

		// Stroke Rect
		view->SetHighColor(100, 100, 100);
		view->SetPenSize(2);
		view->StrokeRoundRect(fPadRect, 4, 4);

		// x scroll range line
		view->SetHighColor(200, 0, 0);
		view->StrokeLine(BPoint(fPadRect.left + fXScrollRange, fPadRect.top),
			BPoint(fPadRect.left + fXScrollRange, fPadRect.bottom));

		fXScrollDragZone = BRect(fPadRect.left + fXScrollRange - dragSize,
			fPadRect.top - dragSize, fPadRect.left + fXScrollRange + dragSize,
			fPadRect.bottom + dragSize);
		fXScrollDragZone1 = BRect(fPadRect.left + fXScrollRange - dragSize,
			fPadRect.top - dragSize, fPadRect.left + fXScrollRange + dragSize,
			fPadRect.top + dragSize);
		view->FillRect(fXScrollDragZone1);
		fXScrollDragZone2 = BRect(fPadRect.left + fXScrollRange - dragSize,
			fPadRect.bottom - dragSize,
			fPadRect.left + fXScrollRange + dragSize,
			fPadRect.bottom + dragSize);
		view->FillRect(fXScrollDragZone2);

		// y scroll range line
		view->StrokeLine(BPoint(fPadRect.left, fPadRect.top + fYScrollRange),
			BPoint(fPadRect.right, fPadRect.top  + fYScrollRange));

		fYScrollDragZone = BRect(fPadRect.left - dragSize,
			fPadRect.top + fYScrollRange - dragSize,
			fPadRect.right  + dragSize,
			fPadRect.top + fYScrollRange + dragSize);
		fYScrollDragZone1 = BRect(fPadRect.left - dragSize,
			fPadRect.top + fYScrollRange - dragSize, fPadRect.left  + dragSize,
			fPadRect.top + fYScrollRange + dragSize);
		view->FillRect(fYScrollDragZone1);
		fYScrollDragZone2 = BRect(fPadRect.right - dragSize,
			fPadRect.top + fYScrollRange - dragSize, fPadRect.right  + dragSize,
			fPadRect.top + fYScrollRange + dragSize);
		view->FillRect(fYScrollDragZone2);

		fOffScreenView->Sync();
		fOffScreenBitmap->Unlock();
		DrawBitmap(fOffScreenBitmap, B_ORIGIN);
	}

	UnlockLooper();
}
예제 #7
0
void MScene::drawForeground(QPainter *painter, const QRectF &rect)
{
    Q_D(MScene);

    /* Overlay information on the widgets in development mode */
    if (MApplication::showBoundingRect() || MApplication::showSize() || MApplication::showPosition() || MApplication::showMargins() || MApplication::showObjectNames() || MApplication::showStyleNames()) {
        QList<QGraphicsItem *> itemList = items(rect);
        QList<QGraphicsItem *>::iterator item;

        painter->setFont(TextFont);
        int fontHeight = d->metrics.height();
        QTransform rotationMatrix;
        painter->setTransform(rotationMatrix);

        QList<QGraphicsItem *>::iterator end = itemList.end();
        for (item = itemList.begin(); item != end; ++item) {
            QRectF br = (*item)->boundingRect();
            QPolygonF bp = (*item)->mapToScene(br);

            if (MApplication::showBoundingRect()) {
                if (!dynamic_cast<MApplicationPage *>(*item)) { // filter out page for clarity
                    painter->setOpacity(BoundingRectOpacity);
                    painter->setPen(d->boundingRectLinePen);
                    painter->setBrush(d->boundingRectFillBrush);
                    painter->drawPolygon(bp);
                }
            }

            if (MApplication::showMargins()) {
                // Draw content margins
                QGraphicsLayoutItem *layoutItem = dynamic_cast<QGraphicsLayoutItem *>(*item);
                if (layoutItem) {
                    qreal left, top, right, bottom;
                    layoutItem->getContentsMargins(&left, &top, &right, &bottom);

                    QRectF outerRect = (*item)->mapRectToScene(br);
                    QRectF innerRect = (*item)->mapRectToScene(br.adjusted(left, top, -right, -bottom));

                    QRectF leftRect(outerRect.x(), outerRect.y(), innerRect.x() - outerRect.x(), outerRect.height());
                    QRectF topRect(innerRect.x(), outerRect.y(), innerRect.width(), innerRect.y() - outerRect.y());
                    QRectF rightRect(innerRect.bottomRight().x(), outerRect.y(), outerRect.bottomRight().x() - innerRect.bottomRight().x(), outerRect.height());
                    QRectF bottomRect(innerRect.x(), innerRect.bottomRight().y(), innerRect.width(), outerRect.bottomRight().y() - innerRect.bottomRight().y());

                    painter->setOpacity(0.5);

                    d->fillMarginRectWithPattern(painter, leftRect, leftRect.width());
                    d->fillMarginRectWithPattern(painter, topRect, topRect.height());
                    d->fillMarginRectWithPattern(painter, rightRect, rightRect.width());
                    d->fillMarginRectWithPattern(painter, bottomRect, bottomRect.height());

                }

                painter->setOpacity(1.0);
            }

            if (MApplication::showPosition()) {
                QPointF topLeft = ((*item)->mapToScene(br.topLeft()));
                QString posStr = QString("(%1, %2)").arg(topLeft.x()).arg(topLeft.y());
                painter->setPen(Qt::black);
                painter->drawText(topLeft += QPointF(5, fontHeight), posStr);
                painter->setPen(Qt::white);
                painter->drawText(topLeft -= QPointF(1, 1),  posStr);
            }

            if (MApplication::showSize()) {
                QPointF bottomRight = ((*item)->mapToScene(br.bottomRight()));
                QPointF pos = (*item)->mapToScene(br.topLeft());
                QString sizeStr = QString("%1x%2 (%3,%4)").arg(br.width()).arg(br.height()).arg(pos.x()).arg(pos.y());
                painter->setPen(Qt::black);
                painter->drawText(bottomRight -= QPointF(d->metrics.width(sizeStr), 2), sizeStr);
                painter->setPen(Qt::white);
                painter->drawText(bottomRight -= QPointF(1, 1), sizeStr);
            }

            if (MApplication::showObjectNames()) {
                d->drawObjectNames(painter, item);
            }

            if (MApplication::showStyleNames()) {
                d->drawStyleNames(painter, item);
            }
        }
    }

    bool countingFps = MApplication::logFps() || MApplication::showFps();
    if (countingFps) {
        if (d->fps.frameCount < 0) {
            d->fps.time.restart();
            d->fps.frameCount = 0;
        }
        ++d->fps.frameCount;

        int ms = d->fps.time.elapsed();
        if (ms > FpsRefreshInterval) {
            float fps = d->fps.frameCount * 1000.0f / ms;
            d->fps.time.restart();
            d->fps.frameCount = 0;
            if (MApplication::logFps()) {
                QTime time = d->fps.time.currentTime();
                d->logFpsCounter(&time, fps);
            }
            d->fps.fps = fps;
        }

        if (MApplication::showFps()) {
            d->showFpsCounter(painter, d->fps.fps);
        }

        // this update call makes repainting work as fast
        // as possible, and by that prints useful fps numbers
        QTimer::singleShot(0, this, SLOT(update()));
    } else {
        d->fps.frameCount = -1;
    }

    if (MApplication::emulateTwoFingerGestures() &&
        d->pinchEmulationEnabled)
    {
        static const QPixmap *tapPixmap = MTheme::pixmap("meegotouch-tap");
        QPointF pixmapCenterDelta(tapPixmap->width() / 2, tapPixmap->height() / 2);

        painter->drawPixmap(d->emuPoint1.scenePos() - pixmapCenterDelta, *tapPixmap);
        painter->drawPixmap(d->emuPoint2.scenePos() - pixmapCenterDelta, *tapPixmap);
    }
}