Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2010-04-29 11:01:48 +0400
committerMatt Ebb <matt@mke3.net>2010-04-29 11:01:48 +0400
commitb008f044505b0955318b13733f34ade7f2a688e5 (patch)
treefb5c5d31c42a0a550933a125ca8385d846fc1cfe /source/blender/editors
parent09f2b457f89da84bd1d335112acb6becec80401a (diff)
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
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/ED_logic.h36
-rw-r--r--source/blender/editors/interface/interface_handlers.c2
-rw-r--r--source/blender/editors/space_api/spacetypes.c1
-rw-r--r--source/blender/editors/space_logic/logic_intern.h1
-rw-r--r--source/blender/editors/space_logic/logic_ops.c196
-rw-r--r--source/blender/editors/space_logic/logic_window.c117
6 files changed, 351 insertions, 2 deletions
diff --git a/source/blender/editors/include/ED_logic.h b/source/blender/editors/include/ED_logic.h
new file mode 100644
index 00000000000..eff94229ef8
--- /dev/null
+++ b/source/blender/editors/include/ED_logic.h
@@ -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 */
+
+
+
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 7aace1197b6..ff56b14c653 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -777,6 +777,8 @@ static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data)
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);
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index ba7172b0da8..3def3f962dc 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -100,6 +100,7 @@ void ED_spacetypes_init(void)
ED_operatortypes_metaball();
ED_operatortypes_sound();
ED_operatortypes_render();
+ ED_operatortypes_logic();
UI_view2d_operatortypes();
UI_buttons_operatortypes();
diff --git a/source/blender/editors/space_logic/logic_intern.h b/source/blender/editors/space_logic/logic_intern.h
index 4d19a16ee9c..3b2b6497cdc 100644
--- a/source/blender/editors/space_logic/logic_intern.h
+++ b/source/blender/editors/space_logic/logic_intern.h
@@ -54,6 +54,7 @@ void LOGIC_OT_links_cut(struct wmOperatorType *ot);
/* 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 */
diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c
new file mode 100644
index 00000000000..c627f41f180
--- /dev/null
+++ b/source/blender/editors/space_logic/logic_ops.c
@@ -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);
+}
diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c
index 39d3feafc19..de8c5ae6ba2 100644
--- a/source/blender/editors/space_logic/logic_window.c
+++ b/source/blender/editors/space_logic/logic_window.c
@@ -63,6 +63,8 @@
#include "UI_interface.h"
+#include "RNA_access.h"
+
/* XXX BAD BAD */
#include "../interface/interface_intern.h"
@@ -3168,6 +3170,52 @@ static int is_sensor_linked(uiBlock *block, bSensor *sens)
/* 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)
{
@@ -3179,8 +3227,11 @@ void logic_buttons(bContext *C, ARegion *ar)
bActuator *act;
uiBlock *block;
uiBut *but;
+ uiLayout *layout, *row;
+ PointerRNA logic_ptr;
int a, iact, stbit, offset;
- short xco, yco, count, width, ycoo;
+ int xco, yco, width, ycoo;
+ short count;
char name[32];
/* pin is a bool used for actuator and sensor drawing with states
* pin so changing states dosnt hide the logic brick */
@@ -3193,6 +3244,8 @@ void logic_buttons(bContext *C, ARegion *ar)
block= uiBeginBlock(C, ar, name, UI_EMBOSS);
uiBlockSetHandleFunc(block, do_logic_buts, NULL);
+ RNA_pointer_create(NULL, &RNA_SpaceLogicEditor, slogic, &logic_ptr);
+
idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
/* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that
@@ -3354,8 +3407,66 @@ void logic_buttons(bContext *C, ARegion *ar)
}
/* ******************************* */
- xco= 10; yco= 170; width= 300;
+ xco= 10; yco= 205; width= 320;
+
+#if 0
+
+ layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
+ row = uiLayoutRow(layout, 1);
+
+ uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco, 70, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
+
+ uiItemR(row, &logic_ptr, "sensors_show_selected_objects", 0, "Sel", 0);
+ uiItemR(row, &logic_ptr, "sensors_show_active_objects", 0, "Act", 0);
+ uiItemR(row, &logic_ptr, "sensors_show_linked_controller", 0, "Link", 0);
+ uiItemR(row, &logic_ptr, "sensors_show_active_states", 0, "State", 0);
+
+ row = uiLayoutRow(layout, 1);
+ uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
+ uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", "Add Sensor", 0);
+
+ for(a=0; a<count; a++) {
+ PointerRNA ptr;
+
+ ob= (Object *)idar[a];
+
+ if (!(ob->scavisflag & OB_VIS_SENS) || !(ob->scaflag & OB_SHOWSENS)) continue;
+
+ uiItemS(layout);
+
+ for(sens= ob->sensors.first; sens; sens=sens->next) {
+ RNA_pointer_create(&ob->id, &RNA_Sensor, sens, &ptr);
+
+ if ((slogic->scaflag & BUTS_SENS_STATE) ||
+ (sens->totlinks == 0) || /* always display sensor without links so that is can be edited */
+ (sens->flag & SENS_PIN && slogic->scaflag & BUTS_SENS_STATE) || /* states can hide some sensors, pinned sensors ignore the visible state */
+ (is_sensor_linked(block, sens))
+ )
+ {
+ uiLayout *split, *col;
+
+ split = uiLayoutSplit(layout, 0.95, 0);
+ col = uiLayoutColumn(split, 1);
+ uiLayoutSetContextPointer(col, "sensor", &ptr);
+
+ /* should make UI template for sensor header.. function will do for now */
+ draw_sensor_header(col, &ptr);
+
+ /* draw the brick contents */
+ draw_brick_sensor(col, &ptr);
+
+ /* put link button to the right */
+ col = uiLayoutColumn(split, 0);
+ /* use oldskool uiButtons for links for now */
+ but= uiDefIconBut(block, LINK, 0, ICON_LINK, (short)(xco+width+UI_UNIT_X), yco, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+ uiSetButLink(but, NULL, (void ***)&(sens->links), &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
+ }
+ }
+ }
+ uiBlockLayoutResolve(block, NULL, &yco); /* stores final height in yco */
+#endif
+#if 1
uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco+35, 70, UI_UNIT_Y, "");
uiBlockBeginAlign(block);
@@ -3437,6 +3548,8 @@ void logic_buttons(bContext *C, ARegion *ar)
yco-= 6;
}
}
+#endif
+
/* ******************************* */
xco= 800; yco= 170; width= 300;