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); } }
void button_draw(BUTTON *b, int x, int y, int width, int height) { if(b->nodraw) { return; } if(b->updatecolor) { b->updatecolor(b); } // Ensure that font is set before calculating position and width. setfont(FONT_SELF_NAME); setcolor(WHITE); int w = width; calculate_pos_and_width(b, &x, &w); uint32_t color = b->mousedown ? b->c3 : (b->mouseover ? b->c2 : b->c1); if(b->bm) { drawalpha(b->bm, x, y, width, height, color); } else { drawrectw(x, y, w, height, b->disabled ? LIST_MAIN : color); //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, WHITE); } 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); w -= width / 2 + 1; } } STRING* s = maybe_i18nal_string_get(&b->button_text); drawtext(x + 3 * SCALE, y + SCALE, s->str, s->length); } }
void edit_draw(EDIT *edit, int x, int y, int width, int height) { if((width - 4 * SCALE - SCROLL_WIDTH) < 0) { return; } if(utox_window_baseline && y > utox_window_baseline - font_small_lineheight - 4 * SCALE) { y = utox_window_baseline - font_small_lineheight - 4 * SCALE; } edit->width = width -4 * SCALE - (edit->multiline ? SCROLL_WIDTH : 0); edit->height = height - 4 * SCALE; if(!edit->noborder) { framerect(x, y, x + width, y + height, (edit == active_edit) ? BLUE : (edit->mouseover ? C_GRAY2 : C_GRAY)); } drawrect(x + 1, y + 1, x + width - 1, y + height - 1, WHITE); setfont(FONT_TEXT); setcolor(COLOR_TEXT); int yy = y; if(edit->multiline) { pushclip(x + 1, y + 1, width - 2, height - 2); SCROLLABLE *scroll = edit->scroll; scroll->content_height = text_height(width - 4 * SCALE - SCROLL_WIDTH, font_small_lineheight, edit->data, edit->length) + 4 * SCALE; scroll_draw(scroll, x, y, width, height); yy -= scroll_gety(scroll, height); } if(!edit->length && maybe_i18nal_string_is_valid(&edit->empty_str)) { STRING* empty_str_text = maybe_i18nal_string_get(&edit->empty_str); setcolor(C_GRAY2); drawtext(x + 2 * SCALE, yy + 2 * SCALE, empty_str_text->str, empty_str_text->length); } _Bool a = (edit == active_edit); drawtextmultiline(x + 2 * SCALE, x + width - 2 * SCALE - (edit->multiline ? SCROLL_WIDTH : 0), yy + 2 * SCALE, y, y + height, font_small_lineheight, edit->data, edit->length, a ? edit_sel.start : STRING_IDX_MAX, a ? edit_sel.length : STRING_IDX_MAX, edit->multiline); if(edit->multiline) { popclip(); } }
static void calculate_pos_and_width(BUTTON *b, int *x, int *w) { int old_w = *w; // Increase width if needed, so that button text fits. if(maybe_i18nal_string_is_valid(&b->button_text)) { STRING* s = maybe_i18nal_string_get(&b->button_text); int needed_w = textwidth(s->str, s->length) + 6 * SCALE; if(*w < needed_w) { *w = needed_w; } } // Push away from the right border to fit, // if our panel is right-adjusted. if(b->panel.x < 0) { *x -= *w - old_w; } }
// Generic display function for list-based dropdowns, // userdata of which is an array of DROP_ELEMENTs. STRING* list_dropdown_ondisplay(uint16_t i, const DROPDOWN* dm) { DROP_ELEMENT *e = &((DROP_ELEMENT*) dm->userdata)[i]; return maybe_i18nal_string_get(&e->name); }