diff options
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 55 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_eyedropper.c | 240 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 156 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 19 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_panel.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 119 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 63 | ||||
-rw-r--r-- | source/blender/editors/interface/resources.c | 59 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 53 |
15 files changed, 506 insertions, 285 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 0b1d1c8c30c..8fa604d57cb 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -297,7 +297,7 @@ void ui_block_bounds_calc(uiBlock *block) /* hardcoded exception... but that one is annoying with larger safety */ bt = block->buttons.first; - if (bt && strncmp(bt->str, "ERROR", 5) == 0) xof = 10; + if (bt && STREQLEN(bt->str, "ERROR", 5)) xof = 10; else xof = 40; block->safety.xmin = block->rect.xmin - xof; diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index bcd9b9a5547..e03ea5efba4 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -450,6 +450,51 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w #endif } +/** + * Draw title and text safe areas. + * + * The first 4 parameters are the offsets for the view, not the zones. + */ +void UI_draw_safe_areas( + float x1, float x2, float y1, float y2, + const float title_aspect[2], const float action_aspect[2]) +{ + const float size_x_half = (x2 - x1) * 0.5f; + const float size_y_half = (y2 - y1) * 0.5f; + + const float *safe_areas[] = {title_aspect, action_aspect}; + int i, safe_len = ARRAY_SIZE(safe_areas); + bool is_first = true; + + for (i = 0; i < safe_len; i++) { + if (safe_areas[i][0] || safe_areas[i][1]) { + float margin_x, margin_y; + float minx, miny, maxx, maxy; + + if (is_first) { + UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25f, 0); + is_first = false; + } + + margin_x = safe_areas[i][0] * size_x_half; + margin_y = safe_areas[i][1] * size_y_half; + + minx = x1 + margin_x; + miny = y1 + margin_y; + maxx = x2 - margin_x; + maxy = y2 - margin_y; + + glBegin(GL_LINE_LOOP); + glVertex2f(maxx, miny); + glVertex2f(maxx, maxy); + glVertex2f(minx, maxy); + glVertex2f(minx, miny); + glEnd(); + } + } +} + + static void draw_scope_end(const rctf *rect, GLint *scissor) { /* restore scissortest */ @@ -494,7 +539,7 @@ static void histogram_draw_one(float r, float g, float b, float alpha, glColor4f(r, g, b, alpha); glShadeModel(GL_FLAT); - glBegin(GL_QUAD_STRIP); + glBegin(GL_TRIANGLE_STRIP); glVertex2f(x, y); glVertex2f(x, y + (data[0] * h)); for (i = 1; i < res; i++) { @@ -777,8 +822,8 @@ static void vectorscope_draw_target(float centerx, float centery, float diam, co if (u > 0 && v >= 0) tangle = atanf(v / u); else if (u > 0 && v < 0) tangle = atanf(v / u) + 2.0f * (float)M_PI; else if (u < 0) tangle = atanf(v / u) + (float)M_PI; - else if (u == 0 && v > 0.0f) tangle = (float)M_PI / 2.0f; - else if (u == 0 && v < 0.0f) tangle = -(float)M_PI / 2.0f; + else if (u == 0 && v > 0.0f) tangle = M_PI_2; + else if (u == 0 && v < 0.0f) tangle = -M_PI_2; tampli = sqrtf(u * u + v * v); /* small target vary by 2.5 degree and 2.5 IRE unit */ @@ -1102,7 +1147,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti v1[1] = y1 + sizey_solid; v2[1] = rect->ymax; - glBegin(GL_QUAD_STRIP); + glBegin(GL_TRIANGLE_STRIP); for (a = 0; a <= sizex; a++) { pos = ((float)a) / sizex; do_colorband(coba, pos, colf); @@ -1121,7 +1166,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti v1[1] = y1; v2[1] = y1 + sizey_solid; - glBegin(GL_QUAD_STRIP); + glBegin(GL_TRIANGLE_STRIP); for (a = 0; a <= sizex; a++) { pos = ((float)a) / sizex; do_colorband(coba, pos, colf); diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index d7a4720d595..f5b24f49f98 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -73,10 +73,13 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, const char *name) { - int width; + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; wmWindow *win = CTX_wm_window(C); int x = win->eventstate->x; int y = win->eventstate->y; + const unsigned char fg[4] = {255, 255, 255, 255}; + const unsigned char bg[4] = {0, 0, 0, 50}; + if ((name[0] == '\0') || (BLI_rcti_isect_pt(&ar->winrct, x, y) == false)) @@ -84,19 +87,12 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c return; } - width = UI_fontstyle_string_width(name); x = x - ar->winrct.xmin; y = y - ar->winrct.ymin; - y += 20; - - glColor4ub(0, 0, 0, 50); - - UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA); - UI_draw_roundbox(x, y, x + width + 8, y + 15, 4); + y += U.widget_unit; - glColor4ub(255, 255, 255, 255); - UI_draw_string(x + 4, y + 4, name); + UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, fg, bg); } /** \} */ @@ -176,43 +172,42 @@ static void eyedropper_color_sample_fl(bContext *C, Eyedropper *UNUSED(eye), int /* we could use some clever */ wmWindow *win = CTX_wm_window(C); - ScrArea *sa; - for (sa = win->screen->areabase.first; sa; sa = sa->next) { - if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) { - if (sa->spacetype == SPACE_IMAGE) { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { - SpaceImage *sima = sa->spacedata.first; - int mval[2] = {mx - ar->winrct.xmin, - my - ar->winrct.ymin}; - - if (ED_space_image_color_sample(CTX_data_scene(C), sima, ar, mval, r_col)) { - return; - } + ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my); + + if (sa) { + if (sa->spacetype == SPACE_IMAGE) { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { + SpaceImage *sima = sa->spacedata.first; + int mval[2] = {mx - ar->winrct.xmin, + my - ar->winrct.ymin}; + + if (ED_space_image_color_sample(CTX_data_scene(C), sima, ar, mval, r_col)) { + return; } } - else if (sa->spacetype == SPACE_NODE) { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { - SpaceNode *snode = sa->spacedata.first; - int mval[2] = {mx - ar->winrct.xmin, - my - ar->winrct.ymin}; - - if (ED_space_node_color_sample(CTX_data_scene(C), snode, ar, mval, r_col)) { - return; - } + } + else if (sa->spacetype == SPACE_NODE) { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { + SpaceNode *snode = sa->spacedata.first; + int mval[2] = {mx - ar->winrct.xmin, + my - ar->winrct.ymin}; + + if (ED_space_node_color_sample(CTX_data_scene(C), snode, ar, mval, r_col)) { + return; } } - else if (sa->spacetype == SPACE_CLIP) { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { - SpaceClip *sc = sa->spacedata.first; - int mval[2] = {mx - ar->winrct.xmin, - my - ar->winrct.ymin}; - - if (ED_space_clip_color_sample(CTX_data_scene(C), sc, ar, mval, r_col)) { - return; - } + } + else if (sa->spacetype == SPACE_CLIP) { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { + SpaceClip *sc = sa->spacedata.first; + int mval[2] = {mx - ar->winrct.xmin, + my - ar->winrct.ymin}; + + if (ED_space_clip_color_sample(CTX_data_scene(C), sc, ar, mval, r_col)) { + return; } } } @@ -477,53 +472,49 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int /* we could use some clever */ wmWindow *win = CTX_wm_window(C); - ScrArea *sa; + ScrArea *sa = BKE_screen_find_area_xy(win->screen, -1, mx, my); ScrArea *area_prev = CTX_wm_area(C); ARegion *ar_prev = CTX_wm_region(C); ddr->name[0] = '\0'; - for (sa = win->screen->areabase.first; sa; sa = sa->next) { - if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) { - if (sa->spacetype == SPACE_VIEW3D) { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { - const int mval[2] = { - mx - ar->winrct.xmin, - my - ar->winrct.ymin}; - Base *base; - - CTX_wm_area_set(C, sa); - CTX_wm_region_set(C, ar); - - /* grr, always draw else we leave stale text */ - ED_region_tag_redraw(ar); - - base = ED_view3d_give_base_under_cursor(C, mval); - if (base) { - Object *ob = base->object; - ID *id = NULL; - if (ddr->idcode == ID_OB) { - id = (ID *)ob; - } - else if (ob->data) { - if (GS(((ID *)ob->data)->name) == ddr->idcode) { - id = (ID *)ob->data; - } - else { - BLI_snprintf(ddr->name, sizeof(ddr->name), "Incompatible, expected a %s", - ddr->idcode_name); - } + if (sa) { + if (sa->spacetype == SPACE_VIEW3D) { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { + const int mval[2] = { + mx - ar->winrct.xmin, + my - ar->winrct.ymin}; + Base *base; + + CTX_wm_area_set(C, sa); + CTX_wm_region_set(C, ar); + + /* grr, always draw else we leave stale text */ + ED_region_tag_redraw(ar); + + base = ED_view3d_give_base_under_cursor(C, mval); + if (base) { + Object *ob = base->object; + ID *id = NULL; + if (ddr->idcode == ID_OB) { + id = (ID *)ob; + } + else if (ob->data) { + if (GS(((ID *)ob->data)->name) == ddr->idcode) { + id = (ID *)ob->data; } - - if (id) { - BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s", - ddr->idcode_name, id->name + 2); - *r_id = id; + else { + BLI_snprintf(ddr->name, sizeof(ddr->name), "Incompatible, expected a %s", + ddr->idcode_name); } + } - break; + if (id) { + BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s", + ddr->idcode_name, id->name + 2); + *r_id = id; } } } @@ -760,7 +751,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, /* we could use some clever */ wmWindow *win = CTX_wm_window(C); - ScrArea *sa; + ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my); Scene *scene = win->screen->scene; UnitSettings *unit = &scene->unit; const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0; @@ -770,47 +761,44 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, ddr->name[0] = '\0'; - for (sa = win->screen->areabase.first; sa; sa = sa->next) { - if (BLI_rcti_isect_pt(&sa->totrct, mx, my)) { - if (sa->spacetype == SPACE_VIEW3D) { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { - View3D *v3d = sa->spacedata.first; - RegionView3D *rv3d = ar->regiondata; - /* weak, we could pass in some reference point */ - const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3]; - const int mval[2] = { - mx - ar->winrct.xmin, - my - ar->winrct.ymin}; - float co[3]; - - CTX_wm_area_set(C, sa); - CTX_wm_region_set(C, ar); - - /* grr, always draw else we leave stale text */ - ED_region_tag_redraw(ar); - - view3d_operator_needs_opengl(C); - - if (ED_view3d_autodist(scene, ar, v3d, mval, co, true, NULL)) { - const float mval_center_fl[2] = { - (float)ar->winx / 2, - (float)ar->winy / 2}; - float co_align[3]; - - /* quick way to get view-center aligned point */ - ED_view3d_win_to_3d(ar, co, mval_center_fl, co_align); - - *r_depth = len_v3v3(view_co, co_align); - - bUnit_AsString(ddr->name, sizeof(ddr->name), - (double)*r_depth, - 4, unit->system, B_UNIT_LENGTH, do_split, false); - } - else { - BLI_strncpy(ddr->name, "Nothing under cursor", sizeof(ddr->name)); - } - break; + if (sa) { + if (sa->spacetype == SPACE_VIEW3D) { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + if (ar && BLI_rcti_isect_pt(&ar->winrct, mx, my)) { + View3D *v3d = sa->spacedata.first; + RegionView3D *rv3d = ar->regiondata; + /* weak, we could pass in some reference point */ + const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3]; + const int mval[2] = { + mx - ar->winrct.xmin, + my - ar->winrct.ymin}; + float co[3]; + + CTX_wm_area_set(C, sa); + CTX_wm_region_set(C, ar); + + /* grr, always draw else we leave stale text */ + ED_region_tag_redraw(ar); + + view3d_operator_needs_opengl(C); + + if (ED_view3d_autodist(scene, ar, v3d, mval, co, true, NULL)) { + const float mval_center_fl[2] = { + (float)ar->winx / 2, + (float)ar->winy / 2}; + float co_align[3]; + + /* quick way to get view-center aligned point */ + ED_view3d_win_to_3d(ar, co, mval_center_fl, co_align); + + *r_depth = len_v3v3(view_co, co_align); + + bUnit_AsString(ddr->name, sizeof(ddr->name), + (double)*r_depth, + 4, unit->system, B_UNIT_LENGTH, do_split, false); + } + else { + BLI_strncpy(ddr->name, "Nothing under cursor", sizeof(ddr->name)); } } } @@ -830,8 +818,10 @@ static void depthdropper_depth_set(bContext *C, DepthDropper *ddr, const float d /* set sample from accumulated values */ static void depthdropper_depth_set_accum(bContext *C, DepthDropper *ddr) { - float depth; - depth = ddr->accum_depth * 1.0f / (float)ddr->accum_tot; + float depth = ddr->accum_depth; + if (ddr->accum_tot) { + depth /= (float)ddr->accum_tot; + } depthdropper_depth_set(C, ddr, depth); } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 98b065dabcf..96973194576 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -114,6 +114,7 @@ static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to); static void ui_but_link_add(bContext *C, uiBut *from, uiBut *to); static int ui_do_but_EXIT(bContext *C, uiBut *but, struct uiHandleButtonData *data, const wmEvent *event); +static bool ui_but_find_select_in_enum__cmp(const uiBut *but_a, const uiBut *but_b); #ifdef USE_KEYNAV_LIMIT static void ui_mouse_motion_keynav_init(struct uiKeyNavLock *keynav, const wmEvent *event); @@ -355,6 +356,12 @@ static enum eSnapType ui_event_to_snap(const wmEvent *event) return (event->ctrl) ? (event->shift) ? SNAP_ON_SMALL : SNAP_ON : SNAP_OFF; } +static bool ui_event_is_snap(const wmEvent *event) +{ + return (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY) || + ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)); +} + static void ui_color_snap_hue(const enum eSnapType snap, float *r_hue) { const float snap_increment = (snap == SNAP_ON_SMALL) ? 24 : 12; @@ -2749,7 +2756,7 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle case VKEY: case XKEY: case CKEY: - if (event->ctrl || event->oskey) { + if (IS_EVENT_MOD(event, ctrl, oskey)) { if (event->type == VKEY) changed = ui_textedit_copypaste(but, data, UI_TEXTEDIT_PASTE); else if (event->type == CKEY) @@ -2822,10 +2829,10 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle /* Ctrl + A: Select all */ #if defined(__APPLE__) /* OSX uses cmd-a systemwide, so add it */ - if ((event->oskey && !(event->alt || event->shift || event->ctrl)) || - (event->ctrl && !(event->alt || event->shift || event->oskey))) + if ((event->oskey && !IS_EVENT_MOD(event, shift, alt, ctrl)) || + (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey))) #else - if (event->ctrl && !(event->alt || event->shift || event->oskey)) + if (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey)) #endif { ui_textedit_move(but, data, STRCUR_DIR_PREV, @@ -2848,7 +2855,7 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle update = true; /* do live update for tab key */ } /* the hotkey here is not well defined, was G.qual so we check all */ - else if (event->shift || event->ctrl || event->alt || event->oskey) { + else if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { ui_textedit_prev_but(block, but, data); button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -3342,6 +3349,38 @@ static int ui_do_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data, cons button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } + else if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { + /* Support alt+wheel on expanded enum rows */ + if (but->type == UI_BTYPE_ROW) { + const int direction = (event->type == WHEELDOWNMOUSE) ? -1 : 1; + uiBut *but_select = ui_but_find_select_in_enum(but, direction); + if (but_select) { + uiBut *but_other = (direction == -1) ? but_select->next : but_select->prev; + if (but_other && ui_but_find_select_in_enum__cmp(but, but_other)) { + ARegion *ar = data->region; + + data->cancel = true; + button_activate_exit(C, but, data, false, false); + + /* Activate the text button. */ + button_activate_init(C, ar, but_other, BUTTON_ACTIVATE_OVER); + data = but_other->active; + if (data) { + ui_apply_but(C, but->block, but_other, but_other->active, true); + button_activate_exit(C, but_other, data, false, false); + + /* restore active button */ + button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); + } + else { + /* shouldn't happen */ + BLI_assert(0); + } + } + } + return WM_UI_HANDLER_BREAK; + } + } } return WM_UI_HANDLER_CONTINUE; } @@ -3706,7 +3745,7 @@ static int ui_do_but_NUM(bContext *C, uiBlock *block, uiBut *but, uiHandleButton click = 1; } } - else if (event->type == MOUSEMOVE) { + else if ((event->type == MOUSEMOVE) || ui_event_is_snap(event)) { const enum eSnapType snap = ui_event_to_snap(event); float fac; @@ -4003,7 +4042,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton click = 1; } } - else if (event->type == MOUSEMOVE) { + else if ((event->type == MOUSEMOVE) || ui_event_is_snap(event)) { #ifdef USE_DRAG_MULTINUM data->multi_data.drag_dir[0] += abs(data->draglastx - mx); data->multi_data.drag_dir[1] += abs(data->draglasty - my); @@ -4542,8 +4581,8 @@ static int ui_do_but_UNITVEC(bContext *C, uiBlock *block, uiBut *but, uiHandleBu } } else if (data->state == BUTTON_STATE_NUM_EDITING) { - if (event->type == MOUSEMOVE) { - if (mx != data->draglastx || my != data->draglasty) { + if ((event->type == MOUSEMOVE) || ui_event_is_snap(event)) { + if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); if (ui_numedit_but_UNITVEC(but, data, mx, my, snap)) ui_numedit_apply(C, block, but, data); @@ -4862,8 +4901,8 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu button_activate_state(C, but, BUTTON_STATE_EXIT); } } - else if (event->type == MOUSEMOVE) { - if (mx != data->draglastx || my != data->draglasty) { + else if ((event->type == MOUSEMOVE) || ui_event_is_snap(event)) { + if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->shift != 0)) @@ -5134,8 +5173,8 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle ui_but_hsv_set(but); /* converts to rgb */ ui_numedit_apply(C, block, but, data); } - else if (event->type == MOUSEMOVE) { - if (mx != data->draglastx || my != data->draglasty) { + else if ((event->type == MOUSEMOVE) || ui_event_is_snap(event)) { + if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { @@ -6254,7 +6293,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) { /* handle copy-paste */ - if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && (event->ctrl || event->oskey)) { + if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && + IS_EVENT_MOD(event, ctrl, oskey)) + { /* Specific handling for listrows, we try to find their overlapping tex button. */ if (but->type == UI_BTYPE_LISTROW) { uiBut *labelbut = ui_but_list_row_text_activate(C, but, data, event, BUTTON_ACTIVATE_OVER); @@ -6273,7 +6314,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * } /* handle eyedropper */ else if ((event->type == EKEY) && (event->val == KM_PRESS)) { - if (event->alt || event->shift || event->ctrl || event->oskey) { + if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { /* pass */ } else { @@ -6305,7 +6346,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * } /* handle keyframing */ else if ((event->type == IKEY) && - !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey) && + !IS_EVENT_MOD(event, ctrl, oskey) && (event->val == KM_PRESS)) { if (event->alt) { @@ -6326,7 +6367,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * } /* handle drivers */ else if ((event->type == DKEY) && - !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && + !IS_EVENT_MOD(event, shift, ctrl, oskey) && (event->val == KM_PRESS)) { if (event->alt) @@ -6340,7 +6381,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * } /* handle keyingsets */ else if ((event->type == KKEY) && - !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift) && + !IS_EVENT_MOD(event, shift, ctrl, oskey) && (event->val == KM_PRESS)) { if (event->alt) @@ -6353,7 +6394,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * return WM_UI_HANDLER_BREAK; } /* handle menu */ - else if (event->type == RIGHTMOUSE && event->val == KM_PRESS) { + else if ((event->type == RIGHTMOUSE) && + !IS_EVENT_MOD(event, shift, ctrl, alt, oskey) && + (event->val == KM_PRESS)) + { /* RMB has two options now */ if (ui_but_menu(C, but)) { return WM_UI_HANDLER_BREAK; @@ -6591,6 +6635,45 @@ static bool ui_but_isect_pie_seg(uiBlock *block, uiBut *but) return false; } +static bool ui_but_find_select_in_enum__cmp(const uiBut *but_a, const uiBut *but_b) +{ + return ((but_a->type == but_b->type) && + (but_a->alignnr == but_b->alignnr) && + (but_a->poin == but_b->poin) && + (but_a->rnapoin.type == but_b->rnapoin.type) && + (but_a->rnaprop == but_b->rnaprop)); +} + +/** + * Finds the pressed button in an aligned row (typically an expanded enum). + * + * \param direction Use when there may be multiple buttons pressed. + */ +uiBut *ui_but_find_select_in_enum(uiBut *but, int direction) +{ + uiBut *but_iter = but; + uiBut *but_found = NULL; + BLI_assert(ELEM(direction, -1, 1)); + + while ((but_iter->prev) && + ui_but_find_select_in_enum__cmp(but_iter->prev, but)) + { + but_iter = but_iter->prev; + } + + while (but_iter && ui_but_find_select_in_enum__cmp(but_iter, but)) { + if (but_iter->flag & UI_SELECT) { + but_found = but_iter; + if (direction == 1) { + break; + } + } + but_iter = but_iter->next; + } + + return but_found; +} + uiBut *ui_but_find_active_in_region(ARegion *ar) { uiBlock *block; @@ -8301,7 +8384,7 @@ static int ui_handle_menu_event( case WHEELDOWNMOUSE: case MOUSEPAN: /* arrowkeys: only handle for block_loop blocks */ - if (event->alt || event->shift || event->ctrl || event->oskey) { + if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { /* pass */ } else if (inside || (block->flag & UI_BLOCK_LOOP)) { @@ -8446,9 +8529,7 @@ static int ui_handle_menu_event( case ZKEY: { if ((event->val == KM_PRESS || event->val == KM_DBL_CLICK) && - (event->shift == 0) && - (event->ctrl == 0) && - (event->oskey == 0)) + !IS_EVENT_MOD(event, shift, ctrl, oskey)) { if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) break; @@ -8825,7 +8906,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle block->pie_data.duration_gesture = duration; } - if (len_sq < 1.0) { + if (len_sq < 1.0f) { uiBut *but = ui_but_find_active_in_region(menu->region); if (but) { @@ -8940,9 +9021,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle case ZKEY: { if ((event->val == KM_PRESS || event->val == KM_DBL_CLICK) && - (event->shift == 0) && - (event->ctrl == 0) && - (event->oskey == 0)) + !IS_EVENT_MOD(event, shift, ctrl, oskey)) { for (but = block->buttons.first; but; but = but->next) { if (but->menu_key == event->type) { @@ -9123,13 +9202,13 @@ static void ui_region_handler_remove(bContext *C, void *UNUSED(userdata)) ui_apply_but_funcs_after(C); } +/* handle buttons at the window level, modal, for example while + * number sliding, text editing, or when a menu block is open */ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSED(userdata)) { ARegion *ar; uiBut *but; - /* here we handle buttons at the window level, modal, for example - * while number sliding, text editing, or when a menu block is open */ ar = CTX_wm_menu(C); if (!ar) ar = CTX_wm_region(C); @@ -9137,13 +9216,32 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSE but = ui_but_find_active_in_region(ar); if (but) { + bScreen *screen = CTX_wm_screen(C); + ARegion *ar_temp; uiBut *but_other; uiHandleButtonData *data; + bool is_inside_menu = false; + + /* look for a popup menu containing the mouse */ + for (ar_temp = screen->regionbase.first; ar_temp; ar_temp = ar_temp->next) { + rcti rect = ar_temp->winrct; + + /* resize region rect to ignore shadow */ + BLI_rcti_resize(&rect, (BLI_rcti_size_x(&ar_temp->winrct) - UI_ThemeMenuShadowWidth() * 2), + (BLI_rcti_size_y(&ar_temp->winrct) - UI_ThemeMenuShadowWidth() * 2)); + if (BLI_rcti_isect_pt_v(&rect, &event->x)) { + BLI_assert(ar_temp->type->regionid == RGN_TYPE_TEMPORARY); + + is_inside_menu = true; + break; + } + } /* handle activated button events */ data = but->active; if ((data->state == BUTTON_STATE_MENU_OPEN) && + (is_inside_menu == false) && /* make sure mouse isn't inside another menu (see T43247) */ (but->type == UI_BTYPE_PULLDOWN) && (but_other = ui_but_find_mouse_over(ar, event)) && (but != but_other) && diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 54ba3d784d1..458e268170f 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -616,6 +616,7 @@ extern void ui_but_active_free(const struct bContext *C, uiBut *but); extern bool ui_but_is_active(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT; extern int ui_but_menu_direction(uiBut *but); extern void ui_but_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but, const bool restore); +extern uiBut *ui_but_find_select_in_enum(uiBut *but, int direction); extern uiBut *ui_but_find_active_in_region(struct ARegion *ar); bool ui_but_is_editable(const uiBut *but); bool ui_but_is_editable_as_text(const uiBut *but); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index f02c6a234a9..fb73b8ec34c 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -235,9 +235,10 @@ static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool variable = (ui_layout_vary_direction(layout) == UI_ITEM_VARY_X); if (variable) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; /* it may seem odd that the icon only adds (UI_UNIT_X / 4) * but taking margins into account its fine */ - return (UI_fontstyle_string_width(name) + + return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * ((compact ? 1.25f : 1.50f) + (icon ? 0.25f : 0.0f)))); } @@ -639,7 +640,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n if (name[0]) { /* XXX UI_fontstyle_string_width is not accurate */ #if 0 - labelw = UI_fontstyle_string_width(name); + labelw = UI_fontstyle_string_width(fstyle, name); CLAMP(labelw, w / 4, 3 * w / 4); #endif labelw = w / 3; @@ -1003,7 +1004,7 @@ void uiItemEnumO_value(uiLayout *layout, const char *name, int icon, const char PointerRNA ptr; PropertyRNA *prop; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); WM_operator_properties_create_ptr(&ptr, ot); @@ -1035,7 +1036,7 @@ void uiItemEnumO_string(uiLayout *layout, const char *name, int icon, const char int value; bool free; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); WM_operator_properties_create_ptr(&ptr, ot); @@ -1074,7 +1075,7 @@ void uiItemBooleanO(uiLayout *layout, const char *name, int icon, const char *op wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */ PointerRNA ptr; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); WM_operator_properties_create_ptr(&ptr, ot); RNA_boolean_set(&ptr, propname, value); @@ -1087,7 +1088,7 @@ void uiItemIntO(uiLayout *layout, const char *name, int icon, const char *opname wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */ PointerRNA ptr; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); WM_operator_properties_create_ptr(&ptr, ot); RNA_int_set(&ptr, propname, value); @@ -1100,7 +1101,7 @@ void uiItemFloatO(uiLayout *layout, const char *name, int icon, const char *opna wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */ PointerRNA ptr; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); WM_operator_properties_create_ptr(&ptr, ot); RNA_float_set(&ptr, propname, value); @@ -1113,7 +1114,7 @@ void uiItemStringO(uiLayout *layout, const char *name, int icon, const char *opn wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */ PointerRNA ptr; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); WM_operator_properties_create_ptr(&ptr, ot); RNA_string_set(&ptr, propname, value); @@ -1877,7 +1878,7 @@ void uiItemMenuEnumO(uiLayout *layout, bContext *C, const char *opname, const ch MenuItemLevel *lvl; uiBut *but; - UI_OPERATOR_ERROR_RET(ot, opname, return ); + UI_OPERATOR_ERROR_RET(ot, opname, return); if (!ot->srna) { ui_item_disabled(layout, opname); diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 074faaa86bc..19e389154e4 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -515,7 +515,7 @@ static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b) (but_a->rnaprop == but_b->rnaprop) && (but_a->optype == but_b->optype) && (but_a->unit_type == but_b->unit_type) && - (strncmp(but_a->drawstr, but_b->drawstr, UI_MAX_DRAW_STR) == 0)) + STREQLEN(but_a->drawstr, but_b->drawstr, UI_MAX_DRAW_STR)) { return true; } @@ -858,7 +858,7 @@ int UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(e void UI_drop_color_copy(wmDrag *drag, wmDropBox *drop) { - uiDragColorHandle *drag_info = (uiDragColorHandle *)drag->poin; + uiDragColorHandle *drag_info = drag->poin; RNA_float_set_array(drop->ptr, "color", drag_info->color); RNA_boolean_set(drop->ptr, "gamma", drag_info->gamma_corrected); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index e68c86353a3..d165e2719c5 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1490,7 +1490,7 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active) } BLF_enable(fontid, BLF_ROTATION); - BLF_rotation(fontid, M_PI / 2); + BLF_rotation(fontid, M_PI_2); //UI_fontstyle_set(&style->widget); ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f)); BLF_size(fontid, fstyle_points, U.dpi); @@ -1757,7 +1757,7 @@ int ui_handler_panel_region(bContext *C, const wmEvent *event, ARegion *ar) /* XXX hardcoded key warning */ if ((inside || inside_header) && event->val == KM_PRESS) { - if (event->type == AKEY && !ELEM(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift, event->alt)) { + if (event->type == AKEY && ((event->ctrl + event->oskey + event->shift + event->alt) == 0)) { if (pa->flag & PNL_CLOSEDY) { if ((block->rect.ymax <= my) && (block->rect.ymax + PNL_HEADER >= my)) diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 0ec59e4e4cd..b6a93c8306d 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1919,7 +1919,7 @@ static void ui_update_color_picker_buts_rgb(uiBlock *block, ColorPicker *cpicker ui_but_v3_set(bt, rgb); } - else if (strcmp(bt->str, "Hex: ") == 0) { + else if (STREQ(bt->str, "Hex: ")) { float rgb_gamma[3]; unsigned char rgb_gamma_uchar[3]; double intpart; @@ -2726,7 +2726,8 @@ static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handl static float ui_pie_menu_title_width(const char *name, int icon) { - return (UI_fontstyle_string_width(name) + + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f)))); } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 8b2ce90dcf5..2f46c0906ae 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -45,6 +45,7 @@ #include "BKE_global.h" +#include "BIF_gl.h" #include "BLF_api.h" #ifdef WITH_INTERNATIONAL @@ -147,8 +148,9 @@ static uiFont *uifont_to_blfont(int id) /* *************** draw ************************ */ -void UI_fontstyle_draw_ex(uiFontStyle *fs, const rcti *rect, const char *str, - size_t len, float *r_xofs, float *r_yofs) +void UI_fontstyle_draw_ex( + const uiFontStyle *fs, const rcti *rect, const char *str, + size_t len, float *r_xofs, float *r_yofs) { float height; int xofs = 0, yofs; @@ -194,15 +196,17 @@ void UI_fontstyle_draw_ex(uiFontStyle *fs, const rcti *rect, const char *str, *r_yofs = yofs; } -void UI_fontstyle_draw(uiFontStyle *fs, const rcti *rect, const char *str) +void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str) { float xofs, yofs; - UI_fontstyle_draw_ex(fs, rect, str, - BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); + + UI_fontstyle_draw_ex( + fs, rect, str, + BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); } /* drawn same as above, but at 90 degree angle */ -void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *str) +void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const char *str) { float height; int xofs, yofs; @@ -220,7 +224,7 @@ void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *st /* rotate counter-clockwise for now (assumes left-to-right language)*/ xofs += height; yofs = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) + 5; - angle = (float)M_PI / 2.0f; + angle = M_PI_2; /* translate rect to vertical */ txtrect.xmin = rect->xmin - BLI_rcti_size_y(rect); @@ -255,6 +259,66 @@ void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *st BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); } +/** + * Similar to #UI_fontstyle_draw + * but ignore alignment, shadow & no clipping rect. + * + * For drawing on-screen labels. + */ +void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str) +{ + if (fs->kerning == 1) + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); + + UI_fontstyle_set(fs); + BLF_position(fs->uifont_id, x, y, 0.0f); + BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + + if (fs->kerning == 1) + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); +} + +/** + * Same as #UI_fontstyle_draw but draw a colored backdrop. + */ +void UI_fontstyle_draw_simple_backdrop( + const uiFontStyle *fs, float x, float y, const char *str, + const unsigned char fg[4], const unsigned char bg[4]) +{ + if (fs->kerning == 1) + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); + + UI_fontstyle_set(fs); + + { + const float width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + const float height = BLF_height_max(fs->uifont_id); + const float decent = BLF_descender(fs->uifont_id); + const float margin = height / 4.0f; + + /* backdrop */ + glColor4ubv(bg); + + UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA); + UI_draw_roundbox( + x - margin, + (y + decent) - margin, + x + width + margin, + (y + decent) + height + margin, + margin); + + glColor4ubv(fg); + } + + + BLF_position(fs->uifont_id, x, y, 0.0f); + BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + + if (fs->kerning == 1) + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); +} + + /* ************** helpers ************************ */ /* XXX: read a style configure */ uiStyle *UI_style_get(void) @@ -291,41 +355,29 @@ uiStyle *UI_style_get_dpi(void) return &_style; } -/* temporarily, does widget font */ -int UI_fontstyle_string_width(const char *str) +int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str) { - uiStyle *style = UI_style_get(); - uiFontStyle *fstyle = &style->widget; int width; - if (fstyle->kerning == 1) /* for BLF_width */ - BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); + if (fs->kerning == 1) /* for BLF_width */ + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); - UI_fontstyle_set(fstyle); - width = BLF_width(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + UI_fontstyle_set(fs); + width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); - if (fstyle->kerning == 1) - BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); + if (fs->kerning == 1) + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); return width; } -/* temporarily, does widget font */ -void UI_draw_string(float x, float y, const char *str) +int UI_fontstyle_height_max(const uiFontStyle *fs) { - uiStyle *style = UI_style_get(); - - if (style->widget.kerning == 1) - BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); - - UI_fontstyle_set(&style->widget); - BLF_position(style->widget.uifont_id, x, y, 0.0f); - BLF_draw(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); - - if (style->widget.kerning == 1) - BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT); + UI_fontstyle_set(fs); + return BLF_height_max(fs->uifont_id); } + /* ************** init exit ************************ */ /* called on each startup.blend read */ @@ -398,11 +450,10 @@ void uiStyleInit(void) if (font->blf_id == -1) { font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } - else { - BLF_default_set(font->blf_id); - } } + BLF_default_set(font->blf_id); + if (font->blf_id == -1) { if (G.debug & G_DEBUG) printf("%s: error, no fonts available\n", __func__); @@ -453,7 +504,7 @@ void uiStyleInit(void) BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); } -void UI_fontstyle_set(uiFontStyle *fs) +void UI_fontstyle_set(const uiFontStyle *fs) { uiFont *font = uifont_to_blfont(fs->uifont_id); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 407843d663c..5ac991cbd94 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2862,7 +2862,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, co /* validate arguments */ /* Forbid default UI_UL_DEFAULT_CLASS_NAME list class without a custom list_id! */ - if (!strcmp(UI_UL_DEFAULT_CLASS_NAME, listtype_name) && !(list_id && list_id[0])) { + if (STREQ(UI_UL_DEFAULT_CLASS_NAME, listtype_name) && !(list_id && list_id[0])) { RNA_warning("template_list using default '%s' UIList class must provide a custom list_id", UI_UL_DEFAULT_CLASS_NAME); return; @@ -3570,8 +3570,7 @@ void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop); - uiItemL(layout, IFACE_("Input Color Space:"), ICON_NONE); - uiItemR(layout, &colorspace_settings_ptr, "name", 0, "", ICON_NONE); + uiItemR(layout, &colorspace_settings_ptr, "name", 0, IFACE_("Color Space"), ICON_NONE); } void uiTemplateColormanagedViewSettings(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr, const char *propname) diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 04a886ba2a8..9b22f8a1e7f 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -610,36 +610,36 @@ static void round_box_shade_col4_r(unsigned char r_col[4], const char col1[4], c r_col[3] = (faci * col1[3] + facm * col2[3]) >> 8; } -static void widget_verts_to_quad_strip(uiWidgetBase *wtb, const int totvert, float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]) +static void widget_verts_to_triangle_strip(uiWidgetBase *wtb, const int totvert, float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]) { int a; for (a = 0; a < totvert; a++) { - copy_v2_v2(quad_strip[a * 2], wtb->outer_v[a]); - copy_v2_v2(quad_strip[a * 2 + 1], wtb->inner_v[a]); + copy_v2_v2(triangle_strip[a * 2], wtb->outer_v[a]); + copy_v2_v2(triangle_strip[a * 2 + 1], wtb->inner_v[a]); } - copy_v2_v2(quad_strip[a * 2], wtb->outer_v[0]); - copy_v2_v2(quad_strip[a * 2 + 1], wtb->inner_v[0]); + copy_v2_v2(triangle_strip[a * 2], wtb->outer_v[0]); + copy_v2_v2(triangle_strip[a * 2 + 1], wtb->inner_v[0]); } -static void widget_verts_to_quad_strip_open(uiWidgetBase *wtb, const int totvert, float quad_strip[WIDGET_SIZE_MAX * 2][2]) +static void widget_verts_to_triangle_strip_open(uiWidgetBase *wtb, const int totvert, float triangle_strip[WIDGET_SIZE_MAX * 2][2]) { int a; for (a = 0; a < totvert; a++) { - quad_strip[a * 2][0] = wtb->outer_v[a][0]; - quad_strip[a * 2][1] = wtb->outer_v[a][1]; - quad_strip[a * 2 + 1][0] = wtb->outer_v[a][0]; - quad_strip[a * 2 + 1][1] = wtb->outer_v[a][1] - 1.0f; + triangle_strip[a * 2][0] = wtb->outer_v[a][0]; + triangle_strip[a * 2][1] = wtb->outer_v[a][1]; + triangle_strip[a * 2 + 1][0] = wtb->outer_v[a][0]; + triangle_strip[a * 2 + 1][1] = wtb->outer_v[a][1] - 1.0f; } } static void widgetbase_outline(uiWidgetBase *wtb) { - float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ - widget_verts_to_quad_strip(wtb, wtb->totvert, quad_strip); + float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ + widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip); glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, wtb->totvert * 2 + 2); + glVertexPointer(2, GL_FLOAT, 0, triangle_strip); + glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2); glDisableClientState(GL_VERTEX_ARRAY); } @@ -733,18 +733,18 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) /* for each AA step */ if (wtb->outline) { - float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ - float quad_strip_emboss[WIDGET_SIZE_MAX * 2][2]; /* only for emboss */ + float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ + float triangle_strip_emboss[WIDGET_SIZE_MAX * 2][2]; /* only for emboss */ const unsigned char tcol[4] = {wcol->outline[0], wcol->outline[1], wcol->outline[2], wcol->outline[3] / WIDGET_AA_JITTER}; - widget_verts_to_quad_strip(wtb, wtb->totvert, quad_strip); + widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip); if (wtb->emboss) { - widget_verts_to_quad_strip_open(wtb, wtb->halfwayvert, quad_strip_emboss); + widget_verts_to_triangle_strip_open(wtb, wtb->halfwayvert, triangle_strip_emboss); } glEnableClientState(GL_VERTEX_ARRAY); @@ -757,8 +757,8 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) /* outline */ glColor4ubv(tcol); - glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, wtb->totvert * 2 + 2); + glVertexPointer(2, GL_FLOAT, 0, triangle_strip); + glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2); /* emboss bottom shadow */ if (wtb->emboss) { @@ -766,8 +766,8 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) if (emboss[3]) { glColor4ubv(emboss); - glVertexPointer(2, GL_FLOAT, 0, quad_strip_emboss); - glDrawArrays(GL_QUAD_STRIP, 0, wtb->halfwayvert * 2); + glVertexPointer(2, GL_FLOAT, 0, triangle_strip_emboss); + glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->halfwayvert * 2); } } @@ -2098,7 +2098,7 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r rcti rect1 = *rect; float alphastep; int step, totvert; - float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]; + float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; const float radout = UI_ThemeMenuShadowWidth(); /* disabled shadow */ @@ -2126,10 +2126,10 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r glColor4f(0.0f, 0.0f, 0.0f, alphastep * (1.0f - expfac)); - widget_verts_to_quad_strip(&wtb, totvert, quad_strip); + widget_verts_to_triangle_strip(&wtb, totvert, triangle_strip); - glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, totvert * 2); /* add + 2 for getting a complete soft rect. Now it skips top edge to allow transparent menus */ + glVertexPointer(2, GL_FLOAT, 0, triangle_strip); + glDrawArrays(GL_TRIANGLE_STRIP, 0, totvert * 2); /* add + 2 for getting a complete soft rect. Now it skips top edge to allow transparent menus */ } glDisableClientState(GL_VERTEX_ARRAY); @@ -2210,7 +2210,7 @@ void ui_hsvcircle_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f; float ang, radius_t; - ang = 2.0f * (float)M_PI * hsv[0] + 0.5f * (float)M_PI; + ang = 2.0f * (float)M_PI * hsv[0] + (float)M_PI_2; if ((but->flag & UI_BUT_COLOR_CUBIC) && (U.color_picker_type == USER_CP_CIRCLE_HSV)) radius_t = (1.0f - pow3f(1.0f - hsv[1])); @@ -3007,11 +3007,8 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat float height = rect->ymax - rect->ymin; /* find color luminance and change it slightly */ float bw = rgb_to_bw(col); - - if (bw > 0.5) - bw -= 0.5; - else - bw += 0.5; + + bw += (bw < 0.5f) ? 0.5f : -0.5f; glColor4f(bw, bw, bw, 1.0); glBegin(GL_TRIANGLES); @@ -3947,7 +3944,7 @@ void ui_draw_pie_center(uiBlock *block) int subd = 40; float angle = atan2f(pie_dir[1], pie_dir[0]); - float range = (block->pie_data.flags & UI_PIE_DEGREES_RANGE_LARGE) ? ((float)M_PI / 2.0f) : ((float)M_PI / 4.0f); + float range = (block->pie_data.flags & UI_PIE_DEGREES_RANGE_LARGE) ? M_PI_2 : M_PI_4; glPushMatrix(); glTranslatef(cx, cy, 0.0f); diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index aa5b2570952..dab4b6a941c 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -682,6 +682,9 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo case TH_INFO_DEBUG_TEXT: cp = ts->info_debug_text; break; + case TH_V3D_CLIPPING_BORDER: + cp = ts->clipping_border_3d; + break; } } } @@ -951,6 +954,7 @@ void ui_theme_init_default(void) rgba_char_args_set(btheme->tv3d.gradients.high_gradient, 58, 58, 58, 255); btheme->tv3d.gradients.show_grad = false; + rgba_char_args_set(btheme->tv3d.clipping_border_3d, 50, 50, 50, 255); /* space buttons */ /* to have something initialized */ btheme->tbuts = btheme->tv3d; @@ -1574,7 +1578,7 @@ void init_userdef_do_versions(void) U.tb_rightmouse = 5; } if (U.mixbufsize == 0) U.mixbufsize = 2048; - if (strcmp(U.tempdir, "/") == 0) { + if (STREQ(U.tempdir, "/")) { BKE_tempdir_system_init(U.tempdir); } if (U.autokey_mode == 0) { @@ -1907,39 +1911,39 @@ void init_userdef_do_versions(void) wmKeyMap *km; for (km = U.user_keymaps.first; km; km = km->next) { - if (strcmp(km->idname, "Armature_Sketch") == 0) + if (STREQ(km->idname, "Armature_Sketch")) strcpy(km->idname, "Armature Sketch"); - else if (strcmp(km->idname, "View3D") == 0) + else if (STREQ(km->idname, "View3D")) strcpy(km->idname, "3D View"); - else if (strcmp(km->idname, "View3D Generic") == 0) + else if (STREQ(km->idname, "View3D Generic")) strcpy(km->idname, "3D View Generic"); - else if (strcmp(km->idname, "EditMesh") == 0) + else if (STREQ(km->idname, "EditMesh")) strcpy(km->idname, "Mesh"); - else if (strcmp(km->idname, "TimeLine") == 0) + else if (STREQ(km->idname, "TimeLine")) strcpy(km->idname, "Timeline"); - else if (strcmp(km->idname, "UVEdit") == 0) + else if (STREQ(km->idname, "UVEdit")) strcpy(km->idname, "UV Editor"); - else if (strcmp(km->idname, "Animation_Channels") == 0) + else if (STREQ(km->idname, "Animation_Channels")) strcpy(km->idname, "Animation Channels"); - else if (strcmp(km->idname, "GraphEdit Keys") == 0) + else if (STREQ(km->idname, "GraphEdit Keys")) strcpy(km->idname, "Graph Editor"); - else if (strcmp(km->idname, "GraphEdit Generic") == 0) + else if (STREQ(km->idname, "GraphEdit Generic")) strcpy(km->idname, "Graph Editor Generic"); - else if (strcmp(km->idname, "Action_Keys") == 0) + else if (STREQ(km->idname, "Action_Keys")) strcpy(km->idname, "Dopesheet"); - else if (strcmp(km->idname, "NLA Data") == 0) + else if (STREQ(km->idname, "NLA Data")) strcpy(km->idname, "NLA Editor"); - else if (strcmp(km->idname, "Node Generic") == 0) + else if (STREQ(km->idname, "Node Generic")) strcpy(km->idname, "Node Editor"); - else if (strcmp(km->idname, "Logic Generic") == 0) + else if (STREQ(km->idname, "Logic Generic")) strcpy(km->idname, "Logic Editor"); - else if (strcmp(km->idname, "File") == 0) + else if (STREQ(km->idname, "File")) strcpy(km->idname, "File Browser"); - else if (strcmp(km->idname, "FileMain") == 0) + else if (STREQ(km->idname, "FileMain")) strcpy(km->idname, "File Browser Main"); - else if (strcmp(km->idname, "FileButtons") == 0) + else if (STREQ(km->idname, "FileButtons")) strcpy(km->idname, "File Browser Buttons"); - else if (strcmp(km->idname, "Buttons Generic") == 0) + else if (STREQ(km->idname, "Buttons Generic")) strcpy(km->idname, "Property Editor"); } } @@ -2572,6 +2576,25 @@ void init_userdef_do_versions(void) } } + if (U.versionfile < 273 || (U.versionfile == 273 && U.subversionfile < 5)) { + bTheme *btheme; + for (btheme = U.themes.first; btheme; btheme = btheme->next) { + unsigned char *cp = (unsigned char *)btheme->tv3d.clipping_border_3d; + int c; + copy_v4_v4_char((char *)cp, btheme->tv3d.back); + c = cp[0] - 8; + CLAMP(c, 0, 255); + cp[0] = c; + c = cp[1] - 8; + CLAMP(c, 0, 255); + cp[1] = c; + c = cp[2] - 8; + CLAMP(c, 0, 255); + cp[2] = c; + cp[3] = 255; + } + } + if (U.pixelsize == 0.0f) U.pixelsize = 1.0f; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index de46d47e5a3..b4a120b2dea 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -371,7 +371,8 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, int resize, int mask_ float winx, winy; rctf *cur, *tot; - /* use mask as size of region that View2D resides in, as it takes into account scrollbars already */ + /* use mask as size of region that View2D resides in, as it takes into account + * scrollbars already - keep in sync with zoomx/zoomy in view_zoomstep_apply_ex! */ winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1); winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1); @@ -393,6 +394,7 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, int resize, int mask_ */ totwidth = BLI_rctf_size_x(tot); totheight = BLI_rctf_size_y(tot); + /* keep in sync with zoomx/zoomy in view_zoomstep_apply_ex! */ curwidth = width = BLI_rctf_size_x(cur); curheight = height = BLI_rctf_size_y(cur); @@ -1851,7 +1853,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* draw vertical steps */ if (dfac > 0.0f) { - BLF_rotation_default(M_PI / 2); + BLF_rotation_default(M_PI_2); BLF_enable_default(BLF_ROTATION); for (; fac < vert.ymax - 10; fac += dfac, val += grid->dy) { diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 297d8d0f258..88140d897ae 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -625,6 +625,7 @@ static void view_zoomstep_apply_ex(bContext *C, v2dViewZoomData *vzd, const bool { ARegion *ar = CTX_wm_region(C); View2D *v2d = &ar->v2d; + const rctf cur_old = v2d->cur; float dx, dy; /* calculate amount to move view by, ensuring symmetry so the @@ -651,17 +652,23 @@ static void view_zoomstep_apply_ex(bContext *C, v2dViewZoomData *vzd, const bool v2d->cur.xmax -= 2 * dx; } else { + + v2d->cur.xmin += dx; + v2d->cur.xmax -= dx; + if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { - float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); - float mval_faci = 1.0f - mval_fac; - float ofs = (mval_fac * dx) - (mval_faci * dx); - - v2d->cur.xmin += ofs + dx; - v2d->cur.xmax += ofs - dx; - } - else { - v2d->cur.xmin += dx; - v2d->cur.xmax -= dx; + /* get zoom fac the same way as in ui_view2d_curRect_validate_resize - better keep in sync! */ + const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); + + /* only move view to mouse if zoom fac is inside minzoom/maxzoom */ + if (IN_RANGE_INCL(zoomx, v2d->minzoom, v2d->maxzoom)) { + float mval_fac = (vzd->mx_2d - cur_old.xmin) / BLI_rctf_size_x(&cur_old); + float mval_faci = 1.0f - mval_fac; + float ofs = (mval_fac * dx) - (mval_faci * dx); + + v2d->cur.xmin += ofs; + v2d->cur.xmax += ofs; + } } } } @@ -676,17 +683,23 @@ static void view_zoomstep_apply_ex(bContext *C, v2dViewZoomData *vzd, const bool v2d->cur.ymax -= 2 * dy; } else { + + v2d->cur.ymin += dy; + v2d->cur.ymax -= dy; + if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { - float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); - float mval_faci = 1.0f - mval_fac; - float ofs = (mval_fac * dy) - (mval_faci * dy); - - v2d->cur.ymin += ofs + dy; - v2d->cur.ymax += ofs - dy; - } - else { - v2d->cur.ymin += dy; - v2d->cur.ymax -= dy; + /* get zoom fac the same way as in ui_view2d_curRect_validate_resize - better keep in sync! */ + const float zoomy = (float)(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur); + + /* only move view to mouse if zoom fac is inside minzoom/maxzoom */ + if (IN_RANGE_INCL(zoomy, v2d->minzoom, v2d->maxzoom)) { + float mval_fac = (vzd->my_2d - cur_old.ymin) / BLI_rctf_size_y(&cur_old); + float mval_faci = 1.0f - mval_fac; + float ofs = (mval_fac * dy) - (mval_faci * dy); + + v2d->cur.ymin += ofs; + v2d->cur.ymax += ofs; + } } } } |