Пример #1
0
Texture<GLubyte> Texture<GLubyte>::copy() const
{
    Texture<GLubyte> texture(buffer().data(), filter(), internalFormat(), width(), height(), buffered(), wrapping());

    if(borderColor() != vec4(0))
        texture.setBorderColor(borderColor());

    return texture;
}
Пример #2
0
void Graphic::drawCell (int y, int x, int val) {

    sf::Color borderColor(101, 123, 131);
    sf::Color bgColor(88, 110, 117);
    sf::Color textColor(238, 232, 213);

    sf::RectangleShape square(sf::Vector2f(100, 100));

    square.setOutlineColor(borderColor);
    square.setOutlineThickness(2);
    square.setFillColor(bgColor);
    square.setPosition(x * 110 + 100 + 10, y * 110 + 10);
    this->_win->draw(square);

    // text
    std::string valStr = std::to_string(val);
    sf::Text    text(valStr, this->_font);
    sf::Text    shadow(valStr, this->_font);
    int         textX = static_cast<int>(x * 110 + 100 + 10 + 50 - text.getLocalBounds().width / 2);
    int         textY = y * 110 + 10 + 30;

    text.setCharacterSize(30);
    shadow.setCharacterSize(30);
    text.setColor(textColor);
    shadow.setColor(sf::Color(7, 54, 66));
    text.setPosition(textX, textY);
    shadow.setPosition(textX, textY + 2);
    this->_win->draw(shadow);
    this->_win->draw(text);
}
bool KstViewLabel::fillConfigWidget(QWidget *w, bool isNew) const {
  ViewLabelWidget *widget = dynamic_cast<ViewLabelWidget*>(w);
  if (!widget) {
    return false;
  }

  if (!isNew) {
    widget->_text->setText(text());
  }

  widget->_precision->setValue(int(dataPrecision()));
  widget->_rotation->setValue(double(rotation()));
  widget->_fontSize->setValue(int(fontSize()));
  widget->_horizontal->setCurrentItem(horizJustifyWrap());
  widget->_fontColor->setColor(foregroundColor());
  widget->_font->setCurrentFont(fontName());

  widget->_transparent->setChecked(transparent());
  widget->_border->setValue(borderWidth());
  widget->_boxColors->setForeground(borderColor());
  widget->_boxColors->setBackground(backgroundColor());
  widget->_margin->setValue(labelMargin());

  widget->_text->setFocus();

  return true;
}
Пример #4
0
/** fill the custom widget with current properties */
bool KstViewLegend::fillConfigWidget(QWidget *w, bool isNew) const {
  ViewLegendWidget *widget = dynamic_cast<ViewLegendWidget*>(w);
  if (!widget) {
    return false;
  }

  KstBaseCurveList allCurves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList);
  
  if (isNew) {
    widget->_fontSize->setValue(0);
    widget->_fontColor->setColor(KstSettings::globalSettings()->foregroundColor);
    widget->_font->setCurrentFont(KstApp::inst()->defaultFont());
    widget->_margin->setValue(5);
    widget->_boxColors->setColor(KstSettings::globalSettings()->foregroundColor);
    widget->_vertical->setChecked(true);
    widget->_transparent->setChecked(false);
    widget->_border->setValue(2);
    widget->_title->setText("");
    widget->TrackContents->setChecked(true);
 
    for (KstBaseCurveList::ConstIterator it = allCurves.begin(); it != allCurves.end(); ++it) {
      (*it)->readLock();
      widget->AvailableCurveList->insertItem((*it)->tagName());
      (*it)->unlock();
    }

  } else { // fill legend properties into widget
    widget->TrackContents->setChecked(trackContents());
    widget->_title->setText(title());
    widget->_fontSize->setValue(int(fontSize()));
    widget->_fontColor->setColor(foregroundColor());
    widget->_font->setCurrentFont(fontName());
    widget->_transparent->setChecked(transparent());
    widget->_border->setValue(borderWidth());
    widget->_boxColors->setColor(borderColor());
    widget->_margin->setValue(_legendMargin);
    widget->_vertical->setChecked(vertical());
    for (KstBaseCurveList::ConstIterator it = _curves.begin(); it != _curves.end(); ++it) {
      (*it)->readLock();
      widget->DisplayedCurveList->insertItem((*it)->tagName());
      (*it)->unlock();
    }
    for (KstBaseCurveList::ConstIterator it = allCurves.begin(); it != allCurves.end(); ++it) {
      (*it)->readLock();
      if (_curves.find(*it) == _curves.end()) {
        widget->AvailableCurveList->insertItem((*it)->tagName());
      }
      (*it)->unlock();
    }
  }
  return false;
}
Пример #5
0
void QgsCurveEditorWidget::addPlotMarker( double x, double y, bool isSelected )
{
  QColor borderColor( 0, 0, 0 );

  QColor brushColor = isSelected ? borderColor : QColor( 255, 255, 255, 0 );

  QwtPlotMarker *marker = new QwtPlotMarker();
  marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse,  QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 8, 8 ) ) );
  marker->setValue( x, y );
  marker->attach( mPlot );
  marker->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  mMarkers << marker;
}
Пример #6
0
bool KstViewLabel::fillConfigWidget(QWidget *w, bool isNew) const {
  ViewLabelWidget *widget = dynamic_cast<ViewLabelWidget*>(w);
  if (!widget) {
    return false;
  }
  
  if (isNew) { // probably a new label: set widget to defaults
    widget->_precision->setValue(8);
    widget->_rotation->setValue(0);
    widget->_fontSize->setValue(0);
    widget->_horizontal->setCurrentItem(0);
    widget->_fontColor->setColor(KstSettings::globalSettings()->foregroundColor);
    widget->_font->setCurrentFont(KstApp::inst()->defaultFont());
    widget->_margin->setValue(5);

    widget->_boxColors->setColor(KstSettings::globalSettings()->backgroundColor);

    if (size().width() * size().height() < 25) { // assume a click, and default to just text
      widget->_transparent->setChecked(true);
      widget->_border->setValue(0);
    } else { // someone drew a box, so assume that is what they wanted
      widget->_transparent->setChecked(false);
      widget->_border->setValue(2);
    }

  } else {
    // No, this is broken.  It kills latex.
#if 0
    // replace \n & \t with tabs and newlines for the text edit box
    QString tmpstr = text();
    tmpstr.replace(QString("\\n"), "\n");
    tmpstr.replace(QString("\\t"), "\t");
    widget->_text->setText(tmpstr);
#endif
    widget->_text->setText(text());

    widget->_precision->setValue(int(dataPrecision()));
    widget->_rotation->setValue(double(rotation()));
    widget->_fontSize->setValue(int(fontSize()));
    widget->_horizontal->setCurrentIndex(horizJustifyWrap());
    widget->_fontColor->setColor(foregroundColor());
    widget->_font->setCurrentFont(fontName());

    widget->_transparent->setChecked(transparent());
    widget->_border->setValue(borderWidth());
    widget->_boxColors->setColor(borderColor());
    widget->_margin->setValue(_labelMargin);
  }
  widget->_text->setFocus();
  return true;
}
Пример #7
0
QString Style::makeStyleSheet(const QString& _styleSheetTemplate) const {
  QString styleSheet(_styleSheetTemplate);
  return styleSheet.
    replace("%fontFamily%", fontFamily()).
    replace("%currentTheme%", getStyleId()).
    replace("%viewItemHeight%", QString("%1px").arg(viewItemHeight())).
    replace("%fontSizeTiny%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_TINY))).
    replace("%fontSizeSmall%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_SMALL))).
    replace("%fontSizeNormal%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_NORMAL))).
    replace("%fontSizeExtraNormal%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_EXTRA_NORMAL))).
    replace("%fontSizeLarge%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_LARGE))).
    replace("%fontSizeExtraLarge%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_EXTRA_LARGE))).
    replace("%fontSizeHuge%", QString("%1px").arg(static_cast<quint8>(FontSize::FONT_HUGE))).
    replace("%fontColorGray%", fontColorGray()).
    replace("%fontColorGreen%", fontColorGreen()).
    replace("%fontColorRed%", fontColorRed()).
    replace("%fontColorBlueNormal%", fontColorBlueNormal()).
    replace("%fontColorBlueHover%", fontColorBlueHover()).
    replace("%fontColorBluePressed%", fontColorBluePressed()).
    replace("%backgroundColorGray%", backgroundColorGray()).
    replace("%backgroundButtonColorGrayHover%", backgroundButtonColorGrayHover()).
    replace("%backgroundColorBlueNormal%", backgroundColorBlueNormal()).
    replace("%backgroundColorBlueHover%", backgroundColorBlueHover()).
    replace("%backgroundColorBluePressed%", backgroundColorBluePressed()).
    replace("%backgroundColorBlueDisabled%", backgroundColorBlueDisabled()).
    replace("%backgroundColorGrayNormal%", backgroundColorGrayNormal()).
    replace("%backgroundColorGrayHover%", backgroundColorGrayHover()).
    replace("%backgroundColorGrayPressed%", backgroundColorGrayPressed()).
    replace("%backgroundColorGreen%", backgroundColorGreen()).
    replace("%backgroundColorGreenHover%", backgroundColorGreenHover()).
    replace("%backgroundColorAlternate%", backgroundColorAlternate()).
    replace("%borderColor%", borderColor()).
    replace("%borderColorDark%", borderColorDark()).
    replace("%selectionColor%", selectionColor()).
    replace("%statusBarBackgroundColor%", statusBarBackgroundColor()).
    replace("%statusBarFontColor%", statusBarFontColor()).
    replace("%headerBackgroundColor%", headerBackgroundColor()).
    replace("%headerBorderColor%", headerBorderColor()).
    replace("%addressFontColor%", addressFontColor()).
    replace("%balanceFontColor%", balanceFontColor()).
    replace("%toolButtonBackgroundColorNormal%", toolButtonBackgroundColorNormal()).
    replace("%toolButtonBackgroundColorHover%", toolButtonBackgroundColorHover()).
    replace("%toolButtonBackgroundColorPressed%", toolButtonBackgroundColorPressed()).
    replace("%toolButtonFontColorNormal%", toolButtonFontColorNormal()).
    replace("%toolButtonFontColorDisabled%", toolButtonFontColorDisabled()).
    replace("%toolBarBorderColor%", toolBarBorderColor()).
    replace("%glassColor%", glassColor());
}
Пример #8
0
void PopupContainer::paintBorder(GraphicsContext* gc, const IntRect& rect)
{
    // FIXME: Where do we get the border color from?
    Color borderColor(127, 157, 185);

    gc->setStrokeStyle(NoStroke);
    gc->setFillColor(borderColor, ColorSpaceDeviceRGB);

    int tx = x();
    int ty = y();

    // top, left, bottom, right
    gc->drawRect(IntRect(tx, ty, width(), kBorderSize));
    gc->drawRect(IntRect(tx, ty, kBorderSize, height()));
    gc->drawRect(IntRect(tx, ty + height() - kBorderSize, width(), kBorderSize));
    gc->drawRect(IntRect(tx + width() - kBorderSize, ty, kBorderSize, height()));
}
Пример #9
0
    GraphLib::Object *Ellipse::copy()
    {
        Ellipse *ellipse = new Ellipse();

        ellipse->setCorner(corner());
        ellipse->setWidth(width());
        ellipse->setHeight(height());

        ellipse->setBorderWidth(borderWidth());
        ellipse->setBorderColor(borderColor());
        ellipse->setInnerColor(innerColor());
        ellipse->setShowBackground(showBackground());
        ellipse->setAspectType(aspectType());
        ellipse->setLineStyle(lineStyle());
        ellipse->setDashLength(dashLength());

        return ellipse;
    }
Пример #10
0
PStyle &PStyle::operator =(const PStyle &obj)
{
    inverted(obj.inverted());
    size(obj.size());
    lineWidth(obj.lineWidth());
    smooth(obj.smooth());
    leftPadding(obj.leftPadding());
    rightPadding(obj.rightPadding());
    topPadding(obj.topPadding());
    bottomPadding(obj.bottomPadding());
    foregroundColor(obj.foregroundColor());
    backgroundColor(obj.backgroundColor());
    borderColor(obj.borderColor());
    selectedForegroundColor(obj.selectedForegroundColor());
    selectedBackgroundColor(obj.selectedBackgroundColor());
    selectedBorderColor(obj.selectedBorderColor());

    return *this;
}
Пример #11
0
void SubWindow::paintEvent( QPaintEvent * )
{
	QPainter p( this );
	QRect rect( 0, 0, width(), m_titleBarHeight );
	bool isActive = SubWindow::mdiArea()->activeSubWindow() == this;

	p.fillRect( rect, isActive ? activeColor() : p.pen().brush() );

	// window border
	p.setPen( borderColor() );

	// bottom, left, and right lines
	p.drawLine( 0, height() - 1, width(), height() - 1 );
	p.drawLine( 0, m_titleBarHeight, 0, height() - 1 );
	p.drawLine( width() - 1, m_titleBarHeight, width() - 1, height() - 1 );

	// window icon
	QPixmap winicon( widget()->windowIcon().pixmap( m_buttonSize ) );
	p.drawPixmap( 3, 3, m_buttonSize.width(), m_buttonSize.height(), winicon );
}
Пример #12
0
void KisOpenGLCanvas2::renderCanvasGL()
{
    // Draw the border (that is, clear the whole widget to the border color)
    QColor widgetBackgroundColor = borderColor();
    glClearColor(widgetBackgroundColor.redF(), widgetBackgroundColor.greenF(), widgetBackgroundColor.blueF(), 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    if (d->displayFilter) {
        d->displayFilter->updateShader();
    }

    if (KisOpenGL::hasOpenGL3()) {
        d->quadVAO.bind();
    }
    drawCheckers();
    drawImage();
    if (KisOpenGL::hasOpenGL3()) {
        d->quadVAO.release();
    }
}
Пример #13
0
void LeafPanel::OnPaint(wxPaintEvent &event)
{
        //background...
        wxPaintDC dc(this);
        const int width = dc.GetSize().x;
        const int height = dc.GetSize().y;

        if (m_seleccionado) {
                dc.SetBrush(wxBrush(FONDO_ACTIVO));
                dc.SetPen(wxPen(FONDO_ACTIVO, 1, wxSOLID));
                m_pLabel->SetBackgroundColour(FONDO_ACTIVO);
                m_pLabel1->SetBackgroundColour(FONDO_ACTIVO);
        } else {
                if (m_rowEven) {
                        dc.SetBrush(wxBrush(FONDO_INACTIVO_E));
                        dc.SetPen(wxPen(FONDO_INACTIVO_E, 1, wxSOLID));
                        m_pLabel->SetBackgroundColour(FONDO_INACTIVO_E);
                        m_pLabel1->SetBackgroundColour(FONDO_INACTIVO_E);
                } else {
                        dc.SetBrush(wxBrush(FONDO_INACTIVO_O));
                        dc.SetPen(wxPen(FONDO_INACTIVO_O, 1, wxSOLID));
                        m_pLabel->SetBackgroundColour(FONDO_INACTIVO_O);
                        m_pLabel1->SetBackgroundColour(FONDO_INACTIVO_O);
                }
        }
        dc.DrawRectangle(0,0,width,height);
        //
        if (!m_dibujada) {
                //la primera vez que se pinta se lanza el timer que generara el thumbnail (bajo demanda)
                GNC::GCS::ThumbnailController::Instance()->requestThumbnail(m_pLeaf->GetFilePk(), this);
                m_dibujada = true;
        }
        LeafPanelBase::OnPaint(event);

        wxColour borderColor(0,0,0);
        dc.SetBrush(wxBrush(borderColor,wxTRANSPARENT));
        dc.SetPen(wxPen(borderColor, 1, wxSOLID));
        dc.DrawLine(wxPoint(0,0), wxPoint(0, dc.GetSize().y-1));
        dc.DrawLine(wxPoint(0, dc.GetSize().y-1), wxPoint(dc.GetSize().x - 1, dc.GetSize().y-1));
        dc.DrawLine(wxPoint(dc.GetSize().x - 1, 0), wxPoint(dc.GetSize().x - 1, dc.GetSize().y-1));
}
Пример #14
0
void KstViewBox::paintSelf(KstPainter& p, const QRegion& bounds) {
  p.save();
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
    if (p.makingMask()) {
      p.setRasterOp(Qt::SetROP);
    } else {
      const QRegion clip(clipRegion());
      KstViewObject::paintSelf(p, bounds - clip);
      p.setClipRegion(bounds & clip);
    }
  }

  // restrict the border width so we do not draw outside of the rectangle itself
  int bw(borderWidth() * p.lineWidthAdjustmentFactor());
  if (bw > _geom.width() / 2) {
    bw = _geom.width() / 2;
  }
  if (bw > _geom.height()) {
    bw = _geom.height() / 2;
  }
  
  QPen pen(borderColor(), bw);
  pen.setJoinStyle(_cornerStyle);
  if (bw == 0) {
    pen.setStyle(Qt::NoPen);
  }
  p.setPen(pen);
  if (_transparentFill) {
    p.setBrush(Qt::NoBrush);  
  } else {
    p.setBrush(_foregroundColor);
  }
  QRect r;
  r.setX(_geom.left() + bw / 2);
  r.setY(_geom.top() + bw / 2);
  r.setWidth(_geom.width() - bw);
  r.setHeight(_geom.height() - bw);

  p.drawRoundRect(r, _xRound, _yRound);
  p.restore();
}
Пример #15
0
void CommonWidget::drawBorder(const bool &pDockedTop, const bool &pDockedLeft,
                              const bool &pDockedBottom, const bool &pDockedRight,
                              const bool &pFloatingTop, const bool &pFloatingLeft,
                              const bool &pFloatingBottom, const bool &pFloatingRight)
{
    // Draw a border around the widget
    // Note: a qobject_cast is not good enough for mParent on OS X, so...

    QDockWidget *dockWidget = dynamic_cast<QDockWidget *>(mParent);
    QWidget *widget = dynamic_cast<QWidget *>(this);

    if (dockWidget && widget) {
        // The castings were successful, so our parent is really a QDockWidget,
        // we are really a QWidget, and to top it all our parent is floating (or
        // we want to force the drawing), so let's go ahead...

        QPainter painter(widget);

        QPen newPen = painter.pen();

        newPen.setColor(borderColor());

        painter.setPen(newPen);

        bool isDocked = !dockWidget->isFloating();
        QRect border = widget->rect();

        if ((pDockedTop && isDocked) || (pFloatingTop && !isDocked))
            painter.drawLine(border.topLeft(), border.topRight());

        if ((pDockedLeft && isDocked) || (pFloatingLeft && !isDocked))
            painter.drawLine(border.topLeft(), border.bottomLeft());

        if ((pDockedBottom && isDocked) || (pFloatingBottom && !isDocked))
            painter.drawLine(border.bottomLeft(), border.bottomRight());

        if ((pDockedRight && isDocked) || (pFloatingRight && !isDocked))
            painter.drawLine(border.topRight(), border.bottomRight());
    }
}
Пример #16
0
Файл: Main.cpp Проект: DaZhu/gac
	CustomTemplateWindowStyle()
		:window(0)
	{
		Color borderColor(0, 122, 204);
		Color titleBackgroundColor(45, 45, 48);
		Color backgroundColor(30, 30, 30);
		Color titleColor(153, 153, 153);

		boundsComposition=new GuiTableComposition;
		boundsComposition->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
		boundsComposition->SetRowsAndColumns(4, 7);
		boundsComposition->SetRowOption(0, GuiCellOption::AbsoluteOption(5));
		boundsComposition->SetRowOption(1, GuiCellOption::MinSizeOption());
		boundsComposition->SetRowOption(2, GuiCellOption::PercentageOption(1.0));
		boundsComposition->SetRowOption(3, GuiCellOption::AbsoluteOption(5));
		boundsComposition->SetColumnOption(0, GuiCellOption::AbsoluteOption(5));
		boundsComposition->SetColumnOption(1, GuiCellOption::MinSizeOption());
		boundsComposition->SetColumnOption(2, GuiCellOption::PercentageOption(1.0));
		boundsComposition->SetColumnOption(3, GuiCellOption::MinSizeOption());
		boundsComposition->SetColumnOption(4, GuiCellOption::MinSizeOption());
		boundsComposition->SetColumnOption(5, GuiCellOption::MinSizeOption());
		boundsComposition->SetColumnOption(6, GuiCellOption::AbsoluteOption(5));
		{
			GuiSolidBackgroundElement* element=GuiSolidBackgroundElement::Create();
			element->SetColor(borderColor);
			boundsComposition->SetOwnedElement(element);
		}
		AddBorderCell(0, 0, 1, 1, INativeWindowListener::BorderLeftTop);
		AddBorderCell(0, 6, 1, 1, INativeWindowListener::BorderRightTop);
		AddBorderCell(3, 0, 1, 1, INativeWindowListener::BorderLeftBottom);
		AddBorderCell(3, 6, 1, 1, INativeWindowListener::BorderRightBottom);
		AddBorderCell(1, 0, 2, 1, INativeWindowListener::BorderLeft);
		AddBorderCell(1, 6, 2, 1, INativeWindowListener::BorderRight);
		AddBorderCell(0, 1, 1, 5, INativeWindowListener::BorderTop);
		AddBorderCell(3, 1, 1, 5, INativeWindowListener::BorderBottom);
		{
			{
				iconComposition=AddTitleCell(1, INativeWindowListener::Icon, titleBackgroundColor);
				iconComposition->SetAlignmentToParent(Margin(3, 3, 3, 3));

				Ptr<INativeImage> icon=GetCurrentController()->ImageService()->CreateImageFromFile(GetApplication()->GetExecutableFolder()+L"..\\Resources\\BigDoc.png");
				iconElement=GuiImageFrameElement::Create();
				iconElement->SetImage(icon, 0);
				iconElement->SetStretch(true);
				iconComposition->SetOwnedElement(iconElement);
			}
			{
				titleComposition=AddTitleCell(2, INativeWindowListener::Title, titleBackgroundColor);
				titleComposition->SetAlignmentToParent(Margin(0, 3, 3, 3));

				titleElement=GuiSolidLabelElement::Create();
				titleElement->SetColor(titleColor);
				titleElement->SetAlignments(Alignment::Left, Alignment::Center);
				titleComposition->SetOwnedElement(titleElement);
			}
			{
				minimumButton=AddTitleButton(3, titleBackgroundColor, titleColor);
				minimumButton->GetBoundsComposition()->SetAlignmentToParent(Margin(0, 3, 3, 3));
				minimumButton->Clicked.AttachMethod(this, &CustomTemplateWindowStyle::minimumButton_Clicked);
			}
			{
				maximumButton=AddTitleButton(4, titleBackgroundColor, titleColor);
				maximumButton->GetBoundsComposition()->SetAlignmentToParent(Margin(0, 3, 3, 3));
				maximumButton->Clicked.AttachMethod(this, &CustomTemplateWindowStyle::maximumButton_Clicked);
			}
			{
				closeButton=AddTitleButton(5, titleBackgroundColor, titleColor);
				closeButton->GetBoundsComposition()->SetAlignmentToParent(Margin(0, 3, 3, 3));
				closeButton->Clicked.AttachMethod(this, &CustomTemplateWindowStyle::closeButton_Clicked);
			}
		}
		{
			GuiCellComposition* cell=new GuiCellComposition;
			boundsComposition->AddChild(cell);
			cell->SetSite(2, 1, 1, 5);
			cell->SetAssociatedHitTestResult(INativeWindowListener::Client);

			containerComposition=new GuiBoundsComposition;
			containerComposition->SetAlignmentToParent(Margin(0, 0, 0, 0));
			cell->AddChild(containerComposition);

			GuiSolidBackgroundElement* element=GuiSolidBackgroundElement::Create();
			element->SetColor(backgroundColor);
			containerComposition->SetOwnedElement(element);
		}
	}
Пример #17
0
void KisQPainterCanvas::paintEvent(QPaintEvent * ev)
{
    KisImageWSP image = canvas()->image();
    if (image == 0) return;

    setAutoFillBackground(false);

    if (m_buffer.size() != size()) {
        m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
    }


    QPainter gc(&m_buffer);

    // we double buffer, so we paint on an image first, then from the image onto the canvas,
    // so copy the clip region since otherwise we're filling the whole buffer every time with
    // the background color _and_ the transparent squares.
    gc.setClipRegion(ev->region());

    KisCoordinatesConverter *converter = coordinatesConverter();
    QTransform imageTransform = converter->viewportToWidgetTransform();

    gc.save();

    gc.setCompositionMode(QPainter::CompositionMode_Source);
    gc.fillRect(QRect(QPoint(0, 0), size()), borderColor());

    QTransform checkersTransform;
    QPointF brushOrigin;
    QPolygonF polygon;

    converter->getQPainterCheckersInfo(&checkersTransform, &brushOrigin, &polygon);
    gc.setPen(Qt::NoPen);
    gc.setBrush(m_d->checkBrush);
    gc.setBrushOrigin(brushOrigin);
    gc.setTransform(checkersTransform);
    gc.drawPolygon(polygon);

    gc.setTransform(imageTransform);
    gc.setRenderHint(QPainter::SmoothPixmapTransform, true);

    QRectF viewportRect = converter->widgetToViewport(ev->rect());

    gc.setCompositionMode(QPainter::CompositionMode_SourceOver);
    gc.drawImage(viewportRect, m_d->prescaledProjection->prescaledQImage(),
                 viewportRect);

    gc.restore();


#ifdef DEBUG_REPAINT
    QColor color = QColor(random() % 255, random() % 255, random() % 255, 150);
    gc.fillRect(ev->rect(), color);
#endif

    drawDecorations(gc, ev->rect());
    gc.end();

    QPainter painter(this);
    painter.drawImage(ev->rect(), m_buffer, ev->rect());
}
Пример #18
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void OverlayTextBox::renderBackgroundAndBorder(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
{
    CVF_CALLSITE_OPENGL(oglContext);

    // Prepare 2D pixel exact projection to draw texts
    Camera projCam;
    projCam.setViewport(position.x(), position.y(), size.x(), size.y());
    projCam.setProjectionAsPixelExact2D();
    projCam.setViewMatrix(Mat4d::IDENTITY);

    // Turn off depth test
    RenderStateDepth depth(false, RenderStateDepth::LESS, false);
    depth.applyOpenGL(oglContext);

    ref<ShaderProgram> backgroundShader;
    float vertexArray[12];

    projCam.viewport()->applyOpenGL(oglContext, Viewport::DO_NOT_CLEAR);

    if (software)
    {
        if (ShaderProgram::supportedOpenGL(oglContext))
        {
            ShaderProgram::useNoProgram(oglContext);
        }

#ifndef CVF_OPENGL_ES
        RenderStateMaterial_FF mat;
        mat.enableColorMaterial(true);
        mat.applyOpenGL(oglContext);

        RenderStateLighting_FF light(false);
        light.applyOpenGL(oglContext);
#endif
        projCam.applyOpenGL();
    }
    else
    {
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glEnableVertexAttribArray(ShaderProgram::VERTEX);
        glVertexAttribPointer(ShaderProgram::VERTEX, 3, GL_FLOAT, GL_FALSE, 0, vertexArray);

        backgroundShader = oglContext->resourceManager()->getLinkedUnlitColorShaderProgram(oglContext);
        if (backgroundShader->useProgram(oglContext))
        {
            MatrixState projMatrixState(projCam);
            backgroundShader->clearUniformApplyTracking();
            backgroundShader->applyFixedUniforms(oglContext, projMatrixState);
        }
    }

    Vec3f min(1.0f, 1.0f, 0.0f);
    Vec3f max(static_cast<float>(size.x() - 1), static_cast<float>(size.y() - 1), 0.0f);

    // Setup the vertex array
    float* v1 = &vertexArray[0];
    float* v2 = &vertexArray[3];
    float* v3 = &vertexArray[6];
    float* v4 = &vertexArray[9];
    v1[0] = min.x();
    v1[1] = min.y();
    v1[2] = 0.0f;
    v2[0] = max.x();
    v2[1] = min.y();
    v2[2] = 0.0f;
    v3[0] = max.x();
    v3[1] = max.y();
    v3[2] = 0.0f;
    v4[0] = min.x();
    v4[1] = max.y();
    v4[2] = 0.0f;

    if (m_drawBackground)
    {
        if (software)
        {
#ifndef CVF_OPENGL_ES
            glColor4fv(m_backgroundColor.ptr());
            glBegin(GL_TRIANGLE_FAN);
            glVertex3fv(v1);
            glVertex3fv(v2);
            glVertex3fv(v3);
            glVertex3fv(v4);
            glEnd();
#endif
        }
        else
        {
            // Draw background
            UniformFloat backgroundColor("u_color", Color4f(m_backgroundColor));
            backgroundShader->applyUniform(oglContext, backgroundColor);
            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
        }
    }

    if (m_drawBorder)
    {
        if (software)
        {
#ifndef CVF_OPENGL_ES
            glColor3fv(m_borderColor.ptr());
            glBegin(GL_LINE_LOOP);
            glVertex3fv(v1);
            glVertex3fv(v2);
            glVertex3fv(v3);
            glVertex3fv(v4);
            glEnd();
#endif
        }
        else
        {
            UniformFloat borderColor("u_color", Color4f(m_borderColor));
            backgroundShader->applyUniform(oglContext, borderColor);

            RenderStateLine line(static_cast<float>(3));
            line.applyOpenGL(oglContext);

            // Draw border
            glDrawArrays(GL_LINE_LOOP, 0, 4);

            RenderStateLine resetLine;
            resetLine.applyOpenGL(oglContext);
        }
    }
}