diff options
Diffstat (limited to 'source/blender/editors/animation/anim_markers.c')
-rw-r--r-- | source/blender/editors/animation/anim_markers.c | 217 |
1 files changed, 141 insertions, 76 deletions
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 2450d0740f2..e957e84857a 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -36,13 +36,14 @@ #include "DNA_object_types.h" #include "BLI_blenlib.h" -#include "BLI_math_base.h" +#include "BLI_math.h" #include "BLI_utildefines.h" #include "BLT_translation.h" #include "BKE_context.h" #include "BKE_fcurve.h" +#include "BKE_layer.h" #include "BKE_main.h" #include "BKE_report.h" #include "BKE_scene.h" @@ -56,9 +57,11 @@ #include "WM_api.h" #include "WM_types.h" -#include "BIF_gl.h" #include "BIF_glutil.h" +#include "GPU_immediate.h" +#include "GPU_matrix.h" + #include "UI_interface.h" #include "UI_interface_icons.h" #include "UI_view2d.h" @@ -73,6 +76,8 @@ #include "ED_transform.h" #include "ED_types.h" +#include "DEG_depsgraph.h" + /* ************* Marker API **************** */ /* helper function for getting the list of markers to work on */ @@ -332,6 +337,44 @@ void debug_markers_print_list(ListBase *markers) /* ************* Marker Drawing ************ */ +static void draw_marker_name( + const uiFontStyle *fstyle, TimeMarker *marker, const char *name, + int cfra, const float xpos, const float ypixels) +{ + unsigned char text_col[4]; + float x, y; + + /* minimal y coordinate which wouldn't be occluded by scroll */ + int min_y = 17.0f * UI_DPI_FAC; + + if (marker->flag & SELECT) { + UI_GetThemeColor4ubv(TH_TEXT_HI, text_col); + x = xpos + 4.0f * UI_DPI_FAC; + y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC; + y = max_ii(y, min_y); + } + else { + UI_GetThemeColor4ubv(TH_TEXT, text_col); + if ((marker->frame <= cfra) && (marker->frame + 5 > cfra)) { + x = xpos + 8.0f * UI_DPI_FAC; + y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC; + y = max_ii(y, min_y); + } + else { + x = xpos + 8.0f * UI_DPI_FAC; + y = 17.0f * UI_DPI_FAC; + } + } + +#ifdef DURIAN_CAMERA_SWITCH + if (marker->camera && (marker->camera->restrictflag & OB_RESTRICT_RENDER)) { + text_col[3] = 100; + } +#endif + + UI_fontstyle_draw_simple(fstyle, x, y, name, text_col); +} + /* function to draw markers */ static void draw_marker( View2D *v2d, const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int flag, @@ -339,10 +382,15 @@ static void draw_marker( const float ypixels, const float xscale, const float yscale) { const float xpos = marker->frame * xscale; +#ifdef DURIAN_CAMERA_SWITCH + const float yoffs = (marker->camera) ? 0.2f * UI_DPI_ICON_SIZE : 0.0f; +#else + const float yoffs = 0.0f; +#endif int icon_id; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); /* vertical line - dotted */ #ifdef DURIAN_CAMERA_SWITCH @@ -351,19 +399,30 @@ static void draw_marker( if (flag & DRAW_MARKERS_LINES) #endif { - setlinestyle(3); + Gwn_VertFormat *format = immVertexFormat(); + uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - if (marker->flag & SELECT) - glColor4ub(255, 255, 255, 96); - else - glColor4ub(0, 0, 0, 96); + if (marker->flag & SELECT) { + immUniformColor4f(1.0f, 1.0f, 1.0f, 0.38f); + } + else { + immUniformColor4f(0.0f, 0.0f, 0.0f, 0.38f); + } + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_factor", 0.5f); - glBegin(GL_LINES); - glVertex2f(xpos + 0.5f, 12.0f); - glVertex2f(xpos + 0.5f, (v2d->cur.ymax + 12.0f) * yscale); - glEnd(); + immBegin(GWN_PRIM_LINES, 2); + immVertex2f(pos, xpos + 0.5f, 12.0f); + immVertex2f(pos, xpos + 0.5f, (v2d->cur.ymax + 12.0f) * yscale); + immEnd(); - setlinestyle(0); + immUnbindProgram(); } /* 5 px to offset icon to align properly, space / pixels corrects for zoom */ @@ -372,52 +431,35 @@ static void draw_marker( (marker->flag & SELECT) ? ICON_PMARKER_SEL : ICON_PMARKER; } +#ifdef DURIAN_CAMERA_SWITCH + else if (marker->camera) { + icon_id = (marker->flag & SELECT) ? ICON_OUTLINER_OB_CAMERA : + ICON_OUTLINER_DATA_CAMERA; + } +#endif else { icon_id = (marker->flag & SELECT) ? ICON_MARKER_HLT : ICON_MARKER; } - UI_icon_draw(xpos - 0.45f * UI_DPI_ICON_SIZE, UI_DPI_ICON_SIZE, icon_id); + UI_icon_draw(xpos - 0.45f * UI_DPI_ICON_SIZE, yoffs + UI_DPI_ICON_SIZE, icon_id); glDisable(GL_BLEND); /* and the marker name too, shifted slightly to the top-right */ - if (marker->name[0]) { - float x, y; - - /* minimal y coordinate which wouldn't be occluded by scroll */ - int min_y = 17.0f * UI_DPI_FAC; - - if (marker->flag & SELECT) { - UI_ThemeColor(TH_TEXT_HI); - x = xpos + 4.0f * UI_DPI_FAC; - y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC; - y = max_ii(y, min_y); - } - else { - UI_ThemeColor(TH_TEXT); - if ((marker->frame <= cfra) && (marker->frame + 5 > cfra)) { - x = xpos + 8.0f * UI_DPI_FAC; - y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC; - y = max_ii(y, min_y); - } - else { - x = xpos + 8.0f * UI_DPI_FAC; - y = 17.0f * UI_DPI_FAC; - } - } - #ifdef DURIAN_CAMERA_SWITCH - if (marker->camera && (marker->camera->restrictflag & OB_RESTRICT_RENDER)) { - float col[4]; - glGetFloatv(GL_CURRENT_COLOR, col); - col[3] = 0.4; - glColor4fv(col); - } -#endif + if (marker->camera) { + draw_marker_name(fstyle, marker, marker->camera->id.name + 2, cfra, xpos, ypixels); + } + else if (marker->name[0]) { + draw_marker_name(fstyle, marker, marker->name, cfra, xpos, ypixels); + } +#else + if (marker->name[0]) { + draw_marker_name(fstyle, marker, marker->name, cfra, xpos, ypixels); - UI_fontstyle_draw_simple(fstyle, x, y, marker->name); } +#endif } /* Draw Scene-Markers in time window */ @@ -443,21 +485,27 @@ void ED_markers_draw(const bContext *C, int flag) v2d = UI_view2d_fromcontext(C); if (flag & DRAW_MARKERS_MARGIN) { + unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + const unsigned char shade[4] = {0, 0, 0, 16}; - glColor4ubv(shade); + immUniformColor4ubv(shade); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - glRectf(v2d->cur.xmin, 0, v2d->cur.xmax, UI_MARKER_MARGIN_Y); + immRectf(pos, v2d->cur.xmin, 0, v2d->cur.xmax, UI_MARKER_MARGIN_Y); glDisable(GL_BLEND); + + immUnbindProgram(); } /* no time correction for framelen! space is drawn with old values */ ypixels = BLI_rcti_size_y(&v2d->mask); UI_view2d_scale_get(v2d, &xscale, &yscale); - glScalef(1.0f / xscale, 1.0f, 1.0f); + gpuPushMatrix(); + gpuScale2f(1.0f / xscale, 1.0f); /* x-bounds with offset for text (adjust for long string, avoid checking string width) */ font_width_max = (10 * UI_DPI_FAC) / xscale; @@ -480,7 +528,7 @@ void ED_markers_draw(const bContext *C, int flag) } } - glScalef(xscale, 1.0f, 1.0f); + gpuPopMatrix(); } /* ************************ Marker Wrappers API ********************* */ @@ -552,7 +600,6 @@ static int ed_markers_poll_markers_exist(bContext *C) static int ed_markers_opwrap_invoke_custom(bContext *C, wmOperator *op, const wmEvent *event, int (*invoke_func)(bContext *, wmOperator *, const wmEvent *)) { - ScrArea *sa = CTX_wm_area(C); int retval = OPERATOR_PASS_THROUGH; /* removed check for Y coord of event, keymap has bounbox now */ @@ -565,12 +612,10 @@ static int ed_markers_opwrap_invoke_custom(bContext *C, wmOperator *op, const wm else BKE_report(op->reports, RPT_ERROR, "Programming error: operator does not actually have code to do anything!"); - /* return status modifications - for now, make this spacetype dependent as above */ - if (sa->spacetype != SPACE_TIME) { - /* unless successful, must add "pass-through" to let normal operator's have a chance at tackling this event */ - if ((retval & (OPERATOR_FINISHED | OPERATOR_INTERFACE)) == 0) { - retval |= OPERATOR_PASS_THROUGH; - } + + /* unless successful, must add "pass-through" to let normal operator's have a chance at tackling this event */ + if ((retval & (OPERATOR_FINISHED | OPERATOR_INTERFACE)) == 0) { + retval |= OPERATOR_PASS_THROUGH; } return retval; @@ -672,8 +717,7 @@ typedef struct MarkerMove { static bool ed_marker_move_use_time(MarkerMove *mm) { - if (((mm->slink->spacetype == SPACE_TIME) && !(((SpaceTime *)mm->slink)->flag & TIME_DRAWFRAMES)) || - ((mm->slink->spacetype == SPACE_SEQ) && !(((SpaceSeq *)mm->slink)->flag & SEQ_DRAWFRAMES)) || + if (((mm->slink->spacetype == SPACE_SEQ) && !(((SpaceSeq *)mm->slink)->flag & SEQ_DRAWFRAMES)) || ((mm->slink->spacetype == SPACE_ACTION) && (((SpaceAction *)mm->slink)->flag & SACTION_DRAWTIME)) || ((mm->slink->spacetype == SPACE_IPO) && !(((SpaceIpo *)mm->slink)->flag & SIPO_DRAWTIME)) || ((mm->slink->spacetype == SPACE_NLA) && !(((SpaceNla *)mm->slink)->flag & SNLA_DRAWTIME))) @@ -844,7 +888,7 @@ static void ed_marker_move_apply(bContext *C, wmOperator *op) BKE_scene_camera_switch_update(scene); if (camera != scene->camera) { - BKE_screen_view3d_scene_sync(sc); + BKE_screen_view3d_scene_sync(sc, scene); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene); } #endif @@ -917,10 +961,7 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *even mm->evtx = event->x; fac = ((float)(event->x - mm->firstx) * dx); - if (mm->slink->spacetype == SPACE_TIME) - apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0); - else - apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/); + apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/); RNA_int_set(op->ptr, "frames", (int)fac); ed_marker_move_apply(C, op); @@ -1129,12 +1170,13 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool if (camera) { Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Base *base; TimeMarker *marker; int sel = 0; if (!extend) - BKE_scene_base_deselect_all(scene); + BKE_view_layer_base_deselect_all(view_layer); for (marker = markers->first; marker; marker = marker->next) { if (marker->frame == cfra) { @@ -1146,16 +1188,17 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool for (marker = markers->first; marker; marker = marker->next) { if (marker->camera) { if (marker->frame == cfra) { - base = BKE_scene_base_find(scene, marker->camera); + base = BKE_view_layer_base_find(view_layer, marker->camera); if (base) { - ED_base_object_select(base, sel); + ED_object_base_select(base, sel); if (sel) - ED_base_object_activate(C, base); + ED_object_base_activate(C, base); } } } } + DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE); WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } #else @@ -1517,7 +1560,7 @@ static void MARKER_OT_make_links_scene(wmOperatorType *ot) #ifdef DURIAN_CAMERA_SWITCH /* ******************************* camera bind marker ***************** */ -static int ed_marker_camera_bind_exec(bContext *C, wmOperator *UNUSED(op)) +static int ed_marker_camera_bind_exec(bContext *C, wmOperator *op) { bScreen *sc = CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); @@ -1525,15 +1568,37 @@ static int ed_marker_camera_bind_exec(bContext *C, wmOperator *UNUSED(op)) ListBase *markers = ED_context_get_markers(C); TimeMarker *marker; - marker = ED_markers_get_first_selected(markers); - if (marker == NULL) + /* Don't do anything if we don't have a camera selected */ + if (ob == NULL) { + BKE_report(op->reports, RPT_ERROR, "Select a camera to bind to a marker on this frame"); + return OPERATOR_CANCELLED; + } + + /* add new marker, unless we already have one on this frame, in which case, replace it */ + if (markers == NULL) return OPERATOR_CANCELLED; + marker = ED_markers_find_nearest_marker(markers, CFRA); + if ((marker == NULL) || (marker->frame != CFRA)) { + marker = MEM_callocN(sizeof(TimeMarker), "Camera TimeMarker"); + marker->flag = SELECT; + marker->frame = CFRA; + BLI_addtail(markers, marker); + + /* deselect all others, so that the user can then move it without problems */ + for (TimeMarker *m = markers->first; m; m = m->next) { + if (m != marker) { + m->flag &= ~SELECT; + } + } + } + + /* bind to the nominated camera (as set in operator props) */ marker->camera = ob; /* camera may have changes */ BKE_scene_camera_switch_update(scene); - BKE_screen_view3d_scene_sync(sc); + BKE_screen_view3d_scene_sync(sc, scene); WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL); @@ -1546,13 +1611,13 @@ static void MARKER_OT_camera_bind(wmOperatorType *ot) { /* identifiers */ ot->name = "Bind Camera to Markers"; - ot->description = "Bind the active camera to selected marker(s)"; + ot->description = "Bind the selected camera to a marker on the current frame"; ot->idname = "MARKER_OT_camera_bind"; /* api callbacks */ ot->exec = ed_marker_camera_bind_exec; ot->invoke = ed_markers_opwrap_invoke; - ot->poll = ed_markers_poll_selected_no_locked_markers; + ot->poll = ED_operator_animview_active; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; |