Пример #1
0
void TestFontRender(CuTest* t)
{
    memset(FontNames, 0, sizeof(FontNames));
    int idx = FONT_GetFromString("15normal");
    LCD_Clear(0);
    LCD_SetFont(idx);
    LCD_SetFontColor(0xF0);
    LCD_PrintStringXY(0, 0, "the quick brown fox jumps over the lazy dog");
    LCD_PrintStringXY(5, 20, "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG");
    LCD_PrintStringXY(15, 40, "0123456789)!@#$%^&*(");

    AssertScreenshot(t, "font");
}
Пример #2
0
void GUI_DrawLabelHelper(u16 obj_x, u16 obj_y, u16 obj_w, u16 obj_h, const char *str,
        const struct LabelDesc *desc, u8 is_selected)
{
    u16 txt_w, txt_h;
    u16 txt_x, txt_y;
    u16 offset = (LCD_DEPTH > 1 && desc->font==NARROW_FONT.font) ? 1 : 0;
    LCD_SetFont(desc->font);
    LCD_GetStringDimensions((const u8 *)str, &txt_w, &txt_h); txt_w++;
    if (obj_w == 0)
        obj_w = txt_w;
    if (obj_h == 0)
        obj_h = txt_h;
    if (offset && obj_y >= offset) {
        obj_y -= offset;
    }
    if (desc->style == LABEL_BOX) {
        // draw round rect for the textsel widget when it is pressable
        if (is_selected) {
            LCD_FillRoundRect(obj_x, obj_y, obj_w, obj_h , 3, 1);
        }  else {
            GUI_DrawBackground(obj_x, obj_y, obj_w, obj_h);
            LCD_DrawRoundRect(obj_x, obj_y, obj_w, obj_h , 3,  1);
        }
    }
    else if (desc->style == LABEL_FILL) {
        LCD_FillRect(obj_x, obj_y, obj_w, obj_h, desc->fill_color);
    } else {
        GUI_DrawBackground(obj_x, obj_y, obj_w, obj_h);
    }
    if (desc->fill_color != desc->outline_color) {
        LCD_DrawRect(obj_x, obj_y, obj_w, obj_h, desc->outline_color);
        obj_x+=2; obj_w-=4;
    }

    if (desc->style == LABEL_RIGHT) {
        txt_x = obj_x + obj_w - txt_w;
    } else if (obj_w > txt_w && !(desc->style == LABEL_LEFT)) {
        txt_x = obj_x+1 + (obj_w - txt_w + 1) / 2;
    } else {
        txt_x = obj_x+1;
    }
    txt_y = obj_y + offset + (obj_h - txt_h + 1) / 2;

    if (desc->style != LABEL_FILL && is_selected) {
        LCD_SetFontColor(~desc->font_color);
    } else {
        LCD_SetFontColor(desc->font_color);
    }
    LCD_PrintStringXY(txt_x, txt_y, str);
}
Пример #3
0
void GUI_DrawLabelHelper(u16 obj_x, u16 obj_y, u16 obj_w, u16 obj_h, const char *str,
        const struct LabelDesc *desc, u8 is_selected)
{
    u16 txt_w, txt_h;
    u16 txt_x, txt_y;
    // This is used to align text vertically
    u16 offset = (desc->font==NARROW_FONT.font) ? 1 : 0;
    LCD_SetFont(desc->font);
    LCD_GetStringDimensions((const u8 *)str, &txt_w, &txt_h); txt_w++;
    if (obj_w == 0)
        obj_w = txt_w;
    if (obj_h == 0)
        obj_h = txt_h;
    if (desc->style == LABEL_LISTBOX) {
        LCD_FillRect(obj_x, obj_y, obj_w, obj_h, is_selected ? Display.listbox.fg_color : Display.listbox.bg_color);
    } else if (desc->style == LABEL_FILL) {
        LCD_FillRect(obj_x, obj_y, obj_w, obj_h, desc->fill_color);
    } else {
        GUI_DrawBackground(obj_x, obj_y, obj_w, obj_h);
    }
    if (desc->style != LABEL_LISTBOX && desc->fill_color != desc->outline_color) {
        LCD_DrawRect(obj_x, obj_y, obj_w, obj_h, desc->outline_color);
        obj_x+=2; obj_w-=4;
    }

    if (desc->style == LABEL_RIGHT) {
        txt_x = obj_x + obj_w - txt_w;
    } else if (obj_w > txt_w && !(desc->style == LABEL_LEFT)) {
        txt_x = obj_x+1 + (obj_w - txt_w + 1) / 2;
    } else {
        txt_x = obj_x+1;
    }
    txt_y = obj_y + offset + (obj_h - txt_h + 1) / 2;

    if (desc->style == LABEL_LISTBOX) {
        LCD_SetFontColor(is_selected ? Display.listbox.fg_select : Display.listbox.bg_select);
    } else {
        if (desc->style != LABEL_FILL && is_selected) {
            LCD_SetFontColor(~desc->font_color);
        } else {
            LCD_SetFontColor(desc->font_color);
        }
    }
    LCD_PrintStringXY(txt_x, txt_y, str);
}
Пример #4
0
//char SELECT_CHAR[] = "☼";
void GUI_DrawLabelHelper(u16 obj_x, u16 obj_y, u16 obj_width, u16 obj_height,
        const char *str, const struct LabelDesc *desc, u8 is_selected) {
	u16 txt_w, txt_h;
    (void)obj_height;
    u16 cx, cy;
    LCD_GetStringDimensions((const u8 *)str, &txt_w, &txt_h);
    LCD_GetCharDimensions(LCD_SELECT_CHAR, &cx, &cy);
    if (desc && (desc->style == LABEL_INVERTED || (desc->style != LABEL_FILL && is_selected))) {
        LCD_PrintCharXY(obj_x, obj_y, LCD_SELECT_CHAR);
        txt_w += cx;
        obj_x += cx;
    }

    //printf("%s, %d, %d\n", tempstring, txt_w, obj_width);
    LCD_PrintStringXY(obj_x, obj_y, str);
    for(;txt_w < obj_width;txt_w += cx)
    	LCD_PrintCharXY(obj_x+txt_w, obj_y, ' ');
}
Пример #5
0
void GUI_DrawDialog(struct guiObject *obj)
{
    struct guiBox *box = &obj->box;
    struct guiDialog *dialog = (struct guiDialog *)obj;
    if (dialog->txtbox.height == 0) {
        _draw_dialog_box(box, dialog->txtbox.x, dialog->title);
    } else if(dialog->txtbox.width) {
        // NOTE: We assume all redraw events after the 1st are incremental!
        GUI_DialogDrawBackground(dialog->txtbox.x, dialog->txtbox.y,
                                 dialog->txtbox.width, dialog->txtbox.height);
    }
    const char *str = dialog->string_cb
                         ? dialog->string_cb(obj, dialog->cbData)
                         : (const char *)dialog->cbData;
    int button_height = GUI_ButtonHeight(DIALOG_BUTTON);
    LCD_SetFont(DIALOGBODY_FONT.font);
    LCD_SetFontColor(DIALOGBODY_FONT.font_color);
    LCD_GetStringDimensions((const u8 *)str, &dialog->txtbox.width, &dialog->txtbox.height);
    dialog->txtbox.y = box->y + DIALOG_HEADER_Y +
        (box->height - dialog->txtbox.height - DIALOG_HEADER_Y - button_height) / 2;
    LCD_PrintStringXY(dialog->txtbox.x, dialog->txtbox.y, str);
}
Пример #6
0
void GUI_DrawLabelHelper(u16 obj_x, u16 obj_y, u16 obj_w, u16 obj_h, const char *str,
        const struct LabelDesc *desc, u8 is_selected)
{
    u16 txt_w, txt_h;
    u16 txt_x, txt_y;
    u16 offset = (LCD_DEPTH > 1 && desc->font==NARROW_FONT.font) ? 1 : 0;
    LCD_SetFont(desc->font);
    LCD_GetStringDimensions((const u8 *)str, &txt_w, &txt_h); txt_w++;
    if (obj_w == 0)
        obj_w = txt_w;
    if (obj_h == 0)
        obj_h = txt_h;
    if (offset && obj_y >= offset) {
        obj_y -= offset;
    }
    if (desc->style != LABEL_TRANSPARENT)
    {
        GUI_DrawBackground(obj_x, obj_y, obj_w, obj_h);
    }
    if (desc->style == LABEL_BOX || desc->style == LABEL_BRACKET || desc->style == LABEL_SQUAREBOX) {
        // draw round rect for the textsel widget when it is pressable
        if (is_selected) {
            if (desc->style == LABEL_SQUAREBOX ||obj_w < 5)
                LCD_FillRect(obj_x, obj_y, obj_w, obj_h , 1);
            else
                LCD_FillRoundRect(obj_x, obj_y, obj_w, obj_h , 3, 1);
        }  else {
            if (desc->style == LABEL_SQUAREBOX)
                if (desc->fill_color == 0)
                    LCD_DrawRect(obj_x, obj_y, obj_w, obj_h, 1);
                else
                    LCD_FillRect(obj_x, obj_y, obj_w, obj_h, desc->fill_color);
            else if (desc->style == LABEL_BRACKET) {
                struct pos { int i1; int i2; int i3; int i4;};
                struct { union { int p[4]; struct pos pos;} u;} x[2], y[2];
                //int x[2][4];
                //int y[2][4];
                if (obj_h > 2 * obj_w) {
                    x[0].u.pos = (struct pos){ 0, 2, obj_w -3, obj_w -1};
                    y[0].u.pos = (struct pos){ 2, 0, 0, 2};
                    x[1].u.pos = x[0].u.pos;
                    y[1].u.pos = (struct pos){ obj_h -3, obj_h -1, obj_h -1, obj_h -3};
                } else {
                    x[0].u.pos = (struct pos){ 2, 0, 0, 2};
                    y[0].u.pos = (struct pos){ 0, 2, obj_h -3, obj_h -1};
                    x[1].u.pos = (struct pos){ obj_w -3, obj_w -1, obj_w -1,  obj_w -3};
                    y[1].u.pos = y[0].u.pos;
                }
                for(int oc = 0; oc < 2; oc++) {
                    for(int i = 0; i < 3; i++) {
                        LCD_DrawLine(obj_x + x[oc].u.p[i], obj_y+y[oc].u.p[i], obj_x+x[oc].u.p[i+1], obj_y + y[oc].u.p[i+1], 1);
                    }
                }
            } else
                LCD_DrawRoundRect(obj_x, obj_y, obj_w, obj_h , 3,  1);
        }
    }
    else if (desc->style == LABEL_FILL) {
        LCD_FillRect(obj_x, obj_y, obj_w, obj_h, desc->fill_color);
    }
    else if (desc->style == LABEL_INVERTED || is_selected) {
        LCD_FillRect(obj_x, obj_y, obj_w, obj_h, 0xffff);
    }
    if (desc->style == LABEL_TRANSPARENT || (LCD_DEPTH > 1 && desc->fill_color != desc->outline_color)) {
        LCD_DrawRect(obj_x, obj_y, obj_w, obj_h, desc->outline_color);
        obj_x+=2; obj_w-=4;
    }

    if (desc->style == LABEL_RIGHT) {
        txt_x = obj_x + obj_w - txt_w;
    } else if (obj_w > txt_w && !(desc->style == LABEL_LEFT || desc->style == LABEL_NO_BOX
                                                            || desc->style == LABEL_UNDERLINE)) {
        txt_x = obj_x+1 + (obj_w - txt_w + 1) / 2;
    } else {
        txt_x = obj_x+1;
    }
    txt_y = obj_y + offset + (obj_h - txt_h + 1) / 2;

    if (desc->style == LABEL_UNDERLINE) {
        LCD_DrawFastHLine(--txt_x, txt_y + txt_h - 1, obj_w, 1);
    }
    if (desc->style == LABEL_BLINK) {
        blink_fontcolor = ~blink_fontcolor;
        LCD_SetFontColor(blink_fontcolor);
    } else if (desc->style == LABEL_INVERTED || (desc->style != LABEL_FILL && is_selected)) {
        LCD_SetFontColor(~desc->font_color);
    } else {
        LCD_SetFontColor(desc->font_color);
    }
    LCD_PrintStringXY(txt_x, txt_y, str);
}