コード例 #1
0
ファイル: RectangleTest.cpp プロジェクト: JanDupal/magnum
void RectangleTest::access() {
    Rectanglei rect({34, 23}, {47, 30});
    constexpr Rectanglei crect({34, 23}, {47, 30});

    CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23));
    CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30));
    CORRADE_COMPARE(rect.bottom(), 23);
    CORRADE_COMPARE(rect.top(), 30);
    CORRADE_COMPARE(rect.left(), 34);
    CORRADE_COMPARE(rect.right(), 47);
    CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23));
    CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30));

    constexpr Int bottom = crect.bottom();
    constexpr Int top = crect.top();
    constexpr Int left = crect.left();
    constexpr Int right = crect.right();
    CORRADE_COMPARE(bottom, 23);
    CORRADE_COMPARE(top, 30);
    CORRADE_COMPARE(left, 34);
    CORRADE_COMPARE(right, 47);

    constexpr Vector2i bottomLeft = crect.bottomLeft();
    constexpr Vector2i topRight = crect.topRight();
    CORRADE_COMPARE(bottomLeft, Vector2i(34, 23));
    CORRADE_COMPARE(topRight, Vector2i(47, 30));

    CORRADE_COMPARE(rect.topLeft(), Vector2i(34, 30));
    CORRADE_COMPARE(rect.bottomRight(), Vector2i(47, 23));
}
コード例 #2
0
QImage QtNativeFont::nativeFontRasterize(String const &text,
                                         Vector4ub const &foreground,
                                         Vector4ub const &background) const
{
#ifdef LIBGUI_ACCURATE_TEXT_BOUNDS
    Rectanglei const bounds = measure(text);
#else
    Rectanglei const bounds(Vector2i(0, -d->metrics->ascent()),
                            Vector2i(d->metrics->width(text),
                                     d->metrics->descent()));
#endif

    QColor const fgColor(foreground.x, foreground.y, foreground.z, foreground.w);
    QColor const bgColor(background.x, background.y, background.z, background.w);

    QImage img(QSize(bounds.width() + 1, bounds.height() + 1),
               QImage::Format_ARGB32);

    img.fill(bgColor.rgba());

    QPainter painter(&img);
    painter.setCompositionMode(QPainter::CompositionMode_Source);

    painter.setFont(d->font);
    painter.setPen(fgColor);
    painter.setBrush(bgColor);
    painter.drawText(-bounds.left(), -bounds.top(), text);

    return img;
}
コード例 #3
0
void BoundTexture2d::update_data(const Rectanglei& update_region,
        Texture::DataPixelFormat data_format, Texture::PixelType pixel_type, const void* data)
{
     glTexSubImage2D(GL_TEXTURE_2D, 0, update_region.left(), update_region.bottom(),
			update_region.width(), update_region.height(), static_cast<GLenum>(data_format),
			static_cast<GLenum>(pixel_type), data);
	CHECK_GL_ERROR(glTexSubImage2D);
}
コード例 #4
0
duint CanvasWindow::grabAsTexture(Rectanglei const &area, GrabMode mode) const
{
    QSize size;
    if(mode == GrabHalfSized)
    {
        size = QSize(area.width()/2, area.height()/2);
    }
    return d->canvas->grabAsTexture(
                QRect(area.left(), area.top(), area.width(), area.height()), size);
}
コード例 #5
0
    void glSubImage(int level, Rectanglei const &rect, Image const &image,
                    CubeFace face = PositiveX)
    {
        auto const &glFormat = image.glFormat();

        LIBGUI_GL.glPixelStorei(GL_UNPACK_ALIGNMENT,  GLint(glFormat.rowAlignment));
        LIBGUI_GL.glPixelStorei(GL_UNPACK_ROW_LENGTH, GLint(image.width()));

        int const bytesPerPixel = image.depth() / 8;

        LIBGUI_GL.glTexSubImage2D(isCube()? glFace(face) : texTarget,
                                  level, rect.left(), rect.top(), rect.width(), rect.height(),
                                  glFormat.format, glFormat.type,
                                  static_cast<dbyte const *>(image.bits()) +
                                  bytesPerPixel * rect.left() + image.stride() * rect.top());

        LIBGUI_GL.glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

        LIBGUI_ASSERT_GL_OK();
    }