[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49990] trunk/blender/source/blender/ editors: use rctf struct for UI buttons and blocks, easier to read and means we can use BLI_rctf functions.

Campbell Barton ideasman42 at gmail.com
Sat Aug 18 18:53:46 CEST 2012


Revision: 49990
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49990
Author:   campbellbarton
Date:     2012-08-18 16:53:46 +0000 (Sat, 18 Aug 2012)
Log Message:
-----------
use rctf struct for UI buttons and blocks, easier to read and means we can use BLI_rctf functions.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_intern.h
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_ops.c
    trunk/blender/source/blender/editors/interface/interface_panel.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/space_image/image_buttons.c
    trunk/blender/source/blender/editors/space_logic/logic_buttons.c
    trunk/blender/source/blender/editors/space_node/node_templates.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2012-08-18 16:16:13 UTC (rev 49989)
+++ trunk/blender/source/blender/editors/interface/interface.c	2012-08-18 16:53:46 UTC (rev 49990)
@@ -196,19 +196,13 @@
 
 void ui_block_translate(uiBlock *block, int x, int y)
 {
-	uiBut *bt;
+	uiBut *but;
 
-	for (bt = block->buttons.first; bt; bt = bt->next) {
-		bt->x1 += x;
-		bt->y1 += y;
-		bt->x2 += x;
-		bt->y2 += y;
+	for (but = block->buttons.first; but; but = but->next) {
+		BLI_rctf_translate(&but->rect, x, y);
 	}
 
-	block->minx += x;
-	block->miny += y;
-	block->maxx += x;
-	block->maxy += y;
+	BLI_rctf_translate(&block->rect, x, y);
 }
 
 static void ui_text_bounds_block(uiBlock *block, float offset)
@@ -227,24 +221,24 @@
 			if (j > i) i = j;
 		}
 
