示例#1
0
void NinePatch::initialize(TextureRegion region, int left, int right, int top, int bottom)
{
    int middleWidth = region.getRegionWidth() - left - right;
    int middleHeight = region.getRegionHeight() - top - bottom;

    if (top > 0) {
        if (left > 0) patches[0] = TextureRegion(region, 0, 0, left, top);
        if (middleWidth > 0) patches[1] = TextureRegion(region, left, 0, middleWidth, top);
        if (right > 0) patches[2] = TextureRegion(region, left + middleWidth, 0, right, top);
    }
    if (middleHeight > 0) {
        if (left > 0) patches[3] = TextureRegion(region, 0, top, left, middleHeight);
        if (middleWidth > 0) patches[4] = TextureRegion(region, left, top, middleWidth, middleHeight);
        if (right > 0) patches[5] = TextureRegion(region, left + middleWidth, top, right, middleHeight);
    }
    if (bottom > 0) {
        if (left > 0) patches[6] = TextureRegion(region, 0, top + middleHeight, left, bottom);
        if (middleWidth > 0) patches[7] = TextureRegion(region, left, top + middleHeight, middleWidth, bottom);
        if (right > 0) patches[8] = TextureRegion(region, left + middleWidth, top + middleHeight, right, bottom);
    }

    // If split only vertical, move splits from right to center.
    if (left == 0 && middleWidth == 0) {
        patches[(uint32_t) Sides::TOP_CENTER] = patches[(uint32_t) Sides::TOP_RIGHT];
        patches[(uint32_t) Sides::MIDDLE_CENTER] = patches[(uint32_t) Sides::MIDDLE_RIGHT];
        patches[(uint32_t) Sides::BOTTOM_CENTER] = patches[(uint32_t) Sides::BOTTOM_RIGHT];
    }
    
    // If split only horizontal, move splits from bottom to center.
    if (top == 0 && middleHeight == 0) {
        patches[(uint32_t) Sides::MIDDLE_LEFT] = patches[(uint32_t) Sides::BOTTOM_LEFT];
        patches[(uint32_t) Sides::MIDDLE_CENTER] = patches[(uint32_t) Sides::BOTTOM_CENTER];
        patches[(uint32_t) Sides::MIDDLE_RIGHT] = patches[(uint32_t) Sides::BOTTOM_RIGHT];        
    }
}
示例#2
0
TextureRegion Art::load (std::string name, int width, int height)
{
    Texture* texture = new Texture(Gdx.files->internalHandle(name));
    TextureRegion* region = new TextureRegion(texture, 0, 0, width, height);
    region->flip(false, true);
    return region;
}
示例#3
0
TextureRegion* TextureRegion::create(const std::string& filename, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
{
    TextureRegion *TextureRegion = new (std::nothrow) TextureRegion();
    TextureRegion->initWithTextureFilename(filename, rect, rotated, offset, originalSize);
    TextureRegion->autorelease();

    return TextureRegion;
}
示例#4
0
Bitmap::Bitmap(mrb_value self, mrb_value texture_region)
  : Sprite(self)
{
  setProperty("texture_region", texture_region);
  TextureRegion *region = (TextureRegion*) getObject("texture_region");
  setWidth(region->getWidth());
  setHeight(region->getHeight());
}
示例#5
0
TextureRegion* TextureRegion::createWithTexture(Texture2D *texture, const Rect& rect)
{
    TextureRegion *TextureRegion = new (std::nothrow) TextureRegion();
    TextureRegion->initWithTexture(texture, rect);
    TextureRegion->autorelease();
    
    return TextureRegion;
}
示例#6
0
TextureRegion* TextureRegion::createWithTexture(Texture2D* texture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
{
    TextureRegion *TextureRegion = new (std::nothrow) TextureRegion();
    TextureRegion->initWithTexture(texture, rect, rotated, offset, originalSize);
    TextureRegion->autorelease();

    return TextureRegion;
}
示例#7
0
TextureRegion* TextureRegion::clone() const
{
	// no copy constructor	
    TextureRegion *copy = new (std::nothrow) TextureRegion();
    copy->initWithTextureFilename(_textureFilename.c_str(), _rectInPixels, _rotated, _offsetInPixels, _originalSizeInPixels);
    copy->setTexture(_texture);
    copy->autorelease();
    return copy;
}
示例#8
0
FLAKOR_NS_BEGIN

// implementation of TextureRegion

TextureRegion* TextureRegion::create(const std::string& filename, const Rect& rect)
{
    TextureRegion *TextureRegion = new (std::nothrow) TextureRegion();
    TextureRegion->initWithTextureFilename(filename, rect);
    TextureRegion->autorelease();

    return TextureRegion;
}
示例#9
0
Sprite::Sprite(const TextureRegion& region) : color(1,1,1,1) {
    this->scaleX = 1;
    this->scaleY = 1;
    this->dirty = true;
    this->x = this->y = this->width = this->height = 0;
    
    this->rotation = 0;
    
    TextureRegion::setRegion(region);
    setColor(1, 1, 1, 1);
    setSize(std::abs(region.getRegionWidth()), std::abs(region.getRegionHeight()));
    setOrigin(width / 2, height / 2);
}
示例#10
0
void NinePatch::initialize(TextureRegion region, int left, int right, int top, int bottom)
{
    int middleWidth = region.getRegionWidth() - left - right;
    int middleHeight = region.getRegionHeight() - top - bottom;
    
    patches[0] = TextureRegion(region, 0, 0, left, top);
    patches[1] = TextureRegion(region, left, 0, middleWidth, top);
    patches[2] = TextureRegion(region, left + middleWidth, 0, right, top);
    patches[3] = TextureRegion(region, 0, top, left, middleHeight);
    patches[4] = TextureRegion(region, left, top, middleWidth, middleHeight);
    patches[5] = TextureRegion(region, left + middleWidth, top, right, middleHeight);
    patches[6] = TextureRegion(region, 0, top + middleHeight, left, bottom);
    patches[7] = TextureRegion(region, left, top + middleHeight, middleWidth, bottom);
    patches[8] = TextureRegion(region, left + middleWidth, top + middleHeight, right, bottom);
}
示例#11
0
void Button::draw( BaseShader *bs )
{
    if (!m_bShow) return;
    TextureRegion *tr = this;
    if (m_bDown || m_bSelect){
        tr = &m_down;
    }
    tr->getTexture()->bind();
    glVertexAttribPointer(bs->getPositionLoc(), 2, GL_FLOAT, GL_FALSE, 0, getVertices());
    glVertexAttribPointer(bs->getTextureCoordLoc(), 2, GL_FLOAT, GL_FALSE, 0, tr->getTexCoords());
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    if (m_btnImg){
        m_btnImg->setPostion(getX(), getY());
        m_btnImg->draw(bs);
    }
    
}
示例#12
0
void SpriteGeometry::setFromRegion(TextureRegion& region) {

  // Calculate texture points;
  unsigned int width = region.getTexture()->getWidth();
  unsigned int height = region.getTexture()->getHeight();

  setAttribute("Texture", std::vector<float> {
    region.getMinX() / (float)width, region.getMinY() / float(height),
    region.getMaxX() / (float)width, region.getMinY() / float(height),
    region.getMaxX() / (float)width, region.getMaxY() / float(height),
    region.getMinX() / (float)width, region.getMaxY() / float(height)
  });
}
示例#13
0
void Bitmap::renderMe(SDL_Renderer *renderer)
{
  TextureRegion *region = (TextureRegion*) this->getObject("texture_region");
  Texture *texture = (Texture*) region->getObject("texture");

  SDL_Rect srcrect = { region->getX(), region->getY(), region->getWidth(), region->getHeight() };
  SDL_Rect dstrect = { 0, 0, this->getWidth(), this->getHeight() };

  texture->render(renderer, &srcrect, &dstrect);
}
示例#14
0
void SpriteBatch::draw (const TextureRegion& region,float x,float y,float width,float height) {
    if (!drawing)
        throw std::runtime_error("SpriteBatch.begin must be called before draw.");

    Texture::ptr texture = region.getTexture();
    if (texture.get() != lastTexture) {
        renderMesh();
        lastTexture = texture.get();
        invTexWidth = 1.0f / texture->getWidth();
        invTexHeight = 1.0f / texture->getHeight();
    } else if (idx == verticesSize) //
        renderMesh();

    float fx2 = x + width;
    float fy2 = y + height;
    float u = region.u;
    float v = region.v2;
    float u2 = region.u2;
    float v2 = region.v;

    utils::float_buffer& buffer = mesh->getVerticesBuffer();
    buffer.limit(buffer.position() + 20);

    vertices[idx++] = x;
    vertices[idx++] = y;
    vertices[idx++] = color;
    vertices[idx++] = u;
    vertices[idx++] = v;

    vertices[idx++] = x;
    vertices[idx++] = fy2;
    vertices[idx++] = color;
    vertices[idx++] = u;
    vertices[idx++] = v2;

    vertices[idx++] = fx2;
    vertices[idx++] = fy2;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v2;

    vertices[idx++] = fx2;
    vertices[idx++] = y;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v;
}
示例#15
0
void SpriteBatch::draw (const TextureRegion& region,float x,float y,float originX,float originY,float width,float height,float scaleX,float scaleY,float rotation,bool clockwise) {
    if (!drawing)
        throw std::runtime_error("SpriteBatch.begin must be called before draw.");

    Texture::ptr texture = region.getTexture();
    if (texture.get() != lastTexture) {
        renderMesh();
        lastTexture = texture.get();
        invTexWidth = 1.0f / texture->getWidth();
        invTexHeight = 1.0f / texture->getHeight();
    } else if (idx == verticesSize) {
        renderMesh();
    }

    // bottom left and top right corner points relative to origin
    float worldOriginX = x + originX;
    float worldOriginY = y + originY;
    float fx = -originX;
    float fy = -originY;
    float fx2 = width - originX;
    float fy2 = height - originY;

    // scale
    if (scaleX != 1 || scaleY != 1) {
        fx *= scaleX;
        fy *= scaleY;
        fx2 *= scaleX;
        fy2 *= scaleY;
    }

    // construct corner points, start from top left and go counter clockwise
    float p1x = fx;
    float p1y = fy;
    float p2x = fx;
    float p2y = fy2;
    float p3x = fx2;
    float p3y = fy2;
    float p4x = fx2;
    float p4y = fy;

    float x1;
    float y1;
    float x2;
    float y2;
    float x3;
    float y3;
    float x4;
    float y4;

    // rotate
    if (rotation != 0) {
        float cos = math::utils::cosDeg(rotation);
        float sin = math::utils::sinDeg(rotation);

        x1 = cos * p1x - sin * p1y;
        y1 = sin * p1x + cos * p1y;

        x2 = cos * p2x - sin * p2y;
        y2 = sin * p2x + cos * p2y;

        x3 = cos * p3x - sin * p3y;
        y3 = sin * p3x + cos * p3y;

        x4 = x1 + (x3 - x2);
        y4 = y3 - (y2 - y1);
    } else {
        x1 = p1x;
        y1 = p1y;

        x2 = p2x;
        y2 = p2y;

        x3 = p3x;
        y3 = p3y;

        x4 = p4x;
        y4 = p4y;
    }

    x1 += worldOriginX;
    y1 += worldOriginY;
    x2 += worldOriginX;
    y2 += worldOriginY;
    x3 += worldOriginX;
    y3 += worldOriginY;
    x4 += worldOriginX;
    y4 += worldOriginY;

    float u1, v1, u2, v2, u3, v3, u4, v4;
    if (clockwise) {
        u1 = region.u2;
        v1 = region.v2;
        u2 = region.u;
        v2 = region.v2;
        u3 = region.u;
        v3 = region.v;
        u4 = region.u2;
        v4 = region.v;
    } else {
        u1 = region.u;
        v1 = region.v;
        u2 = region.u2;
        v2 = region.v;
        u3 = region.u2;
        v3 = region.v2;
        u4 = region.u;
        v4 = region.v2;
    }

    vertices[idx++] = x1;
    vertices[idx++] = y1;
    vertices[idx++] = color;
    vertices[idx++] = u1;
    vertices[idx++] = v1;

    vertices[idx++] = x2;
    vertices[idx++] = y2;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v2;

    vertices[idx++] = x3;
    vertices[idx++] = y3;
    vertices[idx++] = color;
    vertices[idx++] = u3;
    vertices[idx++] = v3;

    vertices[idx++] = x4;
    vertices[idx++] = y4;
    vertices[idx++] = color;
    vertices[idx++] = u4;
    vertices[idx++] = v4;
}
示例#16
0
void SpriteBatch::draw (const TextureRegion& region,float x,float y) {
    draw(region, x, y, std::abs(region.getRegionWidth()), std::abs(region.getRegionHeight()));
}
示例#17
0
void Sprite::setRegion(const TextureRegion& other)
{
    texture = other.getTexture();
    setRegion(other.u, other.v, other.u2, other.v2);
}