Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/animation/anim_markers.c
| Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | for (marker = markers->first; marker; marker = marker->next) { | ||||
| } | } | ||||
| } | } | ||||
| /* set the min/max values */ | /* set the min/max values */ | ||||
| *first = min; | *first = min; | ||||
| *last = max; | *last = max; | ||||
| } | } | ||||
| /* Function used in operator polls, checks whether the markers region is currently drawn in the | |||||
| * editor in which the operator is called. | |||||
JacquesLucke: End comments with `.`. | |||||
| */ | |||||
| static bool ED_operator_markers_region_active(bContext *C) | |||||
Not Done Inline ActionsName is a bit strange, suggest: ED_operator_marker_region_active similar to the existing ED_operator_animview_active. campbellbarton: Name is a bit strange, suggest:
`ED_operator_marker_region_active` similar to the existing… | |||||
| { | |||||
| ScrArea *sa = CTX_wm_area(C); | |||||
| switch (sa->spacetype) { | |||||
| case SPACE_ACTION: { | |||||
| SpaceAction *saction = CTX_wm_space_action(C); | |||||
| if (saction->flag & SACTION_SHOW_MARKERS) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
Done Inline ActionsJust return instead of using a variable. JacquesLucke: Just return instead of using a variable. | |||||
| } | |||||
| case SPACE_GRAPH: { | |||||
| SpaceGraph *sipo = CTX_wm_space_graph(C); | |||||
| if (sipo->mode != SIPO_MODE_DRIVERS && sipo->flag & SIPO_SHOW_MARKERS) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
| } | |||||
| case SPACE_NLA: { | |||||
| SpaceNla *snla = CTX_wm_space_nla(C); | |||||
| if (snla->flag & SNLA_SHOW_MARKERS) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
| } | |||||
| case SPACE_SEQ: { | |||||
| SpaceSeq *seq = CTX_wm_space_seq(C); | |||||
| if (seq->flag & SEQ_SHOW_MARKERS) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
| } | |||||
| } | |||||
campbellbartonUnsubmitted Not Done Inline ActionsNo need to call functions to get spacedata, sa->spacedata.first gives direct access. campbellbarton: No need to call functions to get spacedata, `sa->spacedata.first` gives direct access. | |||||
| return false; | |||||
| } | |||||
| static bool region_position_is_over_marker(View2D *v2d, ListBase *markers, float region_x) | static bool region_position_is_over_marker(View2D *v2d, ListBase *markers, float region_x) | ||||
| { | { | ||||
| if (markers == NULL || BLI_listbase_is_empty(markers)) { | if (markers == NULL || BLI_listbase_is_empty(markers)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| float frame_at_position = UI_view2d_region_to_view_x(v2d, region_x); | float frame_at_position = UI_view2d_region_to_view_x(v2d, region_x); | ||||
| TimeMarker *nearest_marker = ED_markers_find_nearest_marker(markers, frame_at_position); | TimeMarker *nearest_marker = ED_markers_find_nearest_marker(markers, frame_at_position); | ||||
| ▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | if (marker->camera) { | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| int name_x = marker_x + UI_DPI_ICON_SIZE * 0.6; | int name_x = marker_x + UI_DPI_ICON_SIZE * 0.6; | ||||
| UI_fontstyle_draw_simple(fstyle, name_x, text_y, name, text_color); | UI_fontstyle_draw_simple(fstyle, name_x, text_y, name, text_color); | ||||
| } | } | ||||
| static void draw_marker_line(const float color[4], float x, float ymin, float ymax) | |||||
| { | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); | |||||
| float viewport_size[4]; | |||||
| GPU_viewport_size_get_f(viewport_size); | |||||
| immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); | |||||
| immUniformColor4fv(color); | |||||
| immUniform1i("colors_len", 0); /* "simple" mode */ | |||||
| immUniform1f("dash_width", 6.0f); | |||||
| immUniform1f("dash_factor", 0.5f); | |||||
| immBegin(GPU_PRIM_LINES, 2); | |||||
| immVertex2f(pos, x, ymin); | |||||
| immVertex2f(pos, x, ymax); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| static int marker_get_icon_id(TimeMarker *marker, int flag) | static int marker_get_icon_id(TimeMarker *marker, int flag) | ||||
| { | { | ||||
| if (flag & DRAW_MARKERS_LOCAL) { | if (flag & DRAW_MARKERS_LOCAL) { | ||||
| return (marker->flag & ACTIVE) ? ICON_PMARKER_ACT : | return (marker->flag & ACTIVE) ? ICON_PMARKER_ACT : | ||||
| (marker->flag & SELECT) ? ICON_PMARKER_SEL : ICON_PMARKER; | (marker->flag & SELECT) ? ICON_PMARKER_SEL : ICON_PMARKER; | ||||
| } | } | ||||
| #ifdef DURIAN_CAMERA_SWITCH | #ifdef DURIAN_CAMERA_SWITCH | ||||
| else if (marker->camera) { | else if (marker->camera) { | ||||
| return (marker->flag & SELECT) ? ICON_OUTLINER_OB_CAMERA : ICON_CAMERA_DATA; | return (marker->flag & SELECT) ? ICON_OUTLINER_OB_CAMERA : ICON_CAMERA_DATA; | ||||
| } | } | ||||
| #endif | #endif | ||||
| else { | else { | ||||
| return (marker->flag & SELECT) ? ICON_MARKER_HLT : ICON_MARKER; | return (marker->flag & SELECT) ? ICON_MARKER_HLT : ICON_MARKER; | ||||
| } | } | ||||
| } | } | ||||
| static void draw_marker_line_if_necessary(TimeMarker *marker, int flag, int xpos, int height) | static void draw_marker_line(TimeMarker *marker, int xpos, int height) | ||||
| { | |||||
| #ifdef DURIAN_CAMERA_SWITCH | |||||
| if ((marker->camera) || (flag & DRAW_MARKERS_LINES)) | |||||
| #else | |||||
| if (flag & DRAW_MARKERS_LINES) | |||||
| #endif | |||||
| { | { | ||||
| float color[4]; | float color[4]; | ||||
| if (marker->flag & SELECT) { | if (marker->flag & SELECT) { | ||||
| copy_v4_fl4(color, 1.0f, 1.0f, 1.0f, 0.38f); | copy_v4_fl4(color, 1.0f, 1.0f, 1.0f, 0.38f); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v4_fl4(color, 0.0f, 0.0f, 0.0f, 0.38f); | copy_v4_fl4(color, 0.0f, 0.0f, 0.0f, 0.38f); | ||||
| } | } | ||||
| draw_marker_line(color, xpos, UI_DPI_FAC * 20, height); | GPUVertFormat *format = immVertexFormat(); | ||||
| } | uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); | |||||
| float viewport_size[4]; | |||||
| GPU_viewport_size_get_f(viewport_size); | |||||
| immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); | |||||
| immUniformColor4fv(color); | |||||
| immUniform1i("colors_len", 0); /* "simple" mode */ | |||||
| immUniform1f("dash_width", 6.0f); | |||||
| immUniform1f("dash_factor", 0.5f); | |||||
| immBegin(GPU_PRIM_LINES, 2); | |||||
| immVertex2f(pos, xpos, UI_DPI_FAC * 20); | |||||
| immVertex2f(pos, xpos, height); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | } | ||||
| static void draw_marker( | static void draw_marker( | ||||
| const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int xpos, int flag, int region_height) | const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int xpos, int flag, int region_height) | ||||
| { | { | ||||
| GPU_blend(true); | GPU_blend(true); | ||||
| GPU_blend_set_func_separate( | GPU_blend_set_func_separate( | ||||
| GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); | GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); | ||||
| draw_marker_line_if_necessary(marker, flag, xpos, region_height); | draw_marker_line(marker, xpos, region_height); | ||||
| int icon_id = marker_get_icon_id(marker, flag); | int icon_id = marker_get_icon_id(marker, flag); | ||||
| UI_icon_draw(xpos - 0.55f * UI_DPI_ICON_SIZE, UI_DPI_FAC * 18, icon_id); | UI_icon_draw(xpos - 0.55f * UI_DPI_ICON_SIZE, UI_DPI_FAC * 18, icon_id); | ||||
| GPU_blend(false); | GPU_blend(false); | ||||
| float name_y = UI_DPI_FAC * 18; | float name_y = UI_DPI_FAC * 18; | ||||
| /* Give an offset to the marker name when selected, | /* Give an offset to the marker name when selected, | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------ */ | /* ------------------------ */ | ||||
| /* special poll() which checks if there are selected markers first */ | /* special poll() which checks if there are selected markers first */ | ||||
| static bool ed_markers_poll_selected_markers(bContext *C) | static bool ed_markers_poll_selected_markers(bContext *C) | ||||
| { | { | ||||
| ListBase *markers = ED_context_get_markers(C); | ListBase *markers = ED_context_get_markers(C); | ||||
| /* first things first: markers can only exist in timeline views */ | if (!ED_operator_markers_region_active(C)) { | ||||
| if (ED_operator_animview_active(C) == 0) { | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* check if some marker is selected */ | /* check if some marker is selected */ | ||||
| return ED_markers_get_first_selected(markers) != NULL; | return ED_markers_get_first_selected(markers) != NULL; | ||||
| } | } | ||||
| static bool ed_markers_poll_selected_no_locked_markers(bContext *C) | static bool ed_markers_poll_selected_no_locked_markers(bContext *C) | ||||
| { | { | ||||
| ListBase *markers = ED_context_get_markers(C); | ListBase *markers = ED_context_get_markers(C); | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| if (ts->lock_markers) { | if (ts->lock_markers || !ED_operator_markers_region_active(C)) { | ||||
| return 0; | |||||
| } | |||||
| /* first things first: markers can only exist in timeline views */ | |||||
| if (ED_operator_animview_active(C) == 0) { | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* check if some marker is selected */ | /* check if some marker is selected */ | ||||
| return ED_markers_get_first_selected(markers) != NULL; | return ED_markers_get_first_selected(markers) != NULL; | ||||
| } | } | ||||
| /* special poll() which checks if there are any markers at all first */ | /* special poll() which checks if there are any markers at all first */ | ||||
| static bool ed_markers_poll_markers_exist(bContext *C) | static bool ed_markers_poll_markers_exist(bContext *C) | ||||
| { | { | ||||
| ListBase *markers = ED_context_get_markers(C); | ListBase *markers = ED_context_get_markers(C); | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| if (ts->lock_markers) { | if (ts->lock_markers || !ED_operator_markers_region_active(C)) { | ||||
| return 0; | |||||
| } | |||||
| /* first things first: markers can only exist in timeline views */ | |||||
| if (ED_operator_animview_active(C) == 0) { | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* list of markers must exist, as well as some markers in it! */ | /* list of markers must exist, as well as some markers in it! */ | ||||
| return (markers && markers->first); | return (markers && markers->first); | ||||
| } | } | ||||
| /* ************************** add markers *************************** */ | /* ************************** add markers *************************** */ | ||||
| Show All 38 Lines | |||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add Time Marker"; | ot->name = "Add Time Marker"; | ||||
| ot->description = "Add a new time marker"; | ot->description = "Add a new time marker"; | ||||
| ot->idname = "MARKER_OT_add"; | ot->idname = "MARKER_OT_add"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = ed_marker_add_exec; | ot->exec = ed_marker_add_exec; | ||||
| ot->poll = ED_operator_animview_active; | ot->poll = ED_operator_markers_region_active; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /* ************************** transform markers *************************** */ | /* ************************** transform markers *************************** */ | ||||
| /* operator state vars used: | /* operator state vars used: | ||||
| ▲ Show 20 Lines • Show All 952 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Bind Camera to Markers"; | ot->name = "Bind Camera to Markers"; | ||||
| ot->description = "Bind the selected camera to a marker on the current frame"; | ot->description = "Bind the selected camera to a marker on the current frame"; | ||||
| ot->idname = "MARKER_OT_camera_bind"; | ot->idname = "MARKER_OT_camera_bind"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = ed_marker_camera_bind_exec; | ot->exec = ed_marker_camera_bind_exec; | ||||
| ot->poll = ED_operator_animview_active; | ot->poll = ED_operator_markers_region_active; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* ************************** registration **********************************/ | /* ************************** registration **********************************/ | ||||
| Show All 22 Lines | |||||
End comments with ..