[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20954] branches/blender2.5/blender/source /blender: 2.5

Ton Roosendaal ton at blender.org
Wed Jun 17 13:01:05 CEST 2009


Revision: 20954
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20954
Author:   ton
Date:     2009-06-17 13:01:05 +0200 (Wed, 17 Jun 2009)

Log Message:
-----------
2.5

Logic editing back!

Test screenie:
http://download.blender.org/institute/rt9.jpg

I gave the buttons a bit more width, added nicer linkline draw.

Not working yet:
- theme colors for sensor/actuator types (was old button colors)
- moving sensors up/down (used bad pupmenu... better is icons like
  used for modifiers)
- Linkline mouse-over select. Currently deleting a link goes by
  drawing the same line again.

Needs to be fully tested for functionality too, leave that to the GE
department. :)

I noted there's bad button hacking with reading button values,
like check_state_mask(). uiBut structure was not meant to be exported
outside of interface module.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_widgets.c
    branches/blender2.5/blender/source/blender/editors/interface/resources.c
    branches/blender2.5/blender/source/blender/editors/space_logic/logic_intern.h
    branches/blender2.5/blender/source/blender/editors/space_logic/space_logic.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_space_types.h

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/editors/space_logic/logic_window.c

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c	2009-06-17 09:42:04 UTC (rev 20953)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c	2009-06-17 11:01:05 UTC (rev 20954)
@@ -398,18 +398,21 @@
 
 static void ui_draw_linkline(uiBut *but, uiLinkLine *line)
 {
-	float vec1[2], vec2[2];
+	rcti rect;
 
 	if(line->from==NULL || line->to==NULL) return;
 	
-	vec1[0]= (line->from->x1+line->from->x2)/2.0;
-	vec1[1]= (line->from->y1+line->from->y2)/2.0;
-	vec2[0]= (line->to->x1+line->to->x2)/2.0;
-	vec2[1]= (line->to->y1+line->to->y2)/2.0;
+	rect.xmin= (line->from->x1+line->from->x2)/2.0;
+	rect.ymin= (line->from->y1+line->from->y2)/2.0;
+	rect.xmax= (line->to->x1+line->to->x2)/2.0;
+	rect.ymax= (line->to->y1+line->to->y2)/2.0;
 	
-	if(line->flag & UI_SELECT) glColor3ub(100,100,100);
-	else glColor3ub(0,0,0);
-	fdrawline(vec1[0], vec1[1], vec2[0], vec2[1]);
+	if(line->flag & UI_SELECT) 
+		glColor3ub(100,100,100);
+	else 
+		glColor3ub(0,0,0);
+
+	ui_draw_link_bezier(&rect);
 }
 
 static void ui_draw_links(uiBlock *block)
@@ -475,6 +478,8 @@
 				but->selend= oldbut->selend;
 				but->softmin= oldbut->softmin;
 				but->softmax= oldbut->softmax;
+				but->linkto[0]= oldbut->linkto[0];
+				but->linkto[1]= oldbut->linkto[1];
 				found= 1;
 
 				oldbut->active= NULL;
@@ -733,9 +738,14 @@
 
 /* XXX 2.50 no links supported yet */
 
