示例#1
0
void SDL_LabelDraw(SDL_Widget *widget,SDL_Surface *surface,SDL_Rect *Area)
{
    SDL_Label *Label=(SDL_Label*)widget;
    SDL_Rect DrawPosition;
    SDL_Rect FontInfo;

    if(Label->bgcolor != TRANSPARANT)
    {
		SDL_Rect r;
		r.x = r.y = 0;
		r.w = widget->Rect.w;
		r.h = widget->Rect.h;
        SDL_FillRect(surface,&r,Label->bgcolor);
    }

    if(Label->Caption)
    {
        SDL_LabelSetFontHeight(widget,Label->height);

        Label_CalculatePattern(Label,&DrawPosition);
#if 0
        SDL_FillRectWindow(window,&DrawPosition,0xfff000);
#endif
        SDL_FontCalcDims(Label->Font,Label->Caption,&FontInfo);

        SDL_FontDrawString(surface,Label->Font,Label->Caption,Label->fgcolor,&DrawPosition);
    }
}
示例#2
0
void  SDL_EditDraw(void *edit,SDL_Surface *dest)
{
    SDL_Edit *Edit=(SDL_Edit*)edit;
    SDL_Rect cursor;
    SDL_Rect StringPos;
    int StringWidth;
    char *caption;
    
    if(Edit->Font == NULL)
    {
        printf("SDL_Edit ERROR: Can't draw edit without Font set\n");
        return;
    }


    SDL_FontSetColor(Edit->Font,Edit->fgcolor);
    
    SDL_FillRect(dest,&Edit->rect,Edit->bgcolor);
    
    StringPos.y = Edit->rect.y + ((Edit->rect.h - Edit->Font->height)/2);
    StringPos.x = Edit->rect.x;
    StringPos.w = Edit->rect.w;
    StringPos.h = Edit->rect.h;
    
    StringWidth=SDL_FontGetStringWidth(Edit->Font,Edit->Caption);
    
    if(StringWidth <= Edit->rect.w )
    {
        SDL_FontDrawStringRect(dest,Edit->Font,Edit->Caption,&StringPos);
    }
    else
    {
        caption=Edit->Caption;
        while(SDL_FontGetStringWidth(Edit->Font,caption) > Edit->rect.w)
            caption++;
        SDL_FontDrawString(dest,Edit->Font,caption,Edit->rect.x,StringPos.y);
    }
    
    /* draw cursor */
    
    if(SDL_WidgetHasFocus(edit) || Edit->Focus)
    {
        StringWidth=SDL_FontGetStringWidth(Edit->Font,Edit->Caption);
        if(StringWidth > Edit->rect.w)
            cursor.x = Edit->rect.x + Edit->rect.w - 2;
        else
            cursor.x = Edit->rect.x + SDL_FontGetStringWidth(Edit->Font,Edit->Caption)+2;
        cursor.y = StringPos.y;
        cursor.w = 1;
            cursor.h = Edit->Font->height;
            SDL_FillRect(dest,&cursor,0x000007);
    }
    
}