示例#1
0
void contextmenu_draw(void)
{
    CONTEXTMENU *b = &context_menu;
    if(!b->open) {
        return;
    }

    int x, w, active_h;
    calculate_pos_and_width(b, &x, &w);

    draw_rect_fill(x, b->y, w, b->height, COLOR_BACKGROUND_MAIN);
    active_h = b->y + b->over * CONTEXT_HEIGHT;
    draw_rect_fill(x, active_h, w, CONTEXT_HEIGHT, COLOR_ACTIVEOPTION_BACKGROUND);

    int i;
    for(i = 0; i != b->count; i++) {
        // Ensure that font is set before calculating position and width.
        STRING *name = b->ondisplay(i, b);
        setfont(FONT_TEXT);
        setcolor((active_h == b->y + i * CONTEXT_HEIGHT) ? COLOR_ACTIVEOPTION_TEXT : COLOR_MAIN_TEXT);
        drawtext(x + UTOX_SCALE(2), b->y + UTOX_SCALE(2) + i * CONTEXT_HEIGHT, name->str, name->length);
    }

    draw_rect_frame(x, b->y, w, b->height, COLOR_EDGE_ACTIVE);
}
示例#2
0
文件: button.c 项目: kytvi2p/uTox
void button_draw(BUTTON *b, int x, int y, int width, int height)
{
    // Button is hidden
    if (b->nodraw)
        return;

    // If `update` function is defined, call it on each draw
    if (b->update) {
        b->update(b);
    }

    // Ensure that font is set before calculating position and width.
    setfont(FONT_SELF_NAME);

    // Button contents color
    uint32_t color_text = b->mousedown ? b->ct2 : (b->mouseover ? b->ct2 : b->ct1);
    setcolor(color_text);

    int w = width;
    calculate_pos_and_width(b, &x, &w);

    // Button background color
    uint32_t color_background = b->mousedown ? b->c3 : (b->mouseover ? b->c2 : b->c1);

    if(b->bm) {
        drawalpha(b->bm, x, y, width, height, color_background);
    } else {
        draw_rect_fill(x, y, w, height, b->disabled ? (b->cd ? b->cd : b->cd) : color_background);

        //setfont(FONT_TEXT_LARGE);
        //setcolor(b->mouseover ? 0x222222 : 0x555555);
        //drawtext(x + 5, y, b->text, b->text_length);
    }

    if(b->bm2) {
        int bx = w / 2 - b->bw * SCALE / 2, by = height / 2 - b->bh * SCALE / 2;
        drawalpha(b->bm2, x + bx, y + by, b->bw * SCALE, b->bh * SCALE, color_text);
    }

    if(maybe_i18nal_string_is_valid(&b->button_text)) {
        if(b->bm) {
            while(w > width) {
                // The text didn't fit into the original width.
                // Fill the rest of the new width with the image
                // and hope for the best.
                drawalpha(b->bm, x - width + w, y, width, height, color_background);
                w -= width / 2 + 1;
            }
        }
        STRING* s = maybe_i18nal_string_get(&b->button_text);
        drawtext(x + 3 * SCALE, y + SCALE, s->str, s->length);
    }
}
示例#3
0
文件: text.c 项目: digideskio/uTox
static void drawtexth(int x, int y, char_t *str, uint16_t length, int d, int h, int hlen, uint16_t lineheight)
{
    // Draw cursor
    h -= d;
    if(h + hlen < 0 || h > length) {
        drawtext(x, y, str, length);
        return;
    } else if(hlen == 0) {
        drawtext(x, y, str, length);
        int w =  textwidth(str, h + hlen);
        drawvline(x + w, y, y + lineheight, COLOR_MAIN_TEXT);
        return;
    }

    if(h < 0) {
        hlen += h;
        h = 0;
        if(hlen < 0) {
            hlen = 0;
        }
    }

    if(h + hlen > length) {
        hlen = length - h;
    }

    int width;

    width = drawtext_getwidth(x, y, str, h);

    uint32_t color = setcolor(COLOR_SELECTION_TEXT);

    int w = textwidth(str + h, hlen);
    draw_rect_fill(x + width, y, w, lineheight, COLOR_SELECTION_BACKGROUND);
    drawtext(x + width, y, str + h, hlen);
    width += w;

    setcolor(color);

    drawtext(x + width, y, str + h + hlen, length - (h + hlen));
}
示例#4
0
文件: dropdown.c 项目: Doom032/uTox
// Draw collapsed dropdown
void dropdown_draw(DROPDOWN *b, int x, int y, int width, int height) {
    if(!b->open) {
        // load colors for this style
        uint32_t color_bg,
                 color_border,
                 color_border_h,
                 color_text;

        switch(b->style) {
            case AUXILIARY_STYLE:
                color_bg = COLOR_BACKGROUND_AUX;
                color_border = COLOR_AUX_EDGE_NORMAL;
                color_border_h = COLOR_AUX_EDGE_HOVER;
                color_text = COLOR_AUX_TEXT;
                break;
            default:
                color_bg = COLOR_BACKGROUND_MAIN;
                color_border = COLOR_EDGE_NORMAL;
                color_border_h = COLOR_EDGE_HOVER;
                color_text = COLOR_MAIN_TEXT;
                break;
        }

        draw_rect_frame(x, y, width, height, (b->mouseover ? color_border_h : color_border));
        draw_rect_fill(x + 1, y + 1, width - 1 * SCALE, height - 1 * SCALE, color_bg);

        if(b->dropcount) {
            setfont(FONT_TEXT);
            setcolor(color_text);
            STRING* e = b->ondisplay(b->selected, b);
            drawtextwidth(x + 2 * SCALE, width - 4 * SCALE, y + 2 * SCALE, e->str, e->length);
        }
    } else {
        active_x = x;
        active_y = y;
        active_width = width;
        active_height = height;
    }
}
示例#5
0
文件: dropdown.c 项目: Doom032/uTox
// Draw background rectangles for a dropdown
void dropdown_drawactive(void) {
    DROPDOWN *b = active;
    if(!b) {
        return;
    }

    // load colors for this style
    uint32_t color_bg,
             color_border,
             color_aoptbg,
             color_aopttext,
             color_text;

    switch(b->style) {
        case AUXILIARY_STYLE:
            color_bg = COLOR_BACKGROUND_AUX;
            color_border = COLOR_AUX_EDGE_ACTIVE;
            color_aoptbg = COLOR_AUX_ACTIVEOPTION_BACKGROUND;
            color_aopttext = COLOR_AUX_ACTIVEOPTION_TEXT;
            color_text = COLOR_AUX_TEXT;
            break;
        default:
            color_bg = COLOR_BACKGROUND_MAIN;
            color_border = COLOR_EDGE_ACTIVE;
            color_aoptbg = COLOR_ACTIVEOPTION_BACKGROUND;
            color_aopttext = COLOR_ACTIVEOPTION_TEXT;
            color_text = COLOR_MAIN_TEXT;
            break;
    }

    int x = active_x, y = active_y, w = active_width, h = active_height;

    int i, sign = 1;

    // Increase width if needed, so that all menu items fit.
    for(i = 0; i != b->dropcount; i++) {
        STRING* e = b->ondisplay(i, b);
        int needed_w = textwidth(e->str, e->length) + 4 * SCALE;
        if(w < needed_w) {
            w = needed_w;
        }
    }

    if(y + h * b->dropcount > utox_window_height) {
        y -= h * (b->dropcount - 1);
        sign = -1;
    }

    draw_rect_fill (x, y, w, h * b->dropcount, color_bg);
    draw_rect_frame(x, y, w, h * b->dropcount, color_border);

    if(sign == -1) {
        y += h * (b->dropcount - 1);
    }

    for(i = 0; i != b->dropcount; i++) {
        int j = index(b, i);
        STRING* e = b->ondisplay(j, b);
        if(j == b->over) {
            draw_rect_fill(x + 1, y + 1, w - 2, h - 2, color_aoptbg);
            setcolor(color_aopttext);
        } else {
            setcolor(color_text);
        }
        setfont(FONT_TEXT);
        drawtext(x + 2 * SCALE, y + 2 * SCALE, e->str, e->length);

        y += sign * h;
    }
}
示例#6
0
void draw_highlight_col(std::ostream& out, int col, float r, float g, float b) {
	draw_rect_fill(out, padsize + col * cellsize, padsize, cellsize, gridsize, r, g, b);
}
示例#7
0
void draw_highlight_row(std::ostream& out, int row, float r, float g, float b) {
	draw_rect_fill(out, padsize, padsize + row * cellsize, gridsize, cellsize, r, g, b);
}
示例#8
0
void draw_highlight_box(std::ostream& out, int boxid, float r, float g, float b) {
	draw_rect_fill(out, padsize + (boxid % 3) * boxsize, padsize + (boxid / 3) * boxsize, boxsize, boxsize, r, g, b);
}
示例#9
0
void draw_highlight_candidate(std::ostream& out, Spot spot, int val, float r, float g, float b) {
	draw_rect_fill(out, padsize + cellsize * spot.col + ((val-1) % 3) * candidatesize, padsize + cellsize * spot.row + ((val-1) / 3) * candidatesize, candidatesize, candidatesize, r, g, b);
}
示例#10
0
void draw_highlight_cell(std::ostream& out, Spot spot, float r, float g, float b) {
	draw_rect_fill(out, padsize + cellsize * spot.col, padsize + cellsize * spot.row, cellsize, cellsize, r, g, b);
}