Ignore:
Timestamp:
Feb 1, 2011, 2:20:05 AM (9 years ago)
Author:
sam
Message:

Test entity alignment features. Also, start working on the mouse tracking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/text.cpp

    r325 r326  
    2828
    2929private:
    30     int font;
     30    int font, align, length;
    3131    char *text;
    3232    int3 pos;
     
    4242    data->font = Forge::Register(font);
    4343    data->text = text ? strdup(text) : NULL;
     44    data->length = text ? strlen(text) : 0;
    4445    data->pos = int3(0, 0, 0);
    4546
     
    5253        free(data->text);
    5354    data->text = text ? strdup(text) : NULL;
     55    data->length = text ? strlen(text) : 0;
    5456}
    5557
     
    5860    if (data->text)
    5961        free(data->text);
    60     char buf[128];
    61     sprintf(buf, "%i", val);
    62     data->text = strdup(buf);
     62    char text[128];
     63    sprintf(text, "%i", val);
     64    data->text = strdup(text);
     65    data->length = strlen(text);
    6366}
    6467
     
    6669{
    6770    data->pos = pos;
     71}
     72
     73void Text::SetAlign(int align)
     74{
     75    data->align = align;
    6876}
    6977
     
    7583    {
    7684        Font *font = Forge::GetFont(data->font);
    77         font->Print(data->pos, data->text);
     85        int3 delta = 0;
     86        if (data->align == ALIGN_RIGHT)
     87            delta.x -= data->length * font->GetSize().x;
     88        else if (data->align == ALIGN_CENTER)
     89            delta.x -= data->length * font->GetSize().x / 2;
     90        font->Print(data->pos + delta, data->text);
    7891    }
    7992}
Note: See TracChangeset for help on using the changeset viewer.