[Bf-blender-cvs] [9c5e1a0] wiggly-widgets: Widgets:

Antony Riakiotakis noreply at git.blender.org
Tue Oct 14 18:37:35 CEST 2014


Commit: 9c5e1a0ea54260b5dbd8f3ebbd2eddb6052cccab
Author: Antony Riakiotakis
Date:   Tue Oct 14 18:37:28 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB9c5e1a0ea54260b5dbd8f3ebbd2eddb6052cccab

Widgets:

* Move lamp operators to a proper place
* Store a list of widgets to avoid polling too many times
* Fix wrong indices when widgetgroup was not used.
* Lamp widget now uses an arrow widget. This will be refined to make a
nice prototype for operator/widget interaction.

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

M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_generic_widgets.c
M	source/blender/editors/interface/interface_ops.c
M	source/blender/editors/object/CMakeLists.txt
M	source/blender/editors/object/object_intern.h
A	source/blender/editors/object/object_lamp.c
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_widgets.c

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

diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index bd4f37c..0770e1e 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -41,6 +41,7 @@ struct Base;
 struct BezTriple;
 struct BoundBox;
 struct EditBone;
+struct wmEvent;
 struct ImBuf;
 struct MVert;
 struct Main;
@@ -61,6 +62,8 @@ struct rcti;
 struct wmOperator;
 struct wmOperatorType;
 struct wmWindow;
+struct wmWidget;
+struct wmWidgetGroup;
 
 /* for derivedmesh drawing callbacks, for view3d_select, .... */
 typedef struct ViewContext {
@@ -367,6 +370,10 @@ void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOper
 void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx, int *winy, float persmat[4][4]);
 #endif
 
+bool WIDGETGROUP_lamp_poll(struct wmWidgetGroup *wgroup, const struct bContext *C);
+int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
+void WIDGETGROUP_lamp_update(struct wmWidgetGroup *wgroup, const struct bContext *C);
+
 /* render */
 void ED_view3d_shade_update(struct Main *bmain, struct Scene *scene, struct View3D *v3d, struct ScrArea *sa);
 
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index ef087ba..560f511 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -999,10 +999,6 @@ void UI_butstore_unregister(uiButStore *bs_handle, uiBut **but_p);
 int uiFloatPrecisionCalc(int prec, double value);
 
 /* ui_generic_widgets.c */
