Example #1
0
/**
 * Get the horizontal offset of the image within the ImageView.
 * <p>
 * This will be based off the horizontal alignment constant.
 * @return int
 */
int ImageView::getHorizontalOffset() const {
    int horizontalOffset = 0;
    if (getHorizontalAlignment() == HorizontalAlignment::CENTER) {
        horizontalOffset = (getWidth() - animation->getWidth()) / 2;
    } else if (getHorizontalAlignment() == HorizontalAlignment::RIGHT) {
        horizontalOffset = getWidth() - animation->getWidth();
    } else {
        horizontalOffset = 0;
    }

    return horizontalOffset;
}
Example #2
0
//----------------------------------------------------------------------------//
Rectf Element::getUnclippedOuterRect_impl(bool skipAllPixelAlignment) const
{
    const Sizef pixel_size = skipAllPixelAlignment ?
        calculatePixelSize(true) : getPixelSize();
    Rectf ret(Vector2f(0, 0), pixel_size);

    const Element* parent = getParentElement();

    Rectf parent_rect;
    if (parent)
    {
        const CachedRectf& base = parent->getChildContentArea(isNonClient());
        parent_rect = skipAllPixelAlignment ? base.getFresh(true) : base.get();
    }
    else
    {
        parent_rect = Rectf(Vector2f(0, 0), getRootContainerSize());
    }

    const Sizef parent_size = parent_rect.getSize();

    Vector2f offset = parent_rect.d_min + CoordConverter::asAbsolute(getArea().d_min, parent_size, false);

    switch (getHorizontalAlignment())
    {
        case HA_CENTRE:
            offset.d_x += (parent_size.d_width - pixel_size.d_width) * 0.5f;
            break;
        case HA_RIGHT:
            offset.d_x += parent_size.d_width - pixel_size.d_width;
            break;
        default:
            break;
    }

    switch (getVerticalAlignment())
    {
        case VA_CENTRE:
            offset.d_y += (parent_size.d_height - pixel_size.d_height) * 0.5f;
            break;
        case VA_BOTTOM:
            offset.d_y += parent_size.d_height - pixel_size.d_height;
            break;
        default:
            break;
    }

    if (d_pixelAligned && !skipAllPixelAlignment)
    {
        offset = Vector2f(CoordConverter::alignToPixels(offset.d_x),
                          CoordConverter::alignToPixels(offset.d_y));
    }

    ret.offset(offset);
    return ret;
}
void PatternLayer::draw(Graphics* const TheGraphics, const Pnt2f& TopLeft, const Pnt2f& BottomRight, const Real32 Opacity) const
{
    glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
    GLdouble Plane0[4], Plane1[4], Plane2[4], Plane3[4];
    glGetClipPlane(GL_CLIP_PLANE0, Plane0);
    glGetClipPlane(GL_CLIP_PLANE1, Plane1);
    glGetClipPlane(GL_CLIP_PLANE2, Plane2);
    glGetClipPlane(GL_CLIP_PLANE3, Plane3);

    glEnable(GL_CLIP_PLANE0);
    glEnable(GL_CLIP_PLANE1);
    glEnable(GL_CLIP_PLANE2);
    glEnable(GL_CLIP_PLANE3);

    // The clipping plane for the background must get set to inside the
    // border of the component. It was the outside of the component,
    // so it has to be reset to the stored values from above at the end.
    Vec4d LeftPlaneEquation(1.0,0.0,0.0,-TopLeft.x()),
          RightPlaneEquation(-1.0,0.0,0.0,BottomRight.x()),
          TopPlaneEquation(0.0,1.0,0.0,-TopLeft.y()),
          BottomPlaneEquation(0.0,-1.0,0.0,BottomRight.y());
    
    glClipPlane(GL_CLIP_PLANE0,LeftPlaneEquation.getValues());
    glClipPlane(GL_CLIP_PLANE1,RightPlaneEquation.getValues());
    glClipPlane(GL_CLIP_PLANE2,TopPlaneEquation.getValues());
    glClipPlane(GL_CLIP_PLANE3,BottomPlaneEquation.getValues());

    //Activate the Texture Transformation
    if(getTransformation() != NULL)
    {
        getTransformation()->activate(TheGraphics->getDrawEnv());
    }

    Vec2f BackgroundSize (BottomRight - TopLeft);
    Vec2f TopLeftTexCoords(0.0f,0.0f);
    Vec2f BottomRightTexCoords(1.0f,1.0f);

    Real32 RepeatHorizontal;
    switch(getHorizontalRepeat())
    {
    case PATTERN_REPEAT_ABSOLUTE:
        RepeatHorizontal = getHorizontalRepeatValue();
        break;
    case PATTERN_REPEAT_BY_POINT:
    default:
        RepeatHorizontal = static_cast<Real32>(BottomRight.x() - TopLeft.x())/static_cast<Real32>(getCorrectedPatternSize().x());
        break;
    }

    TopLeftTexCoords[0] = -getHorizontalAlignment() * (RepeatHorizontal -1.0f);
    BottomRightTexCoords[0] = TopLeftTexCoords[0] + RepeatHorizontal;
    
    Real32 RepeatVertical;
    switch(getVerticalRepeat())
    {
    case PATTERN_REPEAT_ABSOLUTE:
        RepeatVertical = getVerticalRepeatValue();
        break;
    case PATTERN_REPEAT_BY_POINT:
    default:
        RepeatVertical = static_cast<Real32>(BottomRight.y() - TopLeft.y())/static_cast<Real32>(getCorrectedPatternSize().y());
        break;
    }
    
    TopLeftTexCoords[1] = -getVerticalAlignment() * (RepeatVertical - 1.0f);
    BottomRightTexCoords[1] = TopLeftTexCoords[1] + RepeatVertical;

    TheGraphics->drawQuad(TopLeft, Pnt2f(BottomRight.x(), TopLeft.y()),BottomRight, Pnt2f(TopLeft.x(), BottomRight.y()),
        TopLeftTexCoords, Vec2f(BottomRightTexCoords.x(), TopLeftTexCoords.y()), BottomRightTexCoords, Vec2f(TopLeftTexCoords.x(), BottomRightTexCoords.y()),
        getColor(), getTexture(), Opacity);

    //Deactivate the Texture Transformation
    if(getTransformation() != NULL)
    {
        getTransformation()->deactivate(TheGraphics->getDrawEnv());
    }

    glPopAttrib();
}