-#if 0
-static uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
+static int uibut_contains_pt(uiBut *but, short *mval)
 {
+	return 0;
+
+}
+
+uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
+{
 	uiBut *bt;
 	
 		/* find button to link to */
@@ -745,7 +755,7 @@
 
 	if (bt) {
 		if (but->type==LINK && bt->type==INLINK) {
-			if( but->link->tocode == (int)bt->min ) {
+			if( but->link->tocode == (int)bt->hardmin ) {
 				return bt;
 			}
 		}
@@ -759,21 +769,6 @@
 	return NULL;
 }
 
-static int ui_is_a_link(uiBut *from, uiBut *to)
-{
-	uiLinkLine *line;
-	uiLink *link;
-	
-	link= from->link;
-	if(link) {
-		line= link->lines.first;
-		while(line) {
-			if(line->from==from && line->to==to) return 1;
-			line= line->next;
-		}
-	}
-	return 0;
-}
 
 static uiBut *ui_find_inlink(uiBlock *block, void *poin)
 {
@@ -839,99 +834,7 @@
 	}
 }
 
-static void ui_add_link(uiBut *from, uiBut *to)
-{
-	/* in 'from' we have to add a link to 'to' */
-	uiLink *link;
-	void **oldppoin;
-	int a;
-	
-	if(ui_is_a_link(from, to)) {
-		printf("already exists\n");
-		return;
-	}
-	
-	link= from->link;
 
-	/* are there more pointers allowed? */
-	if(link->ppoin) {
-		oldppoin= *(link->ppoin);
-		
-		(*(link->totlink))++;
-		*(link->ppoin)= MEM_callocN( *(link->totlink)*sizeof(void *), "new link");
-
-		for(a=0; a< (*(link->totlink))-1; a++) {
-			(*(link->ppoin))[a]= oldppoin[a];
-		}
-		(*(link->ppoin))[a]= to->poin;
-		
-		if(oldppoin) MEM_freeN(oldppoin);
-	}
-	else {
-		*(link->poin)= to->poin;
-	}
-	
-}
-
-static int ui_do_but_LINK(uiBlock *block, uiBut *but)
-{
-	/* 
-	 * This button only visualizes, the dobutton mode
-	 * can add a new link, but then the whole system
-	 * should be redrawn/initialized. 
-	 * 
-	 */
-	uiBut *bt=0, *bto=NULL;
-	short sval[2], mval[2], mvalo[2], first= 1;
-
-	uiGetMouse(curarea->win, sval);
-	mvalo[0]= sval[0];
-	mvalo[1]= sval[1];
-	
-	while (get_mbut() & L_MOUSE) {
-		uiGetMouse(curarea->win, mval);
-
-		if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || first) {			
-				/* clear completely, because of drawbuttons */
-			bt= ui_get_valid_link_button(block, but, mval);
-			if(bt) {
-				bt->flag |= UI_ACTIVE;
-				ui_draw_but(ar, bt);
-			}
-			if(bto && bto!=bt) {
-				bto->flag &= ~UI_ACTIVE;
-				ui_draw_but(ar, bto);
-			}
-			bto= bt;
-
-			if (!first) {
-				glutil_draw_front_xor_line(sval[0], sval[1], mvalo[0], mvalo[1]);
-			}
-			glutil_draw_front_xor_line(sval[0], sval[1], mval[0], mval[1]);
-
-			mvalo[0]= mval[0];
-			mvalo[1]= mval[1];
-
-			first= 0;
-		}
-		else UI_wait_for_statechange();		
-	}
-	
-	if (!first) {
-		glutil_draw_front_xor_line(sval[0], sval[1], mvalo[0], mvalo[1]);
-	}
-
-	if(bt) {
-		if(but->type==LINK) ui_add_link(but, bt);
-		else ui_add_link(bt, but);
-
-		scrarea_queue_winredraw(curarea);
-	}
-
-	return 0;
-}
-#endif
-
 /* ************************************************ */
 
 void uiBlockSetButLock(uiBlock *block, int val, char *lockstr)

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c	2009-06-17 09:42:04 UTC (rev 20953)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c	2009-06-17 11:01:05 UTC (rev 20954)
@@ -165,6 +165,7 @@
 	bContextStore *context;
 } uiAfterFunc;
 
+static int ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y);
 static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state);
 static int ui_handler_region_menu(bContext *C, wmEvent *event, void *userdata);
 static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata);
@@ -525,6 +526,149 @@
 }
 #endif
 