-int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
-void WIDGET_lamp_render_3d_intersect(const struct bContext *C, struct wmWidget *widget, float scale, int selectionbase);
-void WIDGET_lamp_draw(struct wmWidget *widget, const struct bContext *C, float scale);
-bool WIDGETGROUP_lamp_poll(struct wmWidgetGroup *widget, const struct bContext *C);
 
 enum {
 	UI_ARROW_STYLE_SHADED = 0,
diff --git a/source/blender/editors/interface/interface_generic_widgets.c b/source/blender/editors/interface/interface_generic_widgets.c
index 9838d52..f8c7e02 100644
--- a/source/blender/editors/interface/interface_generic_widgets.c
+++ b/source/blender/editors/interface/interface_generic_widgets.c
@@ -31,9 +31,7 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_lamp_types.h"
 #include "DNA_object_types.h"
-#include "DNA_lamp_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_userdef_types.h"
@@ -64,268 +62,6 @@
 
 #include "3d_widgets/ui_widget_library.h"
 
-typedef struct LampPositionData {
-	int pos[2];
-	float quat[4];
-	float lvec[3];
-} LampPositionData;
-
-/* Modal Operator init */
-static int lamp_position_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
-	Object *ob = CTX_data_active_object(C);	
-	LampPositionData *data;
-	data = op->customdata = MEM_mallocN(sizeof (LampPositionData), "lamp_position_data");
-	
-	copy_v2_v2_int(data->pos, event->mval);
-
-	mat4_to_quat(data->quat, ob->obmat);
-	copy_v3_v3(data->lvec, ob->obmat[2]);
-	negate_v3(data->lvec);
-	normalize_v3(data->lvec);
-	
-	WM_event_add_modal_handler(C, op);
-	
-	return OPERATOR_RUNNING_MODAL;
-}
-
-/* Repeat operator */
-static int lamp_position_modal(bContext *C, wmOperator *op, const wmEvent *event)
-{
-	
-	LampPositionData *data = op->customdata;
-	
-	switch (event->type) {
-		case MOUSEMOVE:
-		{
-			Object *ob = CTX_data_active_object(C);	
-			Lamp *la = ob->data;			
-			Scene *scene = CTX_data_scene(C);
-			ARegion *ar = CTX_wm_region(C);
-			View3D *v3d = CTX_wm_view3d(C);
-			float world_pos[3];
-			int flag = v3d->flag2;
-			
-			v3d->flag2 |= V3D_RENDER_OVERRIDE;
-
-			view3d_operator_needs_opengl(C);
-			if (ED_view3d_autodist(scene, ar, v3d, event->mval, world_pos, true, NULL)) {
-				float axis[3];
-
-				/* restore the floag here */				
-				v3d->flag2 = flag;
-				
-				sub_v3_v3(world_pos, ob->obmat[3]);
-				la->dist = normalize_v3(world_pos);
-				
-				cross_v3_v3v3(axis, data->lvec, world_pos);
-				if (normalize_v3(axis) > 0.0001) {
-					float mat[4][4];
-					float quat[4], qfinal[4];
-					float angle = saacos(dot_v3v3(world_pos, data->lvec));
-
-					/* transform the initial rotation quaternion to the new position and set the matrix to the lamp */
-					axis_angle_to_quat(quat, axis, angle);
-					mul_qt_qtqt(qfinal, quat, data->quat);
-					quat_to_mat4(mat, qfinal);
-					copy_v3_v3(mat[3], ob->obmat[3]);
-					
-					BKE_object_apply_mat4(ob, mat, true, false);
-				}
-				
-				DAG_id_tag_update(&ob->id, OB_RECALC_OB);
-				
-				ED_region_tag_redraw(ar);
-			}
-			
-			v3d->flag2 = flag;
-			
-			break;
-		}
-			
-		case LEFTMOUSE:
-			if (event->val == KM_RELEASE) {
-				MEM_freeN(op->customdata);
-				return OPERATOR_FINISHED;
-			}
-	}
-
-	return OPERATOR_RUNNING_MODAL;
-}
-
-static int lamp_position_poll(bContext *C)
-{
-	return CTX_wm_region_view3d(C) != NULL;
-}
-
-
-void UI_OT_lamp_position(struct wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Lamp Position";
-	ot->idname = "UI_OT_lamp_position";
-	ot->description = "Sample a color from the Blender Window to store in a property";
-
-	/* api callbacks */
-	ot->invoke = lamp_position_invoke;
-	ot->modal = lamp_position_modal;
-	ot->poll = lamp_position_poll;
-
-	/* flags */
-	ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO;
-
-	/* properties */	
-}
-
-int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget)
-{	
-	
-	if (event->type == LEFTMOUSE && event->val == KM_PRESS && (widget->flag & WM_WIDGET_HIGHLIGHT)) {
-		struct PointerRNA *ptr = NULL;			/* rna pointer to access properties */
-		struct IDProperty *properties = NULL;	/* operator properties, assigned to ptr->data and can be written to a file */
-
-		WM_operator_properties_alloc(&ptr, &properties, "UI_OT_lamp_position");
-		WM_operator_name_call(C, "UI_OT_lamp_position", WM_OP_INVOKE_DEFAULT, ptr);
-		WM_operator_properties_free(ptr);
-		MEM_freeN(ptr);
-	}
-
-	return OPERATOR_FINISHED;
-}
-
-static void intern_lamp_draw(const struct bContext *C, int selectoffset, wmWidget *widget)
-{
-	ARegion *ar = CTX_wm_region(C);
-	RegionView3D *rv3d = ar->regiondata;
-	float size = 0.30f;
-
-	Object *ob = CTX_data_active_object(C);
-	Lamp *la = ob->data;
-	
-	float widgetmat[4][4];	
-
-	copy_m4_m4(widgetmat, ob->obmat);	
-	normalize_m4(widgetmat);
-	glPushMatrix();
-	glMultMatrixf(&widgetmat[0][0]);
-
-	glDisable(GL_CULL_FACE);
-	glEnable(GL_BLEND);
-
-	if (selectoffset != -1)
-		GPU_select_load_id(selectoffset);
-	glShadeModel(GL_SMOOTH);
-	glBegin(GL_LINES);
-	
-	if (widget->flag & WM_WIDGET_HIGHLIGHT)
-		glColor4f(1.0, 1.0, 0.4, 1.0);
-	else
-		glColor4f(1.0, 1.0, 1.0, 1.0);
-	glVertex3f(0.0, 0.0, 0.0);
-	if (widget->flag & WM_WIDGET_HIGHLIGHT)
-		glColor4f(1.0, 1.0, 2.0, 1.0);
-	else
-		glColor4f(0.0, 0.0, 0.0, 0.0);
-	glVertex3f(0.0, 0.0, -la->dist);
-	glEnd();	
-
-	glDisable(GL_BLEND);	
-	
-	glPopMatrix();
-	mul_mat3_m4_fl(widgetmat, ED_view3d_pixel_size(rv3d, widgetmat[3]) * U.tw_size);	
-	
-	glPushMatrix();
-	glMultMatrixf(&widgetmat[0][0]);
-
-	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-	glBegin(GL_QUAD_STRIP);
-	glVertex3f(size, size, 3.0 * size);
-	glVertex3f(-size, size, 3.0 * size);
-	glVertex3f(size, -size, 3.0 * size);
-	glVertex3f(-size, -size, 3.0 * size);
-	glVertex3f(size, -size, 0.0);
-	glVertex3f(-size, -size, 0.0);
-	glVertex3f(size, size, 0.0);
-	glVertex3f(-size, size, 0.0);
-	glVertex3f(size, size, 3.0 * size);
-	glVertex3f(-size, size, 3.0 * size);
-	glEnd();
-	
-	glPushMatrix();
-	glTranslatef(size, 0.0f, 0.0f);	
-	glRotatef(-90.0f * la->spotsize / M_PI, 0.0f, 1.0f, 0.0f);
-	
-	glBegin(GL_QUADS);
-	glVertex3f(0.0f, -size, 0.0);
-	glVertex3f(0.0f, size, 0.0);
-	glVertex3f(0.0f, size, -size);
-	glVertex3f(0.0f, -size, -size);	
-	glEnd();
-	glPopMatrix();	
-
-	glPushMatrix();
-	glTranslatef(-size, 0.0f, 0.0f);
-	glRotatef(90.0f * la->spotsize / M_PI, 0.0f, 1.0f, 0.0f);
-	
-	glBegin(GL_QUADS);
-	glVertex3f(0.0f, -size, 0.0);
-	glVertex3f(0.0f, size, 0.0);
-	glVertex3f(0.0f, size, -size);
-	glVertex3f(0.0f, -size, -size);	
-	glEnd();
-	glPopMatrix();	
-
-	glPushMatrix();
-	glTranslatef(0.0f, size, 0.0f);
-	glRotatef(90.0f * la->spotsize / M_PI, 1.0f, 0.0f, 0.0f);
-	
-	glBegin(GL_QUADS);
-	glVertex3f(-size, 0.0f, 0.0f);
-	glVertex3f(size, 0.0f, 0.0f);
-	glVertex3f(size, 0.0f, -size);
-	glVertex3f(-size, 0.0f, -size);	
-	glEnd();
-	glPopMatrix();	
-
-	glPushMatrix();
-	glTranslatef(0.0f, -size, 0.0f);
-	glRotatef(-90.0f * la->spotsize / M_PI, 1.0f, 0.0f, 0.0f);
-	
-	glBegin(GL_QUADS);
-	glVertex3f(-size, 0.0f, 0.0f);
-	glVertex3f(size, 0.0f, 0.0f);
-	glVertex3f(size, 0.0f, -size);
-	glVertex3f(-size, 0.0f, -size);	
-	glEnd();
-	glPopMatrix();	
-	
-	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-	
-	glPopMatrix();	
-}
-
-void WIDGET_lamp_render_3d_intersect(const struct bContext *C, struct wmWidget *widget, float UNUSED(scale), int selectionbase)
-{
-	intern_lamp_draw(C, selectionbase, widget);	
-}
-
-void WIDGET_lamp_draw(wmWidget *widget, const struct bContext *C, float UNUSED(scale))
-{
-	intern_lamp_draw(C, -1, widget);
-}
-
-bool WIDGETGROUP_lamp_poll(struct wmWidgetGroup *UNUSED(widget), const struct bContext *C)
-{
-	Object *ob = CTX_data_active_object(C);
-	
-	if (ob && ob->type == OB_LAMP) {
-		Lamp *la = ob->data;
-		return (la->type == LA_SPOT);      
-	}
-	return false;
-}
-
-
 
 /******************************************************
  *            GENERIC WIDGET LIBRARY                  *
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 43d2507..817445c 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -950,6 +950,4 @@ void UI_buttons_operatortypes(void)
 	/* external */
 	WM_operatortype_append(UI_OT_eyedropper_color);
 	WM_operatortype_append(UI_OT_eyedropper_id);
-	
-	WM_operatortype_append(UI_OT_lamp_position);
 }
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list