[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28502] trunk/blender/source/blender: Rewrite of Logic editor UI to use layout engine

Matt Ebb matt at mke3.net
Thu Apr 29 09:01:48 CEST 2010


Revision: 28502
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28502
Author:   broken
Date:     2010-04-29 09:01:48 +0200 (Thu, 29 Apr 2010)

Log Message:
-----------
Rewrite of Logic editor UI to use layout engine

This commit puts the ground work in place, swapping out the crusty old Logic Editor
UI code for the new RNA-based layout engine. It's disabled with ifdefs at the moment
because it's incomplete, but Dalai can now do the grunt work to fill it all out and get it running.

Also includes a bug fix to LINK buttons, and two new logic operators to add and delete sensors.

Dalai, just switch the #if 0 and #if 1 in logic_window.c:3412 and 3469

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/space_api/spacetypes.c
    trunk/blender/source/blender/editors/space_logic/logic_intern.h
    trunk/blender/source/blender/editors/space_logic/logic_window.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/RNA_enum_types.h
    trunk/blender/source/blender/makesrna/intern/rna_sensor.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Added Paths:
-----------
    trunk/blender/source/blender/editors/include/ED_logic.h
    trunk/blender/source/blender/editors/space_logic/logic_ops.c

Added: trunk/blender/source/blender/editors/include/ED_logic.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_logic.h	                        (rev 0)
+++ trunk/blender/source/blender/editors/include/ED_logic.h	2010-04-29 07:01:48 UTC (rev 28502)
@@ -0,0 +1,36 @@
+/**
+ * $Id: ED_armature.h 28425 2010-04-26 06:35:25Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef ED_LOGIC_H
+#define ED_LOGIC_H
+
+/* logic_ops.c */
+void ED_operatortypes_logic(void);
+
+#endif /* ED_LOGIC_H */
+
+
+

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-04-29 06:42:31 UTC (rev 28501)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-04-29 07:01:48 UTC (rev 28502)
@@ -777,6 +777,8 @@
 			break;
 	}
 	if(bt && bt!=but) {
+		if (!ELEM(bt->type, LINK, INLINK) || !ELEM(but->type, LINK, INLINK))
+			return;
 		
 		if(but->type==LINK) ui_add_link(but, bt);
 		else ui_add_link(bt, but);

Modified: trunk/blender/source/blender/editors/space_api/spacetypes.c
===================================================================
--- trunk/blender/source/blender/editors/space_api/spacetypes.c	2010-04-29 06:42:31 UTC (rev 28501)
+++ trunk/blender/source/blender/editors/space_api/spacetypes.c	2010-04-29 07:01:48 UTC (rev 28502)
@@ -100,6 +100,7 @@
 	ED_operatortypes_metaball();
 	ED_operatortypes_sound();
 	ED_operatortypes_render();
+	ED_operatortypes_logic();
 	
 	UI_view2d_operatortypes();
 	UI_buttons_operatortypes();

Modified: trunk/blender/source/blender/editors/space_logic/logic_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_intern.h	2010-04-29 06:42:31 UTC (rev 28501)
+++ trunk/blender/source/blender/editors/space_logic/logic_intern.h	2010-04-29 07:01:48 UTC (rev 28502)
@@ -54,6 +54,7 @@
 
 /* logic_window.c */
 void logic_buttons(struct bContext *C, struct ARegion *ar);
+void make_unique_prop_names(struct bContext *C, char *str);
 
 #endif /* ED_LOGIC_INTERN_H */
 

Added: trunk/blender/source/blender/editors/space_logic/logic_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_ops.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/space_logic/logic_ops.c	2010-04-29 07:01:48 UTC (rev 28502)
@@ -0,0 +1,196 @@
+/**
+ * $Id: logic_header.c 27676 2010-03-23 14:09:09Z campbellbarton $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
+ * All rights reserved.
+ *
+ * 
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#include <stddef.h>
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_sensor_types.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_sca.h"
+
+#include "ED_object.h"
+#include "ED_screen.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "logic_intern.h"
+
+/* ************* Generic Operator Helpers ************* */
+
+static int edit_sensor_poll(bContext *C)
+{
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
+
+	if (ptr.data && ((ID*)ptr.id.data)->lib) return 0;
+	return 1;
+}
+
+/* this is the nice py-api-compatible way to do it, like modifiers, 
+   but not entirely working yet..
+ 
+static void edit_sensor_properties(wmOperatorType *ot)
+{
+	RNA_def_string(ot->srna, "sensor", "", 32, "Sensor", "Name of the sensor to edit");
+	RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the object the sensor belongs to");
+}
+
+static int edit_sensor_invoke_properties(bContext *C, wmOperator *op)
+{
+	PointerRNA ptr= CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
+	
+	if (RNA_property_is_set(op->ptr, "sensor") && RNA_property_is_set(op->ptr, "object") )
+		return 1;
+	
+	if (ptr.data) {
+		bSensor *sens = ptr.data;
+		Object *ob = ptr.id.data;
+		
+		RNA_string_set(op->ptr, "sensor", sens->name);
+		RNA_string_set(op->ptr, "object", ob->id.name+2);
+		return 1;
+	}
+	
+	return 0;
+}
+
+static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object *ob)
+{
+	char sensor_name[32];
+	char ob_name[32];
+	bSensor *sens;
+	
+	RNA_string_get(op->ptr, "sensor", sensor_name);
+	RNA_string_get(op->ptr, "object", ob_name);
+	
+	ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
+	if (!ob)
+		return NULL;
+	
+	sens = BLI_findstring(&(ob->sensors), sensor_name, offsetof(bSensor, name));	
+	return sens;
+}
+ */
+
+/* ************* Remove Sensor Operator ************* */
+
+static int sensor_remove_exec(bContext *C, wmOperator *op)
+{
+	/*	Object *ob;
+	bSensor *sens = edit_sensor_property_get(C, op, ob);	*/
+	PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
+	Object *ob= ptr.id.data;
+	bSensor *sens= ptr.data;
+	
+	if (!sens)
+		return OPERATOR_CANCELLED;
+	
+	BLI_remlink(&(ob->sensors), sens);
+	free_sensor(sens);
+	
+	WM_event_add_notifier(C, NC_LOGIC, NULL);
+	
+	return OPERATOR_FINISHED;
+}
+
+
+/* commented along with above stuff
+ static int sensor_remove_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	if (edit_sensor_invoke_properties(C, op))
+		return sensor_remove_exec(C, op);
+	else
+		return OPERATOR_CANCELLED;
+}
+ */
+
+void LOGIC_OT_sensor_remove(wmOperatorType *ot)
+{
+	ot->name= "Remove Sensor";
+	ot->description= "Remove a sensor from the active object";
+	ot->idname= "LOGIC_OT_sensor_remove";
+	
+	//ot->invoke= sensor_remove_invoke;
+	ot->exec= sensor_remove_exec;
+	ot->poll= edit_sensor_poll;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	//edit_sensor_properties(ot);
+}
+
+static int sensor_add_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_active_context(C);
+	bSensor *sens;
+	int type= RNA_enum_get(op->ptr, "type");
+
+	sens= new_sensor(type);
+	BLI_addtail(&(ob->sensors), sens);
+	make_unique_prop_names(C, sens->name);
+	ob->scaflag |= OB_SHOWSENS;
+
+	WM_event_add_notifier(C, NC_LOGIC, NULL);
+	
+	return OPERATOR_FINISHED;
+}
+
+void LOGIC_OT_sensor_add(wmOperatorType *ot)
+{
+	PropertyRNA *prop;
+	
+	/* identifiers */
+	ot->name= "Add Sensor";
+	ot->description = "Add a sensor to the active object";
+	ot->idname= "LOGIC_OT_sensor_add";
+	
+	/* api callbacks */
+	ot->invoke= WM_menu_invoke;
+	ot->exec= sensor_add_exec;
+	ot->poll= ED_operator_object_active_editable;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	
+	/* properties */
+	prop= RNA_def_enum(ot->srna, "type", sensor_type_items, SENS_ALWAYS, "Type", "Type of sensor to add");
+}
+
+void ED_operatortypes_logic(void)
+{
+	WM_operatortype_append(LOGIC_OT_sensor_remove);
+	WM_operatortype_append(LOGIC_OT_sensor_add);
+}

