Commit: ce9603e3822a6e6b4b0d36a640b545b5b1dd3be4
Author: Antony Riakiotakis
Date:   Fri Oct 3 19:11:24 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBce9603e3822a6e6b4b0d36a640b545b5b1dd3be4

WIP, operator to tweak the lamp "focus", driven through widgets.

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

M       source/blender/editors/interface/interface_generic_widgets.c
M       source/blender/editors/interface/interface_intern.h
M       source/blender/editors/interface/interface_ops.c

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

diff --git a/source/blender/editors/interface/interface_generic_widgets.c 
b/source/blender/editors/interface/interface_generic_widgets.c
index a19dc06..055c6f5 100644
--- a/source/blender/editors/interface/interface_generic_widgets.c
+++ b/source/blender/editors/interface/interface_generic_widgets.c
@@ -45,16 +45,99 @@
 #include "ED_view3d.h"
 
 #include "WM_types.h"
+#include "WM_api.h"
 
 #include "GL/glew.h"
 #include "GPU_select.h"
 
 #include "BIF_glutil.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "UI_interface.h"
+#include "interface_intern.h"
+
+
+typedef struct LampPositionData {
+       int pos[2];
+       float quat[4];
+} 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);
+       
+       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)
+{
+       switch (event->type) {
+               case MOUSEMOVE:
+               {
+                       Object *ob = CTX_data_active_object(C); 
+                       Lamp *la = ob->data;
+                       
+                       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;
+
+       /* properties */        
+}
 
 int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, 
struct wmWidget *widget, int active)
 {      
+       
+       if (event->type == LEFTMOUSE && event->val == KM_PRESS && active == 1) {
+               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;
 }
 
diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index 2f66c4a..4cd2c90 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -674,4 +674,8 @@ void ui_but_anim_autokey(struct bContext *C, uiBut *but, 
struct Scene *scene, fl
 void UI_OT_eyedropper_color(struct wmOperatorType *ot);
 void UI_OT_eyedropper_id(struct wmOperatorType *ot);
 
+
+/* interface_generic_widgets.c */
+void UI_OT_lamp_position(struct wmOperatorType *ot);
+
 #endif  /* __INTERFACE_INTERN_H__ */
diff --git a/source/blender/editors/interface/interface_ops.c 
b/source/blender/editors/interface/interface_ops.c
index 817445c..43d2507 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -950,4 +950,6 @@ 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);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to