static void node_uiblocks_init(const bContext *C, bNodeTree *ntree) { bNode *node; char str[32]; /* add node uiBlocks in reverse order - prevents events going to overlapping nodes */ /* process selected nodes first so they're at the start of the uiblocks list */ for(node= ntree->nodes.last; node; node= node->prev) { if (node->flag & NODE_SELECT) { /* ui block */ sprintf(str, "node buttons %p", (void *)node); node->block= uiBeginBlock(C, CTX_wm_region(C), str, UI_EMBOSS); uiBlockSetHandleFunc(node->block, do_node_internal_buttons, node); } } /* then the rest */ for(node= ntree->nodes.last; node; node= node->prev) { if (!(node->flag & (NODE_GROUP_EDIT|NODE_SELECT))) { /* ui block */ sprintf(str, "node buttons %p", (void *)node); node->block= uiBeginBlock(C, CTX_wm_region(C), str, UI_EMBOSS); uiBlockSetHandleFunc(node->block, do_node_internal_buttons, node); } } }
static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op) { static char search[256] = ""; wmEvent event; wmWindow *win = CTX_wm_window(C); uiBlock *block; uiBut *but; wmOperator *op = (wmOperator *)arg_op; block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS); uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU); but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, 9 * UI_UNIT_X, UI_UNIT_Y, 0, 0, ""); uiButSetSearchFunc(but, node_find_cb, op->type, node_find_call_cb, NULL); /* fake button, it holds space for search items */ uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxHeight(), uiSearchBoxWidth(), uiSearchBoxHeight(), NULL, 0, 0, 0, 0, NULL); uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */ uiEndBlock(C, block); // uiButActiveOnly(C, ar, block, but); XXX using this here makes Blender hang - investigate wm_event_init_from_window(win, &event); event.type = EVT_BUT_OPEN; event.val = KM_PRESS; event.customdata = but; event.customdatafree = FALSE; wm_event_add(win, &event); return block; }
/* ID Search browse menu, open */ static uiBlock *tool_search_menu(bContext *C, ARegion *ar, void *arg_listbase) { static char search[OP_MAX_TYPENAME]; wmEvent event; wmWindow *win= CTX_wm_window(C); uiBlock *block; uiBut *but; /* clear initial search string, then all items show */ search[0]= 0; block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS); uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1); /* fake button, it holds space for search items */ uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL); but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, OP_MAX_TYPENAME, 10, 0, 150, 19, 0, 0, ""); uiButSetSearchFunc(but, operator_search_cb, arg_listbase, operator_call_cb, NULL); uiBoundsBlock(block, 6); uiBlockSetDirection(block, UI_DOWN); uiEndBlock(C, block); event= *(win->eventstate); /* XXX huh huh? make api call */ event.type= EVT_BUT_OPEN; event.val= KM_PRESS; event.customdata= but; event.customdatafree= FALSE; wm_event_add(win, &event); return block; }
void sound_header_buttons(const bContext *C, ARegion *ar) { ScrArea *sa= CTX_wm_area(C); uiBlock *block; int xco, yco= 3; block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS); uiBlockSetHandleFunc(block, do_sound_buttons, NULL); xco= ED_area_header_standardbuttons(C, block, yco); if((sa->flag & HEADER_NO_PULLDOWN)==0) { int xmax; xmax= GetButStringLength("View"); uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C), "View", xco, yco-2, xmax-3, UI_UNIT_Y, ""); xco+=UI_UNIT_X+xmax; } uiBlockSetEmboss(block, UI_EMBOSS); /* always as last */ UI_view2d_totRect_set(&ar->v2d, xco+UI_UNIT_X+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin); uiEndBlock(C, block); uiDrawBlock(C, block); }
static uiBlock *dummy_viewmenu(bContext *C, ARegion *ar, void *UNUSED(arg)) { ScrArea *curarea= CTX_wm_area(C); uiBlock *block; short yco= 0, menuwidth=120; block= uiBeginBlock(C, ar, "dummy_viewmenu", UI_EMBOSSP); uiBlockSetButmFunc(block, do_viewmenu, NULL); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); } else { uiBlockSetDirection(block, UI_TOP); uiBlockFlipOrder(block); } uiTextBoundsBlock(block, 50); uiEndBlock(C, block); return block; }
void buttons_header_buttons(const bContext *C, ARegion *ar) { SpaceButs *sbuts = CTX_wm_space_buts(C); uiBlock *block; uiBut *but; int xco, yco = 2; buttons_context_compute(C, sbuts); block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); uiBlockSetHandleFunc(block, do_buttons_buttons, NULL); xco = ED_area_header_switchbutton(C, block, yco); uiBlockSetEmboss(block, UI_EMBOSS); xco -= UI_UNIT_X; // Default panels uiBlockBeginAlign(block); #define BUTTON_HEADER_CTX(_ctx, _icon, _tip) \ if (sbuts->pathflag & (1 << _ctx)) { \ but = uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, _icon, xco += BUT_UNIT_X, yco, BUT_UNIT_X, UI_UNIT_Y, &(sbuts->mainb), 0.0, (float)_ctx, 0, 0, TIP_(_tip)); \ uiButClearFlag(but, UI_BUT_UNDO); \ } \ BUTTON_HEADER_CTX(BCONTEXT_RENDER, ICON_SCENE, N_("Render")) BUTTON_HEADER_CTX(BCONTEXT_SCENE, ICON_SCENE_DATA, N_("Scene")); BUTTON_HEADER_CTX(BCONTEXT_WORLD, ICON_WORLD, N_("World")); BUTTON_HEADER_CTX(BCONTEXT_OBJECT, ICON_OBJECT_DATA, N_("Object")); BUTTON_HEADER_CTX(BCONTEXT_CONSTRAINT, ICON_CONSTRAINT, N_("Object Constraints")); BUTTON_HEADER_CTX(BCONTEXT_MODIFIER, ICON_MODIFIER, N_("Object Modifiers")); BUTTON_HEADER_CTX(BCONTEXT_DATA, sbuts->dataicon, N_("Object Data")); BUTTON_HEADER_CTX(BCONTEXT_BONE, ICON_BONE_DATA, N_("Bone")); BUTTON_HEADER_CTX(BCONTEXT_BONE_CONSTRAINT, ICON_CONSTRAINT_BONE, N_("Bone Constraints")); BUTTON_HEADER_CTX(BCONTEXT_MATERIAL, ICON_MATERIAL, N_("Material")); BUTTON_HEADER_CTX(BCONTEXT_TEXTURE, ICON_TEXTURE, N_("Textures")); BUTTON_HEADER_CTX(BCONTEXT_PARTICLE, ICON_PARTICLES, N_("Particles")); BUTTON_HEADER_CTX(BCONTEXT_PHYSICS, ICON_PHYSICS, N_("Physics")); #undef BUTTON_HEADER_CTX xco += BUT_UNIT_X; uiBlockEndAlign(block); /* always as last */ UI_view2d_totRect_set(&ar->v2d, xco + (UI_UNIT_X / 2), ar->v2d.tot.ymax - ar->v2d.tot.ymin); uiEndBlock(C, block); uiDrawBlock(C, block); }
static void node_uiblocks_init(const bContext *C, bNodeTree *ntree) { bNode *node; char str[32]; /* add node uiBlocks in drawing order - prevents events going to overlapping nodes */ for(node= ntree->nodes.first; node; node=node->next) { /* ui block */ sprintf(str, "node buttons %p", (void *)node); node->block= uiBeginBlock(C, CTX_wm_region(C), str, UI_EMBOSS); uiBlockSetHandleFunc(node->block, do_node_internal_buttons, node); /* this cancels events for background nodes */ uiBlockSetFlag(node->block, UI_BLOCK_CLIP_EVENTS); } }
static void image_panel_preview(ScrArea *sa, short cntrl) // IMAGE_HANDLER_PREVIEW { uiBlock *block; SpaceImage *sima = sa->spacedata.first; int ofsx, ofsy; if (is_preview_allowed(sa) == 0) { rem_blockhandler(sa, IMAGE_HANDLER_PREVIEW); G.scene->r.scemode &= ~R_COMP_CROP; /* quite weak */ return; } block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl); uiSetPanelHandler(IMAGE_HANDLER_PREVIEW); // for close and esc ofsx = -150 + (sa->winx / 2) / sima->blockscale; ofsy = -100 + (sa->winy / 2) / sima->blockscale; if (uiNewPanel(C, ar, block, "Preview", "Image", ofsx, ofsy, 300, 200) == 0) return; uiBlockSetDrawExtraFunc(block, preview_cb); }
static void view3d_panel_preview(bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_PREVIEW { uiBlock *block; View3D *v3d= sa->spacedata.first; int ofsx, ofsy; block= uiBeginBlock(C, ar, "view3d_panel_preview", UI_EMBOSS); uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl); uiSetPanelHandler(VIEW3D_HANDLER_PREVIEW); // for close and esc ofsx= -150+(sa->winx/2)/v3d->blockscale; ofsy= -100+(sa->winy/2)/v3d->blockscale; if(uiNewPanel(C, ar, block, "Preview", "View3d", ofsx, ofsy, 300, 200)==0) return; uiBlockSetDrawExtraFunc(block, BIF_view3d_previewdraw); if(scene->recalc & SCE_PRV_CHANGED) { scene->recalc &= ~SCE_PRV_CHANGED; //printf("found recalc\n"); BIF_view3d_previewrender_free(sa->spacedata.first); BIF_preview_changed(0); } }
/* left hand part */ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; View2D *v2d = &ar->v2d; float y = 0.0f, height; size_t items; int i = 0; /* build list of channels to draw */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* Update max-extent of channels here (taking into account scrollers): * - this is done to allow the channel list to be scrollable, but must be done here * to avoid regenerating the list again and/or also because channels list is drawn first * - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for * start of list offset, and the second is as a correction for the scrollers. */ height = (float)((items * ACHANNEL_STEP) + (ACHANNEL_HEIGHT * 2)); UI_view2d_totRect_set(v2d, ar->winx, height); /* loop through channels, and set up drawing depending on their type */ { /* first pass: just the standard GL-drawing for backdrop + text */ y = (float)ACHANNEL_FIRST; for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) { const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF); const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw(ac, ale, yminc, ymaxc); } /* adjust y-position for next one */ y -= ACHANNEL_STEP; } } { /* second pass: widgets */ uiBlock *block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); size_t channel_index = 0; y = (float)ACHANNEL_FIRST; /* set blending again, as may not be set in previous step */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) { const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF); const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw_widgets(C, ac, ale, block, yminc, ymaxc, channel_index); } /* adjust y-position for next one */ y -= ACHANNEL_STEP; channel_index++; } uiEndBlock(C, block); uiDrawBlock(C, block); glDisable(GL_BLEND); } /* free tempolary channels */ BLI_freelistN(&anim_data); }
void draw_nla_channel_list (bContext *C, bAnimContext *ac, SpaceNla *snla, ARegion *ar) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; View2D *v2d= &ar->v2d; float y= 0.0f; int items, height; /* build list of channels to draw */ filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS); items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* Update max-extent of channels here (taking into account scrollers): * - this is done to allow the channel list to be scrollable, but must be done here * to avoid regenerating the list again and/or also because channels list is drawn first * - offset of NLACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for * start of list offset, and the second is as a correction for the scrollers. */ height= ((items*NLACHANNEL_STEP) + (NLACHANNEL_HEIGHT*2)); /* don't use totrect set, as the width stays the same * (NOTE: this is ok here, the configuration is pretty straightforward) */ v2d->tot.ymin= (float)(-height); /* draw channels */ { /* first pass: backdrops + oldstyle drawing */ y= (float)(-NLACHANNEL_HEIGHT); draw_nla_channel_list_gl(ac, &anim_data, v2d, y); } { /* second pass: UI widgets */ uiBlock *block= uiBeginBlock(C, ar, "NLA channel buttons", UI_EMBOSS); y= (float)(-NLACHANNEL_HEIGHT); /* set blending again, as may not be set in previous step */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* loop through channels, and set up drawing depending on their type */ for (ale= anim_data.first; ale; ale= ale->next) { const float yminc= (float)(y - NLACHANNEL_HEIGHT_HALF); const float ymaxc= (float)(y + NLACHANNEL_HEIGHT_HALF); /* check if visible */ if ( IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw_widgets(ac, ale, block, yminc, ymaxc); } /* adjust y-position for next one */ y -= NLACHANNEL_STEP; } uiEndBlock(C, block); uiDrawBlock(C, block); glDisable(GL_BLEND); } /* free tempolary channels */ BLI_freelistN(&anim_data); }
void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) { ScrArea *sa = CTX_wm_area(C); SpaceClip *sc = CTX_wm_space_clip(C); View2D *v2d = &ar->v2d; MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking; MovieTrackingDopesheet *dopesheet; MovieTrackingDopesheetChannel *channel; uiStyle *style = UI_GetStyle(); uiBlock *block; int fontid = style->widget.uifont_id; int height; float y; PropertyRNA *chan_prop_lock; if (!clip) return; tracking = &clip->tracking; dopesheet = &tracking->dopesheet; height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT); if (height > BLI_rcti_size_y(&v2d->mask)) { /* don't use totrect set, as the width stays the same * (NOTE: this is ok here, the configuration is pretty straightforward) */ v2d->tot.ymin = (float)(-height); } /* need to do a view-sync here, so that the keys area doesn't jump around (it must copy this) */ UI_view2d_sync(NULL, sa, v2d, V2D_LOCK_COPY); /* loop through channels, and set up drawing depending on their type * first pass: just the standard GL-drawing for backdrop + text */ y = (float) CHANNEL_FIRST; BLF_size(fontid, 11.0f * U.pixelsize, U.dpi); for (channel = dopesheet->channels.first; channel; channel = channel->next) { float yminc = (float) (y - CHANNEL_HEIGHT_HALF); float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) { MovieTrackingTrack *track = channel->track; float font_height, color[3]; int sel = track->flag & TRACK_DOPE_SEL; track_channel_color(track, NULL, color); glColor3fv(color); glRectf(v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF, v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF); if (sel) UI_ThemeColor(TH_TEXT_HI); else UI_ThemeColor(TH_TEXT); font_height = BLF_height(fontid, channel->name, sizeof(channel->name)); BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f); BLF_draw(fontid, channel->name, strlen(channel->name)); } /* adjust y-position for next one */ y -= CHANNEL_STEP; } /* second pass: widgets */ block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); y = (float) CHANNEL_FIRST; /* get RNA properties (once) */ chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock"); BLI_assert(chan_prop_lock); glEnable(GL_BLEND); for (channel = dopesheet->channels.first; channel; channel = channel->next) { float yminc = (float)(y - CHANNEL_HEIGHT_HALF); float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) { MovieTrackingTrack *track = channel->track; const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED; PointerRNA ptr; RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, &ptr); uiBlockSetEmboss(block, UI_EMBOSSN); uiDefIconButR_prop(block, ICONTOG, 1, icon, v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD, y - UI_UNIT_Y / 2.0f, UI_UNIT_X, UI_UNIT_Y, &ptr, chan_prop_lock, 0, 0, 0, 0, 0, NULL); uiBlockSetEmboss(block, UI_EMBOSS); } /* adjust y-position for next one */ y -= CHANNEL_STEP; } glDisable(GL_BLEND); uiEndBlock(C, block); uiDrawBlock(C, block); }
void file_draw_list(const bContext *C, ARegion *ar) { SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_params(sfile); FileLayout *layout = ED_fileselect_get_layout(sfile, ar); View2D *v2d = &ar->v2d; struct FileList *files = sfile->files; struct direntry *file; ImBuf *imb; uiBlock *block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); int numfiles; int numfiles_layout; int sx, sy; int offset; int textwidth, textheight; int i; short is_icon; short align; numfiles = filelist_numfiles(files); if (params->display != FILE_IMGDISPLAY) { draw_background(layout, v2d); draw_dividers(layout, v2d); } offset = ED_fileselect_layout_offset(layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax); if (offset < 0) offset = 0; numfiles_layout = ED_fileselect_layout_numfiles(layout, ar); /* adjust, so the next row is already drawn when scrolling */ if (layout->flag & FILE_LAYOUT_HOR) { numfiles_layout += layout->rows; } else { numfiles_layout += layout->columns; } textwidth = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : (int)layout->column_widths[COLUMN_NAME]; textheight = (int)(layout->textheight * 3.0 / 2.0 + 0.5); align = (FILE_IMGDISPLAY == params->display) ? UI_STYLE_TEXT_CENTER : UI_STYLE_TEXT_LEFT; for (i = offset; (i < numfiles) && (i < offset + numfiles_layout); i++) { ED_fileselect_layout_tilepos(layout, i, &sx, &sy); sx += (int)(v2d->tot.xmin + 2.0f); sy = (int)(v2d->tot.ymax - sy); file = filelist_file(files, i); UI_ThemeColor4(TH_TEXT); if (!(file->selflag & EDITING_FILE)) { if ((params->active_file == i) || (file->selflag & HILITED_FILE) || (file->selflag & SELECTED_FILE)) { int colorid = (file->selflag & SELECTED_FILE) ? TH_HILITE : TH_BACK; int shade = (params->active_file == i) || (file->selflag & HILITED_FILE) ? 20 : 0; draw_tile(sx, sy - 1, layout->tile_w + 4, sfile->layout->tile_h + layout->tile_border_y, colorid, shade); } } uiSetRoundBox(UI_CNR_NONE); if (FILE_IMGDISPLAY == params->display) { is_icon = 0; imb = filelist_getimage(files, i); if (!imb) { imb = filelist_geticon(files, i); is_icon = 1; } file_draw_preview(block, file, sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE)); } else { file_draw_icon(block, file->path, sx, sy - (UI_UNIT_Y / 6), get_file_icon(file), ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE); sx += ICON_DEFAULT_WIDTH_SCALE + 4; } UI_ThemeColor4(TH_TEXT); if (file->selflag & EDITING_FILE) { uiBut *but = uiDefBut(block, TEX, 1, "", sx, sy - layout->tile_h - 3, textwidth, textheight, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit), 0, 0, ""); uiButSetRenameFunc(but, renamebutton_cb, file); uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */ uiButClearFlag(but, UI_BUT_UNDO); if (0 == uiButActiveOnly(C, block, but)) { file->selflag &= ~EDITING_FILE; } } if (!(file->selflag & EDITING_FILE)) { int tpos = (FILE_IMGDISPLAY == params->display) ? sy - layout->tile_h + layout->textheight : sy; file_draw_string(sx + 1, tpos, file->relname, (float)textwidth, textheight, align); } if (params->display == FILE_SHORTDISPLAY) { sx += (int)layout->column_widths[COLUMN_NAME] + 12; if (!(file->type & S_IFDIR)) { file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align); sx += (int)layout->column_widths[COLUMN_SIZE] + 12; } } else if (params->display == FILE_LONGDISPLAY) { sx += (int)layout->column_widths[COLUMN_NAME] + 12; #ifndef WIN32 /* rwx rwx rwx */ file_draw_string(sx, sy, file->mode1, layout->column_widths[COLUMN_MODE1], layout->tile_h, align); sx += layout->column_widths[COLUMN_MODE1] + 12; file_draw_string(sx, sy, file->mode2, layout->column_widths[COLUMN_MODE2], layout->tile_h, align); sx += layout->column_widths[COLUMN_MODE2] + 12; file_draw_string(sx, sy, file->mode3, layout->column_widths[COLUMN_MODE3], layout->tile_h, align); sx += layout->column_widths[COLUMN_MODE3] + 12; file_draw_string(sx, sy, file->owner, layout->column_widths[COLUMN_OWNER], layout->tile_h, align); sx += layout->column_widths[COLUMN_OWNER] + 12; #endif file_draw_string(sx, sy, file->date, layout->column_widths[COLUMN_DATE], layout->tile_h, align); sx += (int)layout->column_widths[COLUMN_DATE] + 12; file_draw_string(sx, sy, file->time, layout->column_widths[COLUMN_TIME], layout->tile_h, align); sx += (int)layout->column_widths[COLUMN_TIME] + 12; if (!(file->type & S_IFDIR)) { file_draw_string(sx, sy, file->size, layout->column_widths[COLUMN_SIZE], layout->tile_h, align); sx += (int)layout->column_widths[COLUMN_SIZE] + 12; } } } uiEndBlock(C, block); uiDrawBlock(C, block); }
/* 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; /* Initialize UI block. */ BLI_snprintf(uiblockstr, sizeof(uiblockstr), "win %p", (void *)ar); block = uiBeginBlock(C, ar, uiblockstr, UI_EMBOSS); uiBlockSetHandleFunc(block, do_file_buttons, NULL); /* 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_CHANNELS && 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? */ loadbutton = UI_GetStringWidth(sfile->params->title) + btn_margin; if (loadbutton < btn_minw) { loadbutton = MAX2(btn_minw, btn_margin + UI_GetStringWidth(params->title)); } if (available_w <= loadbutton + separator + input_minw || params->title[0] == 0) { loadbutton = 0; } else { 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) { int overwrite_alert = file_draw_check_exists(sfile); /* callbacks for operator check functions */ uiBlockSetFunc(block, file_draw_check_cb, NULL, NULL); but = uiDefButTextO(block, TEX, "FILE_OT_directory", 0, "", min_x, line1_y, line1_w - chan_offs, btn_h, params->dir, 0.0, (float)FILE_MAX, 0, 0, TIP_("File path")); uiButSetCompleteFunc(but, autocomplete_directory, NULL); uiButSetFlag(but, UI_BUT_NO_UTF8); if ((params->flag & FILE_DIRSEL_ONLY) == 0) { but = uiDefBut(block, TEX, B_FS_FILENAME, "", min_x, line2_y, line2_w - chan_offs, btn_h, params->file, 0.0, (float)FILE_MAXFILE, 0, 0, TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name"))); uiButSetCompleteFunc(but, autocomplete_file, NULL); uiButSetFlag(but, UI_BUT_NO_UTF8); uiButClearFlag(but, UI_BUT_UNDO); /* operator button above does this automatic */ /* check if this overrides a file and if the operator option is used */ if (overwrite_alert) { uiButSetFlag(but, UI_BUT_REDALERT); } } /* clear func */ uiBlockSetFunc(block, NULL, NULL, NULL); } /* Filename number increment / decrement buttons. */ if (fnumbuttons && (params->flag & FILE_DIRSEL_ONLY) == 0) { uiBlockBeginAlign(block); but = uiDefIconButO(block, 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(uiButGetOperatorPtrRNA(but), "increment", -1); but = uiDefIconButO(block, 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(uiButGetOperatorPtrRNA(but), "increment", 1); uiBlockEndAlign(block); } /* Execute / cancel buttons. */ if (loadbutton) { /* params->title is already translated! */ uiDefButO(block, BUT, "FILE_OT_execute", WM_OP_EXEC_REGION_WIN, params->title, max_x - loadbutton, line1_y, loadbutton, btn_h, ""); uiDefButO(block, BUT, "FILE_OT_cancel", WM_OP_EXEC_REGION_WIN, IFACE_("Cancel"), max_x - loadbutton, line2_y, loadbutton, btn_h, ""); } uiEndBlock(C, block); uiDrawBlock(C, block); }
/* left hand part */ void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; View2D *v2d = &ar->v2d; float y = 0.0f; size_t items; int height; /* build list of channels to draw */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* Update max-extent of channels here (taking into account scrollers): * - this is done to allow the channel list to be scrollable, but must be done here * to avoid regenerating the list again and/or also because channels list is drawn first * - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for * start of list offset, and the second is as a correction for the scrollers. */ height = ((items * ACHANNEL_STEP) + (ACHANNEL_HEIGHT * 2)); if (height > (v2d->mask.ymax - v2d->mask.ymin)) { /* don't use totrect set, as the width stays the same * (NOTE: this is ok here, the configuration is pretty straightforward) */ v2d->tot.ymin = (float)(-height); } /* need to do a view-sync here, so that the keys area doesn't jump around (it must copy this) */ UI_view2d_sync(NULL, ac->sa, v2d, V2D_LOCK_COPY); /* loop through channels, and set up drawing depending on their type */ { /* first pass: just the standard GL-drawing for backdrop + text */ y = (float)ACHANNEL_FIRST; for (ale = anim_data.first; ale; ale = ale->next) { float yminc = (float)(y - ACHANNEL_HEIGHT_HALF); float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw(ac, ale, yminc, ymaxc); } /* adjust y-position for next one */ y -= ACHANNEL_STEP; } } { /* second pass: widgets */ uiBlock *block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); size_t channel_index = 0; y = (float)ACHANNEL_FIRST; for (ale = anim_data.first; ale; ale = ale->next) { float yminc = (float)(y - ACHANNEL_HEIGHT_HALF); float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw_widgets(C, ac, ale, block, yminc, ymaxc, channel_index); } /* adjust y-position for next one */ y -= ACHANNEL_STEP; channel_index++; } uiEndBlock(C, block); uiDrawBlock(C, block); } /* free tempolary channels */ BLI_freelistN(&anim_data); }
void action_header_buttons(const bContext *C, ARegion *ar) { ScrArea *sa= CTX_wm_area(C); SpaceAction *saction= CTX_wm_space_action(C); bAnimContext ac; uiBlock *block; int xco, yco= 3, xmax; block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS); uiBlockSetHandleFunc(block, do_action_buttons, NULL); xco= ED_area_header_standardbuttons(C, block, yco); uiBlockSetEmboss(block, UI_EMBOSS); /* get context... (also syncs data) */ ANIM_animdata_get_context(C, &ac); if ((sa->flag & HEADER_NO_PULLDOWN)==0) { xmax= GetButStringLength("View"); uiDefMenuBut(block, act_viewmenu, NULL, "View", xco, yco, xmax-3, 20, ""); xco+= xmax; xmax= GetButStringLength("Select"); uiDefMenuBut(block, act_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, ""); xco+= xmax; if ( (saction->mode == SACTCONT_DOPESHEET) || ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) { xmax= GetButStringLength("Channel"); uiDefMenuBut(block, act_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, ""); xco+= xmax; } else if (saction->mode==SACTCONT_GPENCIL) { xmax= GetButStringLength("Channel"); uiDefMenuBut(block, act_gplayermenu, NULL, "Channel", xco, yco, xmax-3, 20, ""); xco+= xmax; } //xmax= GetButStringLength("Marker"); //uiDefMenuBut(block, act_markermenu, NULL, "Marker", xco, yco, xmax-3, 20, ""); //xco+= xmax; if (saction->mode == SACTCONT_GPENCIL) { //xmax= GetButStringLength("Frame"); //uiDefMenuBut(block, act_selectmenu, NULL, "Frame", xco, yco, xmax-3, 20, ""); //xco+= xmax; } else { xmax= GetButStringLength("Key"); uiDefMenuBut(block, act_editmenu, NULL, "Key", xco, yco, xmax-3, 20, ""); xco+= xmax; } } uiBlockSetEmboss(block, UI_EMBOSS); /* MODE SELECTOR */ uiDefButC(block, MENU, B_MODECHANGE, "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, "Editing modes for this editor"); xco += (90 + 8); /* SUMMARY CHANNEL */ uiDefIconTextButBitI(block, TOG, ADS_FILTER_SUMMARY, B_REDR, ICON_BORDERMOVE, "Summary", xco,yco,XIC*4,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Include DopeSheet summary row"); // TODO: needs a better icon xco += (XIC*4.5); /*if (ac.data)*/ { /* MODE-DEPENDENT DRAWING */ if (saction->mode == SACTCONT_DOPESHEET) { /* FILTERING OPTIONS */ xco -= XIC; // XXX first button incurs this offset... xco= ANIM_headerUI_standard_buttons(C, &saction->ads, block, xco, yco); } else if (saction->mode == SACTCONT_ACTION) { uiLayout *layout; bScreen *sc= CTX_wm_screen(C); PointerRNA ptr; RNA_pointer_create(&sc->id, &RNA_SpaceDopeSheetEditor, saction, &ptr); layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, 20+3, 20, 1, U.uistyles.first); uiTemplateID(layout, (bContext*)C, &ptr, "action", "ACT_OT_new", NULL, NULL); uiBlockLayoutResolve(block, &xco, NULL); xco += 8; } /* draw AUTOSNAP */ if (saction->mode != SACTCONT_GPENCIL) { if (saction->flag & SACTION_DRAWTIME) { uiDefButC(block, MENU, B_REDR, "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, "Auto-snapping mode for keyframes when transforming"); } else { uiDefButC(block, MENU, B_REDR, "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, "Auto-snapping mode for keyframes when transforming"); } xco += (90 + 8); } /* COPY PASTE */ uiBlockBeginAlign(block); uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer."); xco += XIC; uiDefIconButO(block, BUT, "ACT_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco,yco,XIC,YIC, "Pastes the keyframes from the buffer into the selected channels."); uiBlockEndAlign(block); xco += (XIC + 8); } /* always as last */ UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin)); uiEndBlock(C, block); uiDrawBlock(C, block); }