/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_livedb_draw_content_count_icons(ListBase *lb, int xmax, int *offsx, int ys) { int cat_cnt = 0, mat_cnt = 0, string_width; LiveDbTreeElement *te; char cnt_str[16]; float ufac = UI_UNIT_X / 20.0f; if ((*offsx) - UI_UNIT_X > xmax) return; for (te = lb->first; te; te = te->next) { if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) ++cat_cnt; else ++mat_cnt; } if (cat_cnt > 0) { snprintf(cnt_str, 16, "%d", cat_cnt); string_width = UI_fontstyle_string_width(UI_FSTYLE_WIDGET, cnt_str); UI_draw_roundbox_corner_set(UI_CNR_ALL); glColor4ub(220, 220, 255, 100); UI_draw_roundbox((float) *offsx - 4.0f * ufac, (float)ys + 1.0f * ufac, (float)*offsx + UI_UNIT_X + string_width, (float)ys + UI_UNIT_Y - ufac, (float)UI_UNIT_Y / 2.0f - ufac); glEnable(GL_BLEND); /* roundbox disables */ UI_icon_draw((float)*offsx, (float)ys + 2 * ufac, ICON_FILE_FOLDER); (*offsx) += UI_UNIT_X; UI_ThemeColor(TH_TEXT); UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, (float)*offsx - 2 * ufac, (float)ys + 5 * ufac, cnt_str); offsx += (int)(UI_UNIT_X + string_width); } if (mat_cnt > 0) { snprintf(cnt_str, 16, "%d", mat_cnt); string_width = UI_fontstyle_string_width(UI_FSTYLE_WIDGET, cnt_str); UI_draw_roundbox_corner_set(UI_CNR_ALL); glColor4ub(220, 220, 255, 100); UI_draw_roundbox((float) *offsx - 4.0f * ufac, (float)ys + 1.0f * ufac, (float)*offsx + UI_UNIT_X + string_width, (float)ys + UI_UNIT_Y - ufac, (float)UI_UNIT_Y / 2.0f - ufac); glEnable(GL_BLEND); /* roundbox disables */ UI_icon_draw((float)*offsx, (float)ys + 2 * ufac, ICON_MATERIAL); (*offsx) += UI_UNIT_X; UI_ThemeColor(TH_TEXT); UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, (float)*offsx - 2 * ufac, (float)ys + 5 * ufac, cnt_str); offsx += (int)(UI_UNIT_X + string_width); } } /* mat_livedb_draw_content_count_icons() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_draw_rename_buttons(const bContext *C, uiBlock *block, ARegion *ar, SpaceLDB *slivedb, ListBase *lb) { LiveDbTreeElement *te; int spx, dx, CUR_UNIT_Y; for (te = lb->first; te; te = te->next) { if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) CUR_UNIT_Y = UI_UNIT_Y; else CUR_UNIT_Y = MAT_LIVEDB_UI_UNIT_Y; if (te->ys + 2 * CUR_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) { if (*te->flag & TE_TEXTBUT) { uiBut *bt; if(new_name[0] == 0) strcpy(new_name, te->name); dx = (int)UI_fontstyle_string_width(UI_FSTYLE_WIDGET, te->name); if (dx < 5 * UI_UNIT_X) dx = 5 * UI_UNIT_X; spx = te->xs + 1.8f * UI_UNIT_X; if (spx + dx + 0.5f * UI_UNIT_X > ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax - spx - 0.5f * UI_UNIT_X; bt = uiDefBut(block, UI_BTYPE_TEXT, LDB_NAMEBUTTON, "", spx, (int)te->ys + UI_UNIT_Y * 3, dx + UI_UNIT_X, UI_UNIT_Y - 1, (void *)new_name, 1.0, 255.0f, 0, 0, ""); UI_but_func_rename_set(bt, mat_livedb_namebutton_cb, te->item); /* returns false if button got removed */ if (!UI_but_active_only(C, ar, block, bt)) { *te->flag &= ~TE_TEXTBUT; new_name[0] = 0; } } } if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) mat_draw_rename_buttons(C, block, ar, slivedb, &te->subtree); } } /* mat_draw_rename_buttons() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_livedb_width(SpaceLDB *slivedb, ListBase *lb, int *w, short startx) { LiveDbTreeElement *te = lb->first; while (te) { if (!MAT_LIVEDB_ELEM_OPEN(te, slivedb)) { short offsx = te->xend = startx + UI_UNIT_X * 3 + UI_fontstyle_string_width(UI_FSTYLE_WIDGET, te->name); if (offsx > *w) *w = offsx; } mat_livedb_width(slivedb, &te->subtree, w, startx + UI_UNIT_X); te = te->next; } } /* mat_livedb_width() */
static void wm_drop_operator_draw(const char *name, int x, int y) { int width = UI_fontstyle_string_width(name); int padding = 4 * UI_DPI_FAC; glColor4ub(0, 0, 0, 50); UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA); UI_draw_roundbox(x, y, x + width + 2 * padding, y + 4 * padding, padding); glColor4ub(255, 255, 255, 255); UI_draw_string(x + padding, y + padding, name); }
/* Draw current frame number in a little green box beside the current frame indicator */ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; float xscale, yscale, x, y; char numstr[32] = " t"; /* t is the character to start replacing from */ int slen; /* because the frame number text is subject to the same scaling as the contents of the view */ UI_view2d_scale_get(v2d, &xscale, &yscale); glScalef(1.0f / xscale, 1.0f, 1.0f); /* get timecode string * - padding on str-buf passed so that it doesn't sit on the frame indicator * - power = 0, gives 'standard' behavior for time * but power = 1 is required for frames (to get integer frames) */ if (time) { BLI_timecode_string_from_time(&numstr[4], sizeof(numstr) - 4, 0, FRA2TIME(cfra), FPS, U.timecode_style); } else { BLI_timecode_string_from_time_seconds(&numstr[4], sizeof(numstr) - 4, 1, cfra); } slen = UI_fontstyle_string_width(fstyle, numstr) - 1; /* get starting coordinates for drawing */ x = cfra * xscale; y = 0.9f * U.widget_unit; /* draw green box around/behind text */ UI_ThemeColorShade(TH_CFRAME, 0); glRectf(x, y, x + slen, y + 0.75f * U.widget_unit); /* draw current frame number - black text */ UI_ThemeColor(TH_TEXT); UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr); /* restore view transform */ glScalef(xscale, 1.0, 1.0); }
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_livedb_draw_tree_element(bContext *C, uiBlock *block, ARegion *ar, SpaceLDB *slivedb, LiveDbTreeElement *te, int startx, int *starty, int *row_num) { LiveDbTreeElement *ten; float ufac = UI_UNIT_X / 20.0f; int offsx = 0, active = 0; int CUR_UNIT_Y; if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) CUR_UNIT_Y = UI_UNIT_Y; else CUR_UNIT_Y = MAT_LIVEDB_UI_UNIT_Y; *starty -= CUR_UNIT_Y; ++ *row_num; if (*starty + 2 * CUR_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) { int xmax = ar->v2d.cur.xmax; unsigned char alpha = 128; /* icons can be ui buts, we don't want it to overlap with material previews */ if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_MATERIAL) xmax -= MAT_LIVEDB_UI_UNIT_Y; glEnable(GL_BLEND); if(*row_num % 2) { UI_ThemeColorShade(TH_BACK, 6); glRecti(0, *starty + 1, ar->v2d.cur.xmax, *starty + CUR_UNIT_Y - 1); } if (*te->flag & TE_SELECTED) { float col[4]; unsigned char col_circle[4]; UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col); glColor3fv(col); glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + CUR_UNIT_Y - 1); /* active circle */ UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col_circle); col_circle[3] = alpha; glColor4ubv((GLubyte *)col_circle); UI_draw_roundbox_corner_set(UI_CNR_ALL); UI_draw_roundbox((float)startx + UI_UNIT_X - ufac, (float)*starty + (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY ? 1.0f : UI_UNIT_Y * 3), (float)startx + 2.0f * UI_UNIT_X - 2.0f * ufac, (float)*starty + CUR_UNIT_Y - 1.0f * ufac, UI_UNIT_Y / 2.0f - 1.0f * ufac); glEnable(GL_BLEND); /* roundbox disables it */ } /* start by highlighting search matches */ if (SEARCHING_MAT_LIVEDB(slivedb) && (*te->flag & TE_SEARCHMATCH)) { char col[4]; UI_GetThemeColorType4ubv(TH_MATCH, SPACE_MAT_LIVEDB, col); col[3] = alpha; glColor4ubv((GLubyte *)col); glRecti(startx, *starty + 1, ar->v2d.cur.xmax, *starty + CUR_UNIT_Y - 1); } /* open/close icon, only when sublevels */ if (te->subtree.first || (*te->flag & TE_LAZY_CLOSED)) { int icon_x; if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) icon_x = startx; else icon_x = startx + 5 * ufac; if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) UI_icon_draw((float)icon_x, (float)*starty + 2 * ufac, ICON_DISCLOSURE_TRI_DOWN); else UI_icon_draw((float)icon_x, (float)*starty + 2 * ufac, ICON_DISCLOSURE_TRI_RIGHT); } offsx += UI_UNIT_X; /* Element type icon */ if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) mat_livedb_elem_draw_icon((float)startx + offsx, (float)*starty, te); else mat_livedb_elem_draw_icon((float)startx + offsx, (float)*starty + UI_UNIT_X * 3, te); offsx += UI_UNIT_X; glDisable(GL_BLEND); /* name */ if (active == 1) UI_ThemeColor(TH_TEXT_HI); else UI_ThemeColor(TH_TEXT); if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + 5 * ufac, te->name); else { uiBut *bt; UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + UI_UNIT_X * 3 + 5 * ufac, te->name); UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + UI_UNIT_X * 2 + 5 * ufac, te->nick_name); UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + UI_UNIT_X + 5 * ufac, te->copyright); bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_WORLD, xmax - UI_UNIT_X - 3, *starty + 1 * ufac, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5f, "Get item"); UI_but_func_set(bt, get_material_cb, (void*)slivedb->server_address, (void*)te->item->mat_item.id); UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK); } offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(UI_FSTYLE_WIDGET, te->name)); /* Closed item, we draw the category-info icons */ if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY && !MAT_LIVEDB_ELEM_OPEN(te, slivedb)) { if (te->subtree.first) { int tempx = startx + offsx; /* divider */ UI_ThemeColorShade(TH_BACK, -40); glRecti(tempx - 10.0f * ufac, *starty + 4.0f * ufac, tempx - 8.0f * ufac, *starty + CUR_UNIT_Y - 4.0f * ufac); glEnable(GL_BLEND); glPixelTransferf(GL_ALPHA_SCALE, 0.5); mat_livedb_draw_content_count_icons(&te->subtree, xmax, &tempx, *starty); glPixelTransferf(GL_ALPHA_SCALE, 1.0); glDisable(GL_BLEND); } } } /* store coord and continue, we need coordinates for elements outside view too */ te->xs = (float)startx; te->ys = (float)*starty; te->xend = startx + offsx; if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) { for (ten = te->subtree.first; ten; ten = ten->next) mat_livedb_draw_tree_element(C, block, ar, slivedb, ten, startx + UI_UNIT_X, starty, row_num); } else { for (ten = te->subtree.first; ten; ten = ten->next) mat_livedb_set_coord_tree_element(slivedb, te, startx, starty); } } /* mat_livedb_draw_tree_element() */
/* if rect set, do not draw */ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) { wmWindowManager *wm = CTX_wm_manager(C); wmDrag *drag; const int winsize_y = WM_window_pixels_y(win); int cursorx, cursory, x, y; cursorx = win->eventstate->x; cursory = win->eventstate->y; if (rect) { rect->xmin = rect->xmax = cursorx; rect->ymin = rect->ymax = cursory; } /* XXX todo, multiline drag draws... but maybe not, more types mixed wont work well */ glEnable(GL_BLEND); for (drag = wm->drags.first; drag; drag = drag->next) { int iconsize = 16 * UI_DPI_FAC; /* assumed to be 16 pixels */ int padding = 4 * UI_DPI_FAC; /* image or icon */ if (drag->imb) { x = cursorx - drag->sx / 2; y = cursory - drag->sy / 2; if (rect) drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy); else { glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */ glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, drag->imb->rect, drag->scale, drag->scale); } } else { x = cursorx - 2 * padding; y = cursory - 2 * UI_DPI_FAC; if (rect) drag_rect_minmax(rect, x, y, x + iconsize, y + iconsize); else UI_icon_draw_aspect(x, y, drag->icon, 1.0f / UI_DPI_FAC, 0.8); } /* item name */ if (drag->imb) { x = cursorx - drag->sx / 2; y = cursory - drag->sy / 2 - iconsize; } else { x = cursorx + 10 * UI_DPI_FAC; y = cursory + 1 * UI_DPI_FAC; } if (rect) { int w = UI_fontstyle_string_width(wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x + w, y + iconsize); } else { glColor4ub(255, 255, 255, 255); UI_draw_string(x, y, wm_drag_name(drag)); } /* operator name with roundbox */ if (drag->opname[0]) { if (drag->imb) { x = cursorx - drag->sx / 2; if (cursory + drag->sy / 2 + padding + iconsize < winsize_y) y = cursory + drag->sy / 2 + padding; else y = cursory - drag->sy / 2 - padding - iconsize - padding - iconsize; } else { x = cursorx - 2 * padding; if (cursory + iconsize + iconsize < winsize_y) y = cursory + iconsize; else y = cursory - iconsize - 2 * UI_DPI_FAC; } if (rect) { int w = UI_fontstyle_string_width(wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x + w, y + iconsize); } else wm_drop_operator_draw(drag->opname, x, y); } } glDisable(GL_BLEND); }
static float ui_pie_menu_title_width(const char *name, int icon) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f)))); }
/* Note: This function uses pixelspace (0, 0, winx, winy), not view2d. * The controls are laid out as follows: * * ------------------------------------------- * | Directory input | execute | * ------------------------------------------- * | Filename input | + | - | cancel | * ------------------------------------------- * * The input widgets will stretch to fill any excess space. * When there isn't enough space for all controls to be shown, they are * hidden in this order: x/-, execute/cancel, input widgets. */ void file_draw_buttons(const bContext *C, ARegion *ar) { /* Button layout. */ const int max_x = ar->winx - 10; const int line1_y = ar->winy - (IMASEL_BUTTONS_HEIGHT / 2 + IMASEL_BUTTONS_MARGIN); const int line2_y = line1_y - (IMASEL_BUTTONS_HEIGHT / 2 + IMASEL_BUTTONS_MARGIN); const int input_minw = 20; const int btn_h = UI_UNIT_Y; const int btn_fn_w = UI_UNIT_X; const int btn_minw = 80; const int btn_margin = 20; const int separator = 4; /* Additional locals. */ char uiblockstr[32]; int loadbutton; int fnumbuttons; int min_x = 10; int chan_offs = 0; int available_w = max_x - min_x; int line1_w = available_w; int line2_w = available_w; uiBut *but; uiBlock *block; SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_params(sfile); ARegion *artmp; const bool is_browse_only = (sfile->op == NULL); /* Initialize UI block. */ BLI_snprintf(uiblockstr, sizeof(uiblockstr), "win %p", (void *)ar); block = UI_block_begin(C, ar, uiblockstr, UI_EMBOSS); /* exception to make space for collapsed region icon */ for (artmp = CTX_wm_area(C)->regionbase.first; artmp; artmp = artmp->next) { if (artmp->regiontype == RGN_TYPE_TOOLS && artmp->flag & RGN_FLAG_HIDDEN) { chan_offs = 16; min_x += chan_offs; available_w -= chan_offs; } } /* Is there enough space for the execute / cancel buttons? */ if (is_browse_only) { loadbutton = 0; } else { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; loadbutton = UI_fontstyle_string_width(fstyle, params->title) + btn_margin; CLAMP_MIN(loadbutton, btn_minw); if (available_w <= loadbutton + separator + input_minw) { loadbutton = 0; } } if (loadbutton) { line1_w -= (loadbutton + separator); line2_w = line1_w; } /* Is there enough space for file number increment/decrement buttons? */ fnumbuttons = 2 * btn_fn_w; if (!loadbutton || line2_w <= fnumbuttons + separator + input_minw) { fnumbuttons = 0; } else { line2_w -= (fnumbuttons + separator); } /* Text input fields for directory and file. */ if (available_w > 0) { const struct direntry *file = sfile->files ? filelist_file(sfile->files, params->active_file) : NULL; int overwrite_alert = file_draw_check_exists(sfile); const bool is_active_dir = file && file->path && BLI_is_dir(file->path); /* callbacks for operator check functions */ UI_block_func_set(block, file_draw_check_cb, NULL, NULL); but = uiDefBut(block, UI_BTYPE_TEXT, -1, "", min_x, line1_y, line1_w - chan_offs, btn_h, params->dir, 0.0, (float)FILE_MAX, 0, 0, TIP_("File path")); UI_but_func_complete_set(but, autocomplete_directory, NULL); UI_but_flag_enable(but, UI_BUT_NO_UTF8); UI_but_flag_disable(but, UI_BUT_UNDO); UI_but_funcN_set(but, file_directory_enter_handle, NULL, but); /* TODO, directory editing is non-functional while a library is loaded * until this is properly supported just disable it. */ if (sfile->files && filelist_lib(sfile->files)) UI_but_flag_enable(but, UI_BUT_DISABLED); if ((params->flag & FILE_DIRSEL_ONLY) == 0) { but = uiDefBut(block, UI_BTYPE_TEXT, -1, "", min_x, line2_y, line2_w - chan_offs, btn_h, is_active_dir ? (char *)"" : params->file, 0.0, (float)FILE_MAXFILE, 0, 0, TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name"))); UI_but_func_complete_set(but, autocomplete_file, NULL); UI_but_flag_enable(but, UI_BUT_NO_UTF8); UI_but_flag_disable(but, UI_BUT_UNDO); /* silly workaround calling NFunc to ensure this does not get called * immediate ui_apply_but_func but only after button deactivates */ UI_but_funcN_set(but, file_filename_enter_handle, NULL, but); /* check if this overrides a file and if the operator option is used */ if (overwrite_alert) { UI_but_flag_enable(but, UI_BUT_REDALERT); } } /* clear func */ UI_block_func_set(block, NULL, NULL, NULL); } /* Filename number increment / decrement buttons. */ if (fnumbuttons && (params->flag & FILE_DIRSEL_ONLY) == 0) { UI_block_align_begin(block); but = uiDefIconButO(block, UI_BTYPE_BUT, "FILE_OT_filenum", 0, ICON_ZOOMOUT, min_x + line2_w + separator - chan_offs, line2_y, btn_fn_w, btn_h, TIP_("Decrement the filename number")); RNA_int_set(UI_but_operator_ptr_get(but), "increment", -1); but = uiDefIconButO(block, UI_BTYPE_BUT, "FILE_OT_filenum", 0, ICON_ZOOMIN, min_x + line2_w + separator + btn_fn_w - chan_offs, line2_y, btn_fn_w, btn_h, TIP_("Increment the filename number")); RNA_int_set(UI_but_operator_ptr_get(but), "increment", 1); UI_block_align_end(block); } /* Execute / cancel buttons. */ if (loadbutton) { const struct direntry *file = filelist_file(sfile->files, params->active_file); const char *str_exec = (file && file->path && BLI_is_dir(file->path)) ? /* params->title is already translated! */ IFACE_("Open Directory") : params->title; uiDefButO(block, UI_BTYPE_BUT, "FILE_OT_execute", WM_OP_EXEC_REGION_WIN, str_exec, max_x - loadbutton, line1_y, loadbutton, btn_h, ""); uiDefButO(block, UI_BTYPE_BUT, "FILE_OT_cancel", WM_OP_EXEC_REGION_WIN, IFACE_("Cancel"), max_x - loadbutton, line2_y, loadbutton, btn_h, ""); } UI_block_end(C, block); UI_block_draw(C, block); }