Modified: trunk/blender/source/blender/editors/space_logic/logic_window.c
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_window.c	2010-04-29 06:42:31 UTC (rev 28501)
+++ trunk/blender/source/blender/editors/space_logic/logic_window.c	2010-04-29 07:01:48 UTC (rev 28502)
@@ -63,6 +63,8 @@
 
 #include "UI_interface.h"
 
+#include "RNA_access.h"
+
 /* XXX BAD BAD */
 #include "../interface/interface_intern.h"
 
@@ -3168,7 +3170,53 @@
 /* never used, see CVS 1.120 for the code */
 /*  static uiBlock *freecamera_menu(void) */
 
+static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr)
+{
+	uiLayout *box, *row;
+	
+	box= uiLayoutBox(layout);
+	row= uiLayoutRow(box, 0);
+	
+	uiItemR(row, ptr, "expanded", UI_ITEM_R_NO_BG, "", 0);
+	uiItemR(row, ptr, "type", 0, "", 0);
+	uiItemR(row, ptr, "name", 0, "", 0);
+	uiItemO(row, "", ICON_X, "LOGIC_OT_sensor_remove");
+}
 
+
+static void draw_sensor_touch(uiLayout *layout, PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "material", 0, NULL, 0);
+}
+
+static void draw_sensor_delay(uiLayout *layout, PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "delay", 0, NULL, 0);
+	uiItemR(layout, ptr, "duration", 0, NULL, 0);
+	uiItemR(layout, ptr, "repeat", 0, NULL, 0);
+}
+
+void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr)
+{
+	uiLayout *box;
+	
+	if (!RNA_boolean_get(ptr, "expanded"))
+		return;
+	
+	box = uiLayoutBox(layout);
+	
+	switch (RNA_enum_get(ptr, "type")) {
+		case SENS_ALWAYS:
+			break;
+		case SENS_TOUCH:
+			draw_sensor_touch(box, ptr);
+			break;
+		case SENS_DELAY:
+			draw_sensor_delay(box, ptr);
+			break;
+	}
+}
+
 void logic_buttons(bContext *C, ARegion *ar)
 {
 	SpaceLogic *slogic= CTX_wm_space_logic(C);
@@ -3179,8 +3227,11 @@
 	bActuator *act;
 	uiBlock *block;
 	uiBut *but;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list