[Bf-blender-cvs] [125ce644f28] blender2.8: cleanup

Mike Erwin noreply at git.blender.org
Tue Apr 4 21:41:33 CEST 2017


Commit: 125ce644f28dccea67ad5bdada0013eba8caafbe
Author: Mike Erwin
Date:   Tue Apr 4 15:39:38 2017 -0400
Branches: blender2.8
https://developer.blender.org/rB125ce644f28dccea67ad5bdada0013eba8caafbe

cleanup

I started cleaning up UI_view2d_scale_get where the y scale was unused, then got carried away...

- for loop scope
- declare variables closer to where they are used
- move early exits closer to function start
- unsigned --> unsigned int

===================================================================

M	source/blender/editors/animation/anim_draw.c
M	source/blender/editors/animation/anim_markers.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/space_clip/clip_utils.c
M	source/blender/editors/space_graph/graph_draw.c

===================================================================

diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index 5d357e2f93e..f448a281cfc 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -71,17 +71,12 @@
 /* Draw current frame number in a little green box beside the current frame indicator */
 static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time)
 {
-	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
-	VertexFormat *format = immVertexFormat();
-	unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
-	unsigned char col[4];
-	float xscale, yscale, x, y;
 	char numstr[32] = "    t";  /* t is the character to start replacing from */
-	int slen;
 	
 	/* because the frame number text is subject to the same scaling as the contents of the view */
+	float xscale;
+	UI_view2d_scale_get(v2d, &xscale, NULL);
 	gpuPushMatrix();
-	UI_view2d_scale_get(v2d, &xscale, &yscale);
 	gpuScale2f(1.0f / xscale, 1.0f);
 	
 	/* get timecode string 
@@ -96,11 +91,15 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
 		BLI_timecode_string_from_time_seconds(&numstr[4], sizeof(numstr) - 4, 1, cfra);
 	}
 
-	slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
+	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
+	int slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
 	
 	/* get starting coordinates for drawing */
-	x = cfra * xscale;
-	y = 0.9f * U.widget_unit;
+	float x = cfra * xscale;
+	float y = 0.9f * U.widget_unit;
+
+	VertexFormat *format = immVertexFormat();
+	unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
 
 	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
@@ -110,7 +109,8 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
 	immRectf(pos, x, y,  x + slen,  y + 0.75f * U.widget_unit);
 	immUnbindProgram();
 
-	/* draw current frame number - black text */
+	/* draw current frame number */
+	unsigned char col[4];
 	UI_GetThemeColor4ubv(TH_TEXT, col);
 	UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr, col);
 
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index 9d7d1535eb3..9b8dd47e4aa 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -131,8 +131,7 @@ ListBase *ED_animcontext_get_markers(const bAnimContext *ac)
  */
 int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, float value, char side)
 {
-	TimeMarker *marker;
-	float cfra = (float)CFRA;
+	const float cfra = (float)CFRA;
 	int changed_tot = 0;
 	
 	/* sanity check */
@@ -140,7 +139,7 @@ int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, f
 		return changed_tot;
 	
 	/* affect selected markers - it's unlikely that we will want to affect all in this way? */
-	for (marker = markers->first; marker; marker = marker->next) {
+	for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
 		if (marker->flag & SELECT) {
 			switch (mode) {
 				case TFM_TIME_TRANSLATE:
@@ -235,13 +234,12 @@ void ED_markers_get_minmax(ListBase *markers, short sel, float *first, float *la
 /* Adds a marker to list of cfra elems */
 static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only_sel)
 {
-	CfraElem *ce, *cen;
-	
 	/* should this one only be considered if it is selected? */
 	if ((only_sel) && ((marker->flag & SELECT) == 0))
 		return;
 	
 	/* insertion sort - try to find a previous cfra elem */
+	CfraElem *ce;
 	for (ce = lb->first; ce; ce = ce->next) {
 		if (ce->cfra == marker->frame) {
 			/* do because of double keys */
@@ -254,7 +252,7 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only
 		}
 	}
 	
-	cen = MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem");
+	CfraElem *cen = MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem");
 	if (ce) BLI_insertlinkbefore(lb, ce, cen);
 	else BLI_addtail(lb, cen);
 
@@ -268,8 +266,6 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only
  */
 void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
 {
-	TimeMarker *marker;
-	
 	if (lb) {
 		/* Clear the list first, since callers have no way of knowing
 		 * whether this terminated early otherwise. This may lead
@@ -285,7 +281,7 @@ void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
 		return;
 	}
 	
-	for (marker = markers->first; marker; marker = marker->next)
+	for (TimeMarker *marker = markers->first; marker; marker = marker->next)
 		add_marker_to_cfra_elem(lb, marker, only_sel);
 }
 
@@ -294,10 +290,8 @@ void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
 /* Get the first selected marker */
 TimeMarker *ED_markers_get_first_selected(ListBase *markers)
 {
-	TimeMarker *marker;
-	
 	if (markers) {
-		for (marker = markers->first; marker; marker = marker->next) {
+		for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
 			if (marker->flag & SELECT)
 				return marker;
 		}
@@ -313,8 +307,6 @@ TimeMarker *ED_markers_get_first_selected(ListBase *markers)
  */
 void debug_markers_print_list(ListBase *markers)
 {
-	TimeMarker *marker;
-	
 	if (markers == NULL) {
 		printf("No markers list to print debug for\n");
 		return;
@@ -322,7 +314,7 @@ void debug_markers_print_list(ListBase *markers)
 	
 	printf("List of markers follows: -----\n");
 	
-	for (marker = markers->first; marker; marker = marker->next) {
+	for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
 		printf("\t'%s' on %d at %p with %u\n", marker->name, marker->frame, (void *)marker, marker->flag);
 	}
 	
@@ -391,7 +383,7 @@ static void draw_marker(
 		float x, y;
 
 		/* minimal y coordinate which wouldn't be occluded by scroll */
-		int min_y = 17.0f * UI_DPI_FAC;
+		const int min_y = 17.0f * UI_DPI_FAC;
 		
 		if (marker->flag & SELECT) {
 			UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
@@ -427,22 +419,14 @@ void ED_markers_draw(const bContext *C, int flag)
 {
 	const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
 	ListBase *markers = ED_context_get_markers(C);
-	View2D *v2d;
 	TimeMarker *marker;
-	Scene *scene;
-	int select_pass;
-	int v2d_clip_range_x[2];
-	float font_width_max;
-
-	/* cache values */
-	float ypixels, xscale, yscale;
 
 	if (markers == NULL || BLI_listbase_is_empty(markers)) {
 		return;
 	}
 
-	scene = CTX_data_scene(C);
-	v2d = UI_view2d_fromcontext(C);
+	Scene *scene = CTX_data_scene(C);
+	View2D *v2d = UI_view2d_fromcontext(C);
 
 	if (flag & DRAW_MARKERS_MARGIN) {
 		unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
@@ -462,18 +446,21 @@ void ED_markers_draw(const bContext *C, int flag)
 	}
 
 	/* no time correction for framelen! space is drawn with old values */
-	ypixels = BLI_rcti_size_y(&v2d->mask);
+	float ypixels = BLI_rcti_size_y(&v2d->mask);
+	float xscale, yscale;
 	UI_view2d_scale_get(v2d, &xscale, &yscale);
 	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;
-	v2d_clip_range_x[0] = v2d->cur.xmin - (sizeof(marker->name) * font_width_max);
-	v2d_clip_range_x[1] = v2d->cur.xmax + font_width_max;
+	float font_width_max = (10 * UI_DPI_FAC) / xscale;
+	int v2d_clip_range_x[2] = {
+		v2d->cur.xmin - (sizeof(marker->name) * font_width_max),
+		v2d->cur.xmax + font_width_max
+	};
 
 	/* loop [unselected, selected] */
-	for (select_pass = 0; select_pass <= SELECT; select_pass += SELECT) {
+	for (int select_pass = 0; select_pass <= SELECT; select_pass += SELECT) {
 		/* unselected markers are drawn at the first time */
 		for (marker = markers->first; marker; marker = marker->next) {
 			if ((marker->flag & SELECT) == select_pass) {
@@ -834,9 +821,9 @@ static void ed_marker_move_apply(bContext *C, wmOperator *op)
 #endif
 	MarkerMove *mm = op->customdata;
 	TimeMarker *marker;
-	int a, offs;
-	
-	offs = RNA_int_get(op->ptr, "frames");
+
+	const int offs = RNA_int_get(op->ptr, "frames");
+	int a;
 	for (a = 0, marker = mm->markers->first; marker; marker = marker->next) {
 		if (marker->flag & SELECT) {
 			marker->frame = mm->oldframe[a] + offs;
@@ -1007,21 +994,20 @@ static void MARKER_OT_move(wmOperatorType *ot)
 static void ed_marker_duplicate_apply(bContext *C)
 {
 	ListBase *markers = ED_context_get_markers(C);
-	TimeMarker *marker, *newmarker;
-	
-	if (markers == NULL) 
+
+	if (markers == NULL)
 		return;
 
 	/* go through the list of markers, duplicate selected markers and add duplicated copies
 	 * to the beginning of the list (unselect original markers)
 	 */
-	for (marker = markers->first; marker; marker = marker->next) {
+	for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
 		if (marker->flag & SELECT) {
 			/* unselect selected marker */
 			marker->flag &= ~SELECT;
 			
 			/* create and set up new marker */
-			newmarker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
+			TimeMarker *newmarker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
 			newmarker->flag = SELECT;
 			newmarker->frame = marker->frame;
 			BLI_strncpy(newmarker->name, marker->name, sizeof(marker->name));
@@ -1117,25 +1103,20 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool
 	ListBase *markers = ED_context_get_markers(C);
 	ARegion *ar = CTX_wm_region(C);
 	View2D *v2d = UI_view2d_fromcontext(C);
-	float viewx;
-	int x, cfra;
 	
 	if (markers == NULL)
 		return OPERATOR_PASS_THROUGH;
 
-	x = event->x - ar->winrct.xmin;
-	
-	viewx = UI_view2d_region_to_view_x(v2d, x);
-	
-	cfra = ED_markers_find_nearest_marker_time(markers, viewx);
-	
+	const int x = event->x - ar->winrct.xmin;
+	const float viewx = UI_view2d_region_to_view_x(v2d, x);
+	const int cfra = ED_markers_find_nearest_marker_time(markers, viewx);
+
 	select_timeline_marker_frame(markers, cfra, extend);
 	
 #ifdef DURIAN_CAMERA_SWITCH
 
 	if (camera) {
 		Scene *scene = CTX_data_scene(C);
-		BaseLegacy *base;
 		TimeMarker *marker;
 		int sel =

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list