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); }
// 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; } }
// 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; } }