-		if (bt->next && bt->x1 < bt->next->x1)
+		if (bt->next && bt->rect.xmin < bt->next->rect.xmin)
 			lastcol++;
 	}
 
 	/* cope with multi collumns */
 	bt = block->buttons.first;
 	while (bt) {
-		if (bt->next && bt->x1 < bt->next->x1) {
+		if (bt->next && bt->rect.xmin < bt->next->rect.xmin) {
 			nextcol = 1;
 			col++;
 		}
 		else nextcol = 0;
 		
-		bt->x1 = x1addval;
-		bt->x2 = bt->x1 + i + block->bounds;
+		bt->rect.xmin = x1addval;
+		bt->rect.xmax = bt->rect.xmin + i + block->bounds;
 		
 		if (col == lastcol)
-			bt->x2 = MAX2(bt->x2, offset + block->minbounds);
+			bt->rect.xmax = MAX2(bt->rect.xmax, offset + block->minbounds);
 
 		ui_check_but(bt);   // clips text again
 		
@@ -262,43 +256,43 @@
 	
 	if (block->buttons.first == NULL) {
 		if (block->panel) {
-			block->minx = 0.0; block->maxx = block->panel->sizex;
-			block->miny = 0.0; block->maxy = block->panel->sizey;
+			block->rect.xmin = 0.0; block->rect.xmax = block->panel->sizex;
+			block->rect.ymin = 0.0; block->rect.ymax = block->panel->sizey;
 		}
 	}
 	else {
 	
-		block->minx = block->miny = 10000;
-		block->maxx = block->maxy = -10000;
-		
+		block->rect.xmin = block->rect.ymin =  10000;
+		block->rect.xmax = block->rect.ymax = -10000;
+
 		bt = block->buttons.first;
 		while (bt) {
-			if (bt->x1 < block->minx) block->minx = bt->x1;
-			if (bt->y1 < block->miny) block->miny = bt->y1;
+			if (bt->rect.xmin < block->rect.xmin) block->rect.xmin = bt->rect.xmin;
+			if (bt->rect.ymin < block->rect.ymin) block->rect.ymin = bt->rect.ymin;
 	
-			if (bt->x2 > block->maxx) block->maxx = bt->x2;
-			if (bt->y2 > block->maxy) block->maxy = bt->y2;
+			if (bt->rect.xmax > block->rect.xmax) block->rect.xmax = bt->rect.xmax;
+			if (bt->rect.ymax > block->rect.ymax) block->rect.ymax = bt->rect.ymax;
 
 			bt = bt->next;
 		}
 		
-		block->minx -= block->bounds;
-		block->miny -= block->bounds;
-		block->maxx += block->bounds;
-		block->maxy += block->bounds;
+		block->rect.xmin -= block->bounds;
+		block->rect.ymin -= block->bounds;
+		block->rect.xmax += block->bounds;
+		block->rect.ymax += block->bounds;
 	}
 
-	block->maxx = block->minx + MAX2(block->maxx - block->minx, block->minbounds);
+	block->rect.xmax = block->rect.xmin + MAX2(block->rect.xmax - block->rect.xmin, block->minbounds);
 
 	/* hardcoded exception... but that one is annoying with larger safety */ 
 	bt = block->buttons.first;
 	if (bt && strncmp(bt->str, "ERROR", 5) == 0) xof = 10;
 	else xof = 40;
 
-	block->safety.xmin = block->minx - xof;
-	block->safety.ymin = block->miny - xof;
-	block->safety.xmax = block->maxx + xof;
-	block->safety.ymax = block->maxy + xof;
+	block->safety.xmin = block->rect.xmin - xof;
+	block->safety.ymin = block->rect.ymin - xof;
+	block->safety.xmax = block->rect.xmax + xof;
+	block->safety.ymax = block->rect.ymax + xof;
 }
 
 static void ui_centered_bounds_block(const bContext *C, uiBlock *block)
@@ -316,13 +310,13 @@
 	
 	ui_bounds_block(block);
 	
-	width = block->maxx - block->minx;
-	height = block->maxy - block->miny;
+	width = block->rect.xmax - block->rect.xmin;
+	height = block->rect.ymax - block->rect.ymin;
 	
 	startx = (xmax * 0.5f) - (width * 0.5f);
 	starty = (ymax * 0.5f) - (height * 0.5f);
 	
-	ui_block_translate(block, startx - block->minx, starty - block->miny);
+	ui_block_translate(block, startx - block->rect.xmin, starty - block->rect.ymin);
 	
 	/* now recompute bounds and safety */
 	ui_bounds_block(block);
@@ -341,14 +335,14 @@
 	
 	wm_window_get_size(window, &xmax, &ymax);
 
-	oldwidth = block->maxx - block->minx;
-	oldheight = block->maxy - block->miny;
+	oldwidth = block->rect.xmax - block->rect.xmin;
+	oldheight = block->rect.ymax - block->rect.ymin;
 
 	/* first we ensure wide enough text bounds */
 	if (bounds_calc == UI_BLOCK_BOUNDS_POPUP_MENU) {
 		if (block->flag & UI_BLOCK_LOOP) {
 			block->bounds = 50;
-			ui_text_bounds_block(block, block->minx);
+			ui_text_bounds_block(block, block->rect.xmin);
 		}
 	}
 
@@ -357,8 +351,8 @@
 	ui_bounds_block(block);
 
 	/* and we adjust the position to fit within window */
-	width = block->maxx - block->minx;
-	height = block->maxy - block->miny;
+	width = block->rect.xmax - block->rect.xmin;
+	height = block->rect.ymax - block->rect.ymin;
 
 	/* avoid divide by zero below, caused by calling with no UI, but better not crash */
 	oldwidth = oldwidth > 0 ? oldwidth : MAX2(1, width);
@@ -366,8 +360,8 @@
 
 	/* offset block based on mouse position, user offset is scaled
 	 * along in case we resized the block in ui_text_bounds_block */
-	startx = window->eventstate->x + block->minx + (block->mx * width) / oldwidth;
-	starty = window->eventstate->y + block->miny + (block->my * height) / oldheight;
+	startx = window->eventstate->x + block->rect.xmin + (block->mx * width) / oldwidth;
+	starty = window->eventstate->y + block->rect.ymin + (block->my * height) / oldheight;
 
 	if (startx < 10)
 		startx = 10;
@@ -386,7 +380,7 @@
 		starty = endy - height;
 	}
 
-	ui_block_translate(block, startx - block->minx, starty - block->miny);
+	ui_block_translate(block, startx - block->rect.xmin, starty - block->rect.ymin);
 
 	/* now recompute bounds and safety */
 	ui_bounds_block(block);
@@ -436,10 +430,10 @@
 
 void uiExplicitBoundsBlock(uiBlock *block, int minx, int miny, int maxx, int maxy)
 {
-	block->minx = minx;
-	block->miny = miny;
-	block->maxx = maxx;
-	block->maxy = maxy;
+	block->rect.xmin = minx;
+	block->rect.ymin = miny;
+	block->rect.xmax = maxx;
+	block->rect.ymax = maxy;
 	block->dobounds = 0;
 }
 
@@ -504,10 +498,10 @@
 
 	if (line->from == NULL || line->to == NULL) return;
 	
-	rect.xmin = (line->from->x1 + line->from->x2) / 2.0f;
-	rect.ymin = (line->from->y1 + line->from->y2) / 2.0f;
-	rect.xmax = (line->to->x1 + line->to->x2) / 2.0f;
-	rect.ymax = (line->to->y1 + line->to->y2) / 2.0f;
+	rect.xmin = (line->from->rect.xmin + line->from->rect.xmax) / 2.0f;
+	rect.ymin = (line->from->rect.ymin + line->from->rect.ymax) / 2.0f;
+	rect.xmax = (line->to->rect.xmin + line->to->rect.xmax) / 2.0f;
+	rect.ymax = (line->to->rect.ymin + line->to->rect.ymax) / 2.0f;
 	
 	if (line->flag & UI_SELECT)
 		glColor3ub(100, 100, 100);