+
+static void ui_delete_active_linkline(uiBlock *block)
+{
+	uiBut *but;
+	uiLink *link;
+	uiLinkLine *line, *nline;
+	int a, b;
+	
+	but= block->buttons.first;
+	while(but) {
+		if(but->type==LINK && but->link) {
+			line= but->link->lines.first;
+			while(line) {
+				
+				nline= line->next;
+				
+				if(line->flag & UI_SELECT) {
+					BLI_remlink(&but->link->lines, line);
+					
+					link= line->from->link;
+					
+					/* are there more pointers allowed? */
+					if(link->ppoin) {
+						
+						if(*(link->totlink)==1) {
+							*(link->totlink)= 0;
+							MEM_freeN(*(link->ppoin));
+							*(link->ppoin)= NULL;
+						}
+						else {
+							b= 0;
+							for(a=0; a< (*(link->totlink)); a++) {
+								
+								if( (*(link->ppoin))[a] != line->to->poin ) {
+									(*(link->ppoin))[b]= (*(link->ppoin))[a];
+									b++;
+								}
+							}	
+							(*(link->totlink))--;
+						}
+					}
+					else {
+						*(link->poin)= NULL;
+					}
+					
+					MEM_freeN(line);
+				}
+				line= nline;
+			}
+		}
+		but= but->next;
+	}
+}
+
+
+static uiLinkLine *ui_is_a_link(uiBut *from, uiBut *to)
+{
+	uiLinkLine *line;
+	uiLink *link;
+	
+	link= from->link;
+	if(link) {
+		line= link->lines.first;
+		while(line) {
+			if(line->from==from && line->to==to) return line;
+			line= line->next;
+		}
+	}
+	return NULL;
+}
+
+static void ui_add_link(uiBut *from, uiBut *to)
+{
+	/* in 'from' we have to add a link to 'to' */
+	uiLink *link;
+	uiLinkLine *line;
+	void **oldppoin;
+	int a;
+	
+	if( (line= ui_is_a_link(from, to)) ) {
+		line->flag |= UI_SELECT;
+		ui_delete_active_linkline(from->block);
+		printf("already exists, means deletion now\n");
+		return;
+	}
+
+	if (from->type==LINK && to->type==INLINK) {
+		if( from->link->tocode != (int)to->hardmin ) {
+			printf("cannot link\n");
+			return;
+		}
+	}
+	else if(from->type==INLINK && to->type==LINK) {
+		if( to->link->tocode == (int)from->hardmin ) {
+			printf("cannot link\n");
+			return;
+		}
+	}
+	
+	link= from->link;
+	
+	/* are there more pointers allowed? */
+	if(link->ppoin) {
+		oldppoin= *(link->ppoin);
+		
+		(*(link->totlink))++;
+		*(link->ppoin)= MEM_callocN( *(link->totlink)*sizeof(void *), "new link");
+		
+		for(a=0; a< (*(link->totlink))-1; a++) {
+			(*(link->ppoin))[a]= oldppoin[a];
+		}
+		(*(link->ppoin))[a]= to->poin;
+		
+		if(oldppoin) MEM_freeN(oldppoin);
+	}
+	else {
+		*(link->poin)= to->poin;
+	}
+	
+}
+
+
+static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+	ARegion *ar= CTX_wm_region(C);
+	uiBut *bt;
+	
+	for(bt= but->block->buttons.first; bt; bt= bt->next) {
+		if( ui_mouse_inside_button(ar, bt, but->linkto[0]+ar->winrct.xmin, but->linkto[1]+ar->winrct.ymin) )
+			break;
+	}
+	if(bt && bt!=but) {
+		
+		if(but->type==LINK) ui_add_link(but, bt);
+		else ui_add_link(bt, but);
+
+		ui_apply_but_func(C, but);
+		data->retval= but->retval;
+	}
+	data->applied= 1;
+}
+
+
 static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
 {
 	char *editstr;
@@ -640,6 +784,7 @@
 #endif
 		case LINK:
 		case INLINK:
+			ui_apply_but_LINK(C, but, data);
 			break;
 		default:
 			break;
@@ -2806,6 +2951,38 @@
 }
 #endif
 
+
+static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event)
+{
+	ARegion *ar= CTX_wm_region(C);
+	
+	but->linkto[0]= event->x-ar->winrct.xmin;
+	but->linkto[1]= event->y-ar->winrct.ymin;
+	
+	if(data->state == BUTTON_STATE_HIGHLIGHT) {
+		if(event->type == LEFTMOUSE && event->val==KM_PRESS) {
+			button_activate_state(C, but, BUTTON_STATE_WAIT_RELEASE);
+			return WM_UI_HANDLER_BREAK;
+		}
+		else if(event->type == LEFTMOUSE && but->block->handle) {
+			button_activate_state(C, but, BUTTON_STATE_EXIT);
+			return WM_UI_HANDLER_BREAK;
+		}
+	}
+	else if(data->state == BUTTON_STATE_WAIT_RELEASE) {
+		
+		if(event->type == LEFTMOUSE && event->val!=KM_PRESS) {
+			if(!(but->flag & UI_SELECT))
+				data->cancel= 1;
+			button_activate_state(C, but, BUTTON_STATE_EXIT);
+			return WM_UI_HANDLER_BREAK;
+		}
+	}
+	
+	return WM_UI_HANDLER_CONTINUE;
+}
+
+
 static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
 {
 	uiHandleButtonData *data;
@@ -2951,13 +3128,11 @@
 		retval= ui_do_but_CHARTAB(C, block, but, data, event);
 		break;
 #endif
-	/* XXX 2.50 links not implemented yet */
-#if 0
+
 	case LINK:
 	case INLINK:
-		retval= retval= ui_do_but_LINK(block, but);
+		retval= ui_do_but_LINK(C, but, data, event);
 		break;
-#endif
 	}
 	
 	return retval;
@@ -3421,21 +3596,29 @@
 	else if(data->state == BUTTON_STATE_WAIT_RELEASE) {
 		switch(event->type) {
 			case MOUSEMOVE:
-				/* deselect the button when moving the mouse away */
-				if(ui_mouse_inside_button(ar, but, event->x, event->y)) {
-					if(!(but->flag & UI_SELECT)) {
-						but->flag |= UI_SELECT;
-						data->cancel= 0;
-						ED_region_tag_redraw(data->region);
-					}
+				
+				if(ELEM(but->type,LINK, INLINK)) {
+					but->flag |= UI_SELECT;
+					ui_do_button(C, block, but, event);
+					ED_region_tag_redraw(data->region);
 				}
 				else {
-					if(but->flag & UI_SELECT) {
-						but->flag &= ~UI_SELECT;
-						data->cancel= 1;
-						ED_region_tag_redraw(data->region);
+					/* deselect the button when moving the mouse away */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list