Esempio n. 1
0
static void drawRegion(memvolume_t &volume, Rectanglei const &rect, size_t start,
    size_t size, float const color[4])
{
    DENG2_ASSERT(start + size <= volume.size);

    int const bytesPerRow = (volume.size - sizeof(memzone_t)) / rect.height();
    float const toPixelScale = (float)rect.width() / (float)bytesPerRow;
    size_t const edge = rect.topLeft.x + rect.width();
    int x = (start % bytesPerRow) * toPixelScale + rect.topLeft.x;
    int y = start / bytesPerRow + rect.topLeft.y;
    int pixels = de::max<dint>(1, std::ceil(size * toPixelScale));

    while(pixels > 0)
    {
        int const availPixels = edge - x;
        int const usedPixels = de::min(availPixels, pixels);

        glColor4fv(color);
        glVertex2i(x, y);
        glVertex2i(x + usedPixels, y);

        pixels -= usedPixels;

        // Move to the next row.
        y++;
        x = rect.topLeft.x;
    }
}
Esempio n. 2
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);
}
Esempio n. 3
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;
}
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);
}
Esempio n. 5
0
Rectanglei QtNativeFont::nativeFontMeasure(String const &text) const
{
    Rectanglei rect = Rectanglei::fromQRect(d->metrics->boundingRect(text));

    if(rect.height() == 0)
    {
        // It seems measuring the bounds of a Tab character produces
        // strange results (position 100000?).
        rect = Rectanglei(0, 0, rect.width(), 0);
    }

    return rect;
}
Esempio n. 6
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();
    }
Esempio n. 7
0
    /**
     * Submits the image to the backing store, or commits it if no backing
     * store is available.
     *
     * @param image  Image.
     * @param rect   Rectangle for the image determined by an IAllocator.
     */
    void submitImage(Image const &image, Rectanglei const &rect)
    {
        Rectanglei const noBorders  = rect.shrunk(border);
        Rectanglei const withMargin = rect.expanded(margin);

        if (hasBacking())
        {
            // The margin is cleared to transparent black.
            backing.fill(withMargin, Image::Color(0, 0, 0, 0));

            if (border > 0)
            {
                if (flags.testFlag(WrapBordersInBackingStore))
                {
                    // Wrap using the source image (left, right, top, bottom edges).
                    backing.drawPartial(image, Rectanglei(0, 0, border, image.height()),
                                           rect.topRight() + Vector2i(-border, border));

                    backing.drawPartial(image, Rectanglei(image.width() - border, 0,
                                                             border, image.height()),
                                           rect.topLeft + Vector2i(0, border));

                    backing.drawPartial(image, Rectanglei(0, 0, image.width(), border),
                                           rect.bottomLeft() + Vector2i(border, -border));

                    backing.drawPartial(image, Rectanglei(0, image.height() - border,
                                                             image.width(), border),
                                           rect.topLeft + Vector2i(border, 0));
                }
            }
            backing.draw(image, noBorders.topLeft);

            //backing.toQImage().save(QString("backing-%1.png").arg(uint64_t(this)));

            markAsChanged(rect);
        }
        else
        {
            // No backing, must commit immediately.
            if (border > 0)
            {
                // Expand with borders (repeat edges).
                QImage const srcImg = image.toQImage();
                int const sw = srcImg.width();
                int const sh = srcImg.height();

                QImage bordered(QSize(rect.width(), rect.height()), srcImg.format());
                int const w = bordered.width();
                int const h = bordered.height();

                QPainter painter(&bordered);
                painter.setCompositionMode(QPainter::CompositionMode_Source);
                painter.fillRect(bordered.rect(), QColor(0, 0, 0, 0));

                /// @todo This really only works for a border of 1 pixels. Should
                /// repeat the same outmost edge pixels for every border. -jk

                painter.drawImage(border, border, srcImg);
                painter.drawImage(border, 0,     srcImg, 0, 0, sw, 1); // top
                painter.drawImage(border, h - 1, srcImg, 0, sh - 1, sw, 1); // bottom
                painter.drawImage(0, border,     srcImg, 0, 0, 1, sh); // left
                painter.drawImage(w - 1, border, srcImg, sw - 1, 0, 1, sh); // right

                // Corners.
                painter.drawImage(0, 0,         srcImg, 0, 0, 1, 1);
                painter.drawImage(w - 1, 0,     srcImg, sw - 1, 0, 1, 1);
                painter.drawImage(0, h - 1,     srcImg, 0, sh - 1, 1, 1);
                painter.drawImage(w - 1, h - 1, srcImg, sw - 1, sh - 1, 1, 1);

                self().commit(bordered, rect.topLeft);
            }
            else
            {
                self().commit(image, noBorders.topLeft);
            }
        }
    }