@@ -653,8 +647,8 @@
 				*butpp = oldbut;
 				
 				/* still stuff needs to be copied */
-				oldbut->x1 = but->x1; oldbut->y1 = but->y1;
-				oldbut->x2 = but->x2; oldbut->y2 = but->y2;
+				oldbut->rect.xmin = but->rect.xmin; oldbut->rect.ymin = but->rect.ymin;
+				oldbut->rect.xmax = but->rect.xmax; oldbut->rect.ymax = but->rect.ymax;
 				oldbut->context = but->context; /* set by Layout */
 				
 				/* typically the same pointers, but not on undo/redo */
@@ -764,7 +758,7 @@
 	int tot_missing = 0;
 
 	/* only do it before bounding */
-	if (block->minx != block->maxx)
+	if (block->rect.xmin != block->rect.xmax)
 		return;
 
 	for (pass = 0; pass < 2; pass++) {
@@ -865,7 +859,7 @@
 	IDProperty *prop_menu_name = NULL;
 
 	/* only do it before bounding */
-	if (block->minx != block->maxx)
+	if (block->rect.xmin != block->rect.xmax)
 		return;
 
 	for (but = block->buttons.first; but; but = but->next) {
@@ -960,7 +954,7 @@
 	else if (block->dobounds == UI_BLOCK_BOUNDS_POPUP_CENTER) ui_centered_bounds_block(C, block);
 	else if (block->dobounds) ui_popup_bounds_block(C, block, block->dobounds);
 
-	if (block->minx == 0.0f && block->maxx == 0.0f) uiBoundsBlock(block, 0);
+	if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) uiBoundsBlock(block, 0);
 	if (block->flag & UI_BUT_ALIGN) uiBlockEndAlign(block);
 
 	block->endblock = 1;
@@ -993,14 +987,14 @@
 	getsizex = ar->winx;
 	getsizey = ar->winy;
 
-	gx = (but ? but->x1 : block->minx) + (block->panel ? block->panel->ofsx : 0.0f);
-	gy = (but ? but->y1 : block->miny) + (block->panel ? block->panel->ofsy : 0.0f);
+	gx = (but ? but->rect.xmin : block->rect.xmin) + (block->panel ? block->panel->ofsx : 0.0f);
+	gy = (but ? but->rect.ymin : block->rect.ymin) + (block->panel ? block->panel->ofsy : 0.0f);
 	
 	rect->xmin = floorf(getsizex * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + block->winmat[3][0])));
 	rect->ymin = floorf(getsizey * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + block->winmat[3][1])));
 	
-	gx = (but ? but->x2 : block->maxx) + (block->panel ? block->panel->ofsx : 0.0f);
-	gy = (but ? but->y2 : block->maxy) + (block->panel ? block->panel->ofsy : 0.0f);
+	gx = (but ? but->rect.xmax : block->rect.xmax) + (block->panel ? block->panel->ofsx : 0.0f);
+	gy = (but ? but->rect.ymax : block->rect.ymax) + (block->panel ? block->panel->ofsy : 0.0f);
 	
 	rect->xmax = floorf(getsizex * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + block->winmat[3][0])));
 	rect->ymax = floorf(getsizey * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + block->winmat[3][1])));
@@ -2221,7 +2215,7 @@
 	
 	
 	/* safety is 4 to enable small number buttons (like 'users') */
-	// okwidth= -4 + (but->x2 - but->x1); // UNUSED
+	// okwidth= -4 + (but->rect.xmax - but->rect.xmin); // UNUSED
 	
 	/* name: */
 	switch (but->type) {
@@ -2229,7 +2223,7 @@
 		case MENU:
 		case ICONTEXTROW:
 		
-			if (but->x2 - but->x1 > 24) {
+			if (but->rect.xmax - but->rect.xmin > 24) {
 				UI_GET_BUT_VALUE_INIT(but, value);
 				ui_set_name_menu(but, (int)value);
 			}
@@ -2373,8 +2367,8 @@
 {
 	float dx, dy;
 	
-	dx = fabs(but1->x2 - but2->x1);
-	dy = fabs(but1->y1 - but2->y2);
+	dx = fabs(but1->rect.xmax - but2->rect.xmin);
+	dy = fabs(but1->rect.ymin - but2->rect.ymax);
 	
 	if (dx > dy) return 0;
 	return 1;
@@ -2492,32 +2486,32 @@
 		if (prev) {
 			/* simple cases */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list