Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_panel.c
| Show First 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* XXX Disabled paneltab handling for now. Old 2.4x feature, *DO NOT* confuse it with new tool tabs in 2.70. ;) | /* XXX Disabled paneltab handling for now. Old 2.4x feature, *DO NOT* confuse it with new tool tabs in 2.70. ;) | ||||
| * See also T41704. | * See also T41704. | ||||
| */ | */ | ||||
| /* #define UI_USE_PANELTAB */ | /* #define UI_USE_PANELTAB */ | ||||
| Panel *uiPanelFindByType(ARegion *ar, PanelType *pt) | Panel *UI_panel_find_by_type(ARegion *ar, PanelType *pt) | ||||
| { | { | ||||
| Panel *pa; | Panel *pa; | ||||
| const char *idname = pt->idname; | const char *idname = pt->idname; | ||||
| #ifdef UI_USE_PANELTAB | #ifdef UI_USE_PANELTAB | ||||
| const char *tabname = pt->idname; | const char *tabname = pt->idname; | ||||
| for (pa = ar->panels.first; pa; pa = pa->next) { | for (pa = ar->panels.first; pa; pa = pa->next) { | ||||
| if (STREQLEN(pa->panelname, idname, sizeof(pa->panelname))) { | if (STREQLEN(pa->panelname, idname, sizeof(pa->panelname))) { | ||||
| Show All 9 Lines | for (pa = ar->panels.first; pa; pa = pa->next) { | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * \note \a pa should be return value from #uiPanelFindByType and can be NULL. | * \note \a pa should be return value from #UI_panel_find_by_type and can be NULL. | ||||
| */ | */ | ||||
| Panel *uiBeginPanel(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, Panel *pa, bool *r_open) | Panel *UI_panel_begin(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, Panel *pa, bool *r_open) | ||||
| { | { | ||||
| Panel *palast, *panext; | Panel *palast, *panext; | ||||
| const char *drawname = CTX_IFACE_(pt->translation_context, pt->label); | const char *drawname = CTX_IFACE_(pt->translation_context, pt->label); | ||||
| const char *idname = pt->idname; | const char *idname = pt->idname; | ||||
| #ifdef UI_USE_PANELTAB | #ifdef UI_USE_PANELTAB | ||||
| const char *tabname = pt->idname; | const char *tabname = pt->idname; | ||||
| const char *hookname = NULL; | const char *hookname = NULL; | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | #endif | ||||
| if (pa->paneltab) return pa; | if (pa->paneltab) return pa; | ||||
| if (pa->flag & PNL_CLOSED) return pa; | if (pa->flag & PNL_CLOSED) return pa; | ||||
| *r_open = true; | *r_open = true; | ||||
| return pa; | return pa; | ||||
| } | } | ||||
| void uiEndPanel(uiBlock *block, int width, int height) | void UI_panel_end(uiBlock *block, int width, int height) | ||||
| { | { | ||||
| Panel *pa = block->panel; | Panel *pa = block->panel; | ||||
| if (pa->runtime_flag & PNL_NEW_ADDED) { | if (pa->runtime_flag & PNL_NEW_ADDED) { | ||||
| pa->runtime_flag &= ~PNL_NEW_ADDED; | pa->runtime_flag &= ~PNL_NEW_ADDED; | ||||
| pa->sizex = width; | pa->sizex = width; | ||||
| pa->sizey = height; | pa->sizey = height; | ||||
| } | } | ||||
| Show All 10 Lines | if (width != 0) | ||||
| pa->sizex = width; | pa->sizex = width; | ||||
| if (height != 0) | if (height != 0) | ||||
| pa->sizey = height; | pa->sizey = height; | ||||
| } | } | ||||
| } | } | ||||
| static void ui_offset_panel_block(uiBlock *block) | static void ui_offset_panel_block(uiBlock *block) | ||||
| { | { | ||||
| uiStyle *style = UI_GetStyleDraw(); | uiStyle *style = UI_style_get_dpi(); | ||||
| uiBut *but; | uiBut *but; | ||||
| int ofsy; | int ofsy; | ||||
| /* compute bounds and offset */ | /* compute bounds and offset */ | ||||
| ui_bounds_block(block); | ui_block_bounds_calc(block); | ||||
| ofsy = block->panel->sizey - style->panelspace; | ofsy = block->panel->sizey - style->panelspace; | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| but->rect.ymin += ofsy; | but->rect.ymin += ofsy; | ||||
| but->rect.ymax += ofsy; | but->rect.ymax += ofsy; | ||||
| } | } | ||||
| Show All 16 Lines | |||||
| static void uiPanelPop(uiBlock *UNUSED(block)) | static void uiPanelPop(uiBlock *UNUSED(block)) | ||||
| { | { | ||||
| glPopMatrix(); | glPopMatrix(); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* triangle 'icon' for panel header */ | /* triangle 'icon' for panel header */ | ||||
| void UI_DrawTriIcon(float x, float y, char dir) | void UI_draw_icon_tri(float x, float y, char dir) | ||||
| { | { | ||||
| float f3 = 0.15 * U.widget_unit; | float f3 = 0.15 * U.widget_unit; | ||||
| float f5 = 0.25 * U.widget_unit; | float f5 = 0.25 * U.widget_unit; | ||||
| float f7 = 0.35 * U.widget_unit; | float f7 = 0.35 * U.widget_unit; | ||||
| if (dir == 'h') { | if (dir == 'h') { | ||||
| ui_draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y); | ui_draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | static void ui_draw_aligned_panel_header(uiStyle *style, uiBlock *block, const rcti *rect, char dir) | ||||
| /* active tab */ | /* active tab */ | ||||
| /* draw text label */ | /* draw text label */ | ||||
| UI_ThemeColor(TH_TITLE); | UI_ThemeColor(TH_TITLE); | ||||
| hrect = *rect; | hrect = *rect; | ||||
| if (dir == 'h') { | if (dir == 'h') { | ||||
| hrect.xmin = rect->xmin + pnl_icons; | hrect.xmin = rect->xmin + pnl_icons; | ||||
| hrect.ymin += 2.0f / block->aspect; | hrect.ymin += 2.0f / block->aspect; | ||||
| uiStyleFontDraw(&style->paneltitle, &hrect, activename); | UI_fontstyle_draw(&style->paneltitle, &hrect, activename); | ||||
| } | } | ||||
| else { | else { | ||||
| /* ignore 'pnl_icons', otherwise the text gets offset horizontally | /* ignore 'pnl_icons', otherwise the text gets offset horizontally | ||||
| * + 0.001f to avoid flirting with float inaccuracy | * + 0.001f to avoid flirting with float inaccuracy | ||||
| */ | */ | ||||
| hrect.xmin = rect->xmin + (PNL_ICON + 5) / block->aspect + 0.001f; | hrect.xmin = rect->xmin + (PNL_ICON + 5) / block->aspect + 0.001f; | ||||
| uiStyleFontDrawRotated(&style->paneltitle, &hrect, activename); | UI_fontstyle_draw_rotated(&style->paneltitle, &hrect, activename); | ||||
| } | } | ||||
| } | } | ||||
| /* panel integrated in buttonswindow, tool/property lists etc */ | /* panel integrated in buttonswindow, tool/property lists etc */ | ||||
| void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, const bool show_pin) | void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, const bool show_pin) | ||||
| { | { | ||||
| Panel *panel = block->panel; | Panel *panel = block->panel; | ||||
| rcti headrect; | rcti headrect; | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | #endif | ||||
| else if (panel->flag & PNL_CLOSEDX) { | else if (panel->flag & PNL_CLOSEDX) { | ||||
| /* draw vertical title */ | /* draw vertical title */ | ||||
| ui_draw_aligned_panel_header(style, block, &headrect, 'v'); | ui_draw_aligned_panel_header(style, block, &headrect, 'v'); | ||||
| } | } | ||||
| /* an open panel */ | /* an open panel */ | ||||
| else { | else { | ||||
| /* in some occasions, draw a border */ | /* in some occasions, draw a border */ | ||||
| if (panel->flag & PNL_SELECT) { | if (panel->flag & PNL_SELECT) { | ||||
| if (panel->control & UI_PNL_SOLID) uiSetRoundBox(UI_CNR_ALL); | if (panel->control & UI_PNL_SOLID) UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| else uiSetRoundBox(UI_CNR_NONE); | else UI_draw_roundbox_corner_set(UI_CNR_NONE); | ||||
| UI_ThemeColorShade(TH_BACK, -120); | UI_ThemeColorShade(TH_BACK, -120); | ||||
| uiRoundRect(0.5f + rect->xmin, 0.5f + rect->ymin, 0.5f + rect->xmax, 0.5f + headrect.ymax + 1, 8); | UI_draw_roundbox_unfilled(0.5f + rect->xmin, 0.5f + rect->ymin, 0.5f + rect->xmax, 0.5f + headrect.ymax + 1, 8); | ||||
| } | } | ||||
| /* panel backdrop */ | /* panel backdrop */ | ||||
| if (UI_GetThemeValue(TH_PANEL_SHOW_BACK)) { | if (UI_GetThemeValue(TH_PANEL_SHOW_BACK)) { | ||||
| /* draw with background color */ | /* draw with background color */ | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| UI_ThemeColor4(TH_PANEL_BACK); | UI_ThemeColor4(TH_PANEL_BACK); | ||||
| glRecti(rect->xmin, rect->ymin, rect->xmax, rect->ymax); | glRecti(rect->xmin, rect->ymin, rect->xmax, rect->ymax); | ||||
| ▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | static void ui_do_animate(const bContext *C, Panel *panel) | ||||
| } | } | ||||
| if (fac >= 1.0f) { | if (fac >= 1.0f) { | ||||
| panel_activate_state(C, panel, PANEL_STATE_EXIT); | panel_activate_state(C, panel, PANEL_STATE_EXIT); | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| void uiBeginPanels(const bContext *UNUSED(C), ARegion *ar) | void UI_panels_begin(const bContext *UNUSED(C), ARegion *ar) | ||||
| { | { | ||||
| Panel *pa; | Panel *pa; | ||||
| /* set all panels as inactive, so that at the end we know | /* set all panels as inactive, so that at the end we know | ||||
| * which ones were used */ | * which ones were used */ | ||||
| for (pa = ar->panels.first; pa; pa = pa->next) { | for (pa = ar->panels.first; pa; pa = pa->next) { | ||||
| if (pa->runtime_flag & PNL_ACTIVE) | if (pa->runtime_flag & PNL_ACTIVE) | ||||
| pa->runtime_flag = PNL_WAS_ACTIVE; | pa->runtime_flag = PNL_WAS_ACTIVE; | ||||
| else | else | ||||
| pa->runtime_flag = 0; | pa->runtime_flag = 0; | ||||
| } | } | ||||
| } | } | ||||
| /* only draws blocks with panels */ | /* only draws blocks with panels */ | ||||
| void uiEndPanels(const bContext *C, ARegion *ar, int *x, int *y) | void UI_panels_end(const bContext *C, ARegion *ar, int *x, int *y) | ||||
| { | { | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| Panel *panot, *panew, *patest, *pa, *firstpa; | Panel *panot, *panew, *patest, *pa, *firstpa; | ||||
| /* offset contents */ | /* offset contents */ | ||||
| for (block = ar->uiblocks.first; block; block = block->next) | for (block = ar->uiblocks.first; block; block = block->next) | ||||
| if (block->active && block->panel) | if (block->active && block->panel) | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void UI_panels_end(const bContext *C, ARegion *ar, int *x, int *y) | ||||
| if (firstpa) | if (firstpa) | ||||
| firstpa->runtime_flag |= PNL_FIRST; | firstpa->runtime_flag |= PNL_FIRST; | ||||
| /* compute size taken up by panel */ | /* compute size taken up by panel */ | ||||
| ui_panels_size(sa, ar, x, y); | ui_panels_size(sa, ar, x, y); | ||||
| } | } | ||||
| void uiDrawPanels(const bContext *C, ARegion *ar) | void UI_panels_draw(const bContext *C, ARegion *ar) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| UI_ThemeClearColor(TH_BACK); | UI_ThemeClearColor(TH_BACK); | ||||
| /* draw panels, selected on top */ | /* draw panels, selected on top */ | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| if (block->active && block->panel && !(block->panel->flag & PNL_SELECT)) { | if (block->active && block->panel && !(block->panel->flag & PNL_SELECT)) { | ||||
| uiDrawBlock(C, block); | UI_block_draw(C, block); | ||||
| } | } | ||||
| } | } | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| if (block->active && block->panel && (block->panel->flag & PNL_SELECT)) { | if (block->active && block->panel && (block->panel->flag & PNL_SELECT)) { | ||||
| uiDrawBlock(C, block); | UI_block_draw(C, block); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void uiScalePanels(ARegion *ar, float new_width) | void UI_panels_scale(ARegion *ar, float new_width) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but; | uiBut *but; | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| if (block->panel) { | if (block->panel) { | ||||
| float fac = new_width / (float)block->panel->sizex; | float fac = new_width / (float)block->panel->sizex; | ||||
| printf("scaled %f\n", fac); | printf("scaled %f\n", fac); | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | void UI_panel_category_add(ARegion *ar, const char *name) | ||||
| /* 'pc_dyn->rect' must be set on draw */ | /* 'pc_dyn->rect' must be set on draw */ | ||||
| } | } | ||||
| void UI_panel_category_clear_all(ARegion *ar) | void UI_panel_category_clear_all(ARegion *ar) | ||||
| { | { | ||||
| BLI_freelistN(&ar->panels_category); | BLI_freelistN(&ar->panels_category); | ||||
| } | } | ||||
| /* based on uiDrawBox, check on making a version which allows us to skip some sides */ | /* based on UI_draw_roundbox_gl_mode, check on making a version which allows us to skip some sides */ | ||||
| static void ui_panel_category_draw_tab(int mode, float minx, float miny, float maxx, float maxy, float rad, | static void ui_panel_category_draw_tab(int mode, float minx, float miny, float maxx, float maxy, float rad, | ||||
| int roundboxtype, | int roundboxtype, | ||||
| const bool use_highlight, const bool use_shadow, | const bool use_highlight, const bool use_shadow, | ||||
| const unsigned char highlight_fade[3]) | const unsigned char highlight_fade[3]) | ||||
| { | { | ||||
| float vec[4][2] = { | float vec[4][2] = { | ||||
| {0.195, 0.02}, | {0.195, 0.02}, | ||||
| {0.55, 0.169}, | {0.55, 0.169}, | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| * Draw vertical tabs on the left side of the region, | * Draw vertical tabs on the left side of the region, | ||||
| * one tab per category. | * one tab per category. | ||||
| */ | */ | ||||
| void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active) | void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active) | ||||
| { | { | ||||
| /* no tab outlines for */ | /* no tab outlines for */ | ||||
| // #define USE_FLAT_INACTIVE | // #define USE_FLAT_INACTIVE | ||||
| View2D *v2d = &ar->v2d; | View2D *v2d = &ar->v2d; | ||||
| uiStyle *style = UI_GetStyle(); | uiStyle *style = UI_style_get(); | ||||
| const uiFontStyle *fstyle = &style->widget; | const uiFontStyle *fstyle = &style->widget; | ||||
| const int fontid = fstyle->uifont_id; | const int fontid = fstyle->uifont_id; | ||||
| short fstyle_points = fstyle->points; | short fstyle_points = fstyle->points; | ||||
| PanelCategoryDyn *pc_dyn; | PanelCategoryDyn *pc_dyn; | ||||
| const float aspect = ((uiBlock *)ar->uiblocks.first)->aspect; | const float aspect = ((uiBlock *)ar->uiblocks.first)->aspect; | ||||
| const float zoom = 1.0f / aspect; | const float zoom = 1.0f / aspect; | ||||
| const int px = max_ii(1, iroundf(U.pixelsize)); | const int px = max_ii(1, iroundf(U.pixelsize)); | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | #endif | ||||
| is_alpha = (ar->overlap && (theme_col_back[3] != 255)); | is_alpha = (ar->overlap && (theme_col_back[3] != 255)); | ||||
| if (fstyle->kerning == 1) { | if (fstyle->kerning == 1) { | ||||
| BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| BLF_enable(fontid, BLF_ROTATION); | BLF_enable(fontid, BLF_ROTATION); | ||||
| BLF_rotation(fontid, M_PI / 2); | BLF_rotation(fontid, M_PI / 2); | ||||
| //uiStyleFontSet(&style->widget); | //UI_fontstyle_set(&style->widget); | ||||
| ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f)); | ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f)); | ||||
| BLF_size(fontid, fstyle_points, U.dpi); | BLF_size(fontid, fstyle_points, U.dpi); | ||||
| BLF_enable(fontid, BLF_SHADOW); | BLF_enable(fontid, BLF_SHADOW); | ||||
| BLF_shadow(fontid, 3, 1.0f, 1.0f, 1.0f, 0.25f); | BLF_shadow(fontid, 3, 1.0f, 1.0f, 1.0f, 0.25f); | ||||
| BLF_shadow_offset(fontid, -1, -1); | BLF_shadow_offset(fontid, -1, -1); | ||||
| BLI_assert(UI_panel_category_is_visible(ar)); | BLI_assert(UI_panel_category_is_visible(ar)); | ||||
| ▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | if ((inside || inside_header) && event->val == KM_PRESS) { | ||||
| ui_handle_panel_header(C, block, mx, my, event->type, event->ctrl, event->shift); | ui_handle_panel_header(C, block, mx, my, event->type, event->ctrl, event->shift); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| /* on active button, do not handle panels */ | /* on active button, do not handle panels */ | ||||
| if (ui_button_is_active(ar)) | if (ui_but_is_active(ar)) | ||||
| continue; | continue; | ||||
| if (inside || inside_header) { | if (inside || inside_header) { | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| /* open close on header */ | /* open close on header */ | ||||
| if (ELEM(event->type, RETKEY, PADENTER)) { | if (ELEM(event->type, RETKEY, PADENTER)) { | ||||
| ▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines | |||||