Пример #1
0
void GUI_TextField::Update(int force)
{
    if (!parent || !font) {
        return;
    }
    GUI_Widget::Update(force);
    if (force) {
        GUI_Surface *surface;
        SDL_Rect r = area;
        SDL_Rect clip = area;
        clip.x = clip.x + border.x;
        clip.y = clip.y + border.y;
        clip.w = clip.w - (border.x * 2);
        clip.h = clip.h - (border.y * 2);
        SDL_Color color = IsFocused() || IsInside() ? fontfocusedcolor : fontnormalcolor;
        // Draw text
        surface = font->RenderQuality(buffer, color);
        if (surface != NULL) {
            switch (align & ALIGN_HORIZ_MASK) {
             case ALIGN_HORIZ_CENTER:
                  if (surface->GetWidth() < r.w) {
                      r.x = r.x + (r.w - surface->GetWidth()) / 2;
                  }
                  break;
             case ALIGN_HORIZ_RIGHT:
                  if (surface->GetWidth() < r.w) {
                      r.x = r.x + r.w - surface->GetWidth();
                  }
                  break;
            }
            DrawClipped(surface, parent, clip, r.x + border.x - startoffset, r.y + ((r.h - surface->GetHeight()) / 2));
            surface->DecRef();
        }
        // Draw cursor
        if (IsFocused()) {
            strcpy(cbuffer, buffer);
            cbuffer[cursorpos] = 0;
            SDL_Rect textsize = font->GetTextSize(cbuffer);
            int cursorx = r.x + border.x + textsize.w - startoffset;
            surface = new GUI_Surface("cursor", SDL_SWSURFACE, 2, clip.h, 32, RMask, GMask, BMask, AMask);
            surface->Fill(NULL, colorToInt(color));
            DrawClipped(surface, parent, clip, cursorx, r.y + ((r.h - surface->GetHeight()) / 2));
            surface->DecRef();
        }
    }
}
Пример #2
0
void Sprite::DrawClipped(Vector2 position, RectangleWH clipRect, bool flipHorizontally)
{
    DrawClipped(position, clipRect, flipHorizontally, Color::White);
}
Пример #3
0
void Sprite::DrawClipped(Vector2 position, RectangleWH clipRect)
{
    DrawClipped(position, clipRect, false /* flipHorizontally */);
}