[Bf-blender-cvs] [37a7421] wiggly-widgets: Lamp widget:
Antony Riakiotakis
noreply at git.blender.org
Fri Oct 3 17:11:12 CEST 2014
Commit: 37a7421e10afcf2b1394210d5c6afacf224fc311
Author: Antony Riakiotakis
Date: Fri Oct 3 17:11:01 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB37a7421e10afcf2b1394210d5c6afacf224fc311
Lamp widget:
* Make a lamp widget design for the active lamp.
* Fix some handler errors for widgets + autoupdate for different widget
handles.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface_generic_widgets.c
M source/blender/editors/space_view3d/space_view3d.c
M source/blender/editors/transform/transform_manipulator.c
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_widgets.c
M source/blender/windowmanager/wm_event_system.h
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index f262e1b..ee9adbb 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -78,6 +78,7 @@ struct bNodeSocket;
struct wmDropBox;
struct wmDrag;
struct wmEvent;
+struct wmWidget;
typedef struct uiBut uiBut;
typedef struct uiBlock uiBlock;
diff --git a/source/blender/editors/interface/interface_generic_widgets.c b/source/blender/editors/interface/interface_generic_widgets.c
index f98102f..a19dc06 100644
--- a/source/blender/editors/interface/interface_generic_widgets.c
+++ b/source/blender/editors/interface/interface_generic_widgets.c
@@ -34,9 +34,11 @@
#include "DNA_object_types.h"
#include "DNA_lamp_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
#include "BLI_utildefines.h"
#include "BLI_math_matrix.h"
+#include "BLI_math.h"
#include "BKE_context.h"
@@ -45,59 +47,151 @@
#include "WM_types.h"
#include "GL/glew.h"
+#include "GPU_select.h"
+
+#include "BIF_glutil.h"
#include "UI_interface.h"
int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, int active)
-{
- return 0;
+{
+ return OPERATOR_FINISHED;
}
-void WIDGET_lamp_render_3d_intersect(const struct bContext *C, struct wmWidget *widget, int selectionbase)
-{
-
-}
-
-void WIDGET_lamp_draw(const struct bContext *C, struct wmWidget *widget)
+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;
+ int highlight = widget->active_handle;
Object *ob = CTX_data_active_object(C);
Lamp *la = ob->data;
float widgetmat[4][4];
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
copy_m4_m4(widgetmat, ob->obmat);
normalize_m4(widgetmat);
- mul_mat3_m4_fl(widgetmat, ED_view3d_pixel_size(rv3d, widgetmat[3]) * U.tw_size);
-
+ glPushMatrix();
glMultMatrixf(&widgetmat[0][0]);
-
- glDisable(GL_DEPTH_TEST);
+
glDisable(GL_CULL_FACE);
+ glEnable(GL_BLEND);
+ if (selectoffset != -1)
+ GPU_select_load_id(selectoffset + 1);
glShadeModel(GL_SMOOTH);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0, 0.0, 0.0);
- glVertex3f(0.0, 0.0, 1.0);
- glColor3f(0.0, 1.0, 0.0);
- glVertex3f(-1.0, 0.0, -1.0);
- glColor3f(0.0, 0.0, 1.0);
- glVertex3f(1.0, 0.0, -1.0);
+ glBegin(GL_LINES);
+
+ if (highlight == 1)
+ 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 (highlight == 1)
+ 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]);
+
+ if (highlight == 2)
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ else
+ glColor4f(0.8, 0.8, 0.8, 1.0);
+
+ if (selectoffset != -1)
+ GPU_select_load_id(selectoffset + 2);
+ 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, int selectionbase)
+{
+ intern_lamp_draw(C, selectionbase, widget);
+}
+
+void WIDGET_lamp_draw(const struct bContext *C, wmWidget *widget)
+{
+ intern_lamp_draw(C, -1, widget);
}
bool WIDGET_lamp_poll(const struct bContext *C, struct wmWidget *UNUSED(widget))
{
Object *ob = CTX_data_active_object(C);
- if (ob->type == OB_LAMP) {
+ if (ob && ob->type == OB_LAMP) {
Lamp *la = ob->data;
return (la->type == LA_SPOT);
}
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 7e71230..e0c166e 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -695,23 +695,19 @@ static void view3d_widgets(void)
{
wmWidget *widget = NULL;
struct wmWidgetMap *wmap = WM_widgetmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
- int *realtimeflags = MEM_mallocN(sizeof(int), "manipulator_display_flags");
- *realtimeflags = 0;
-
widget = WM_widget_new(WIDGET_manipulator_poll,
WIDGET_manipulator_draw,
WIDGET_manipulator_render_3d_intersect,
NULL,
- WIDGET_manipulator_handler, realtimeflags, true);
+ WIDGET_manipulator_handler, NULL, false);
WM_widget_register(wmap, widget);
- realtimeflags = MEM_mallocN(sizeof(int), "manipulator_display_flags");
widget = WM_widget_new(WIDGET_lamp_poll,
WIDGET_lamp_draw,
- WIDGET_manipulator_render_3d_intersect,
+ WIDGET_lamp_render_3d_intersect,
NULL,
- WIDGET_lamp_handler, realtimeflags, true);
+ WIDGET_lamp_handler, NULL, false);
WM_widget_register(wmap, widget);
}
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 49d9e8b..00477b4 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1629,6 +1629,27 @@ static void draw_manipulator_rotate_cyl(
/* main call, does calc centers & orientation too */
static int drawflags = 0xFFFF; // only for the calls below, belongs in scene...?
+static int manipulator_flags_from_active(int active)
+{
+ int val;
+
+ if (active != -1) {
+ if (active == MAN_SEL_TRANS_C) {
+ val = MAN_TRANS_C;
+ }
+ else if (active == MAN_SEL_SCALE_C) {
+ val = MAN_SCALE_C;
+ }
+ else {
+ val = 1 << active;
+ }
+ }
+ else
+ val = 0;
+
+ return val;
+}
+
void WIDGET_manipulator_draw(const bContext *C, wmWidget *widget)
{
ScrArea *sa = CTX_wm_area(C);
@@ -1640,7 +1661,7 @@ void WIDGET_manipulator_draw(const bContext *C, wmWidget *widget)
int highlight = 0;
if (widget->flag & WM_WIDGET_HIGHLIGHT)
- highlight = *((int *)widget->customdata);
+ highlight = manipulator_flags_from_active(widget->active_handle);
v3d->twflag &= ~V3D_DRAW_MANIPULATOR;
@@ -1744,38 +1765,19 @@ void WIDGET_manipulator_render_3d_intersect(const bContext *C, wmWidget *UNUSED(
}
/* return 0; nothing happened */
-int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidget *widget, int active)
+int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidget *UNUSED(widget), int active)
{
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = sa->spacedata.first;
- ARegion *ar = CTX_wm_region(C);
int constraint_axis[3] = {0, 0, 0};
int val;
int shift = event->shift;
- int *prevval = ((int *)widget->customdata);
struct IDProperty *properties = NULL; /* operator properties, assigned to ptr->data and can be written to a file */
struct PointerRNA *ptr = NULL; /* rna pointer to access properties */
-
- if (active != -1) {
- if (active == MAN_SEL_TRANS_C) {
- val = MAN_TRANS_C;
- }
- else if (active == MAN_SEL_SCALE_C) {
- val = MAN_SCALE_C;
- }
- else {
- val = 1 << active;
- }
- }
- else
- val = 0;
-
- if (*prevval != val) {
- *prevval = val;
- ED_region_tag_redraw(ar);
- }
+ val = manipulator_flags_from_active(active);
+
if (!((v3d->twflag & V3D_USE_MANIPULATOR) && (v3d->twflag & V3D_DRAW_MANIPULATOR)) ||
!(event->keymodifier == 0 || event->keymodifier == KM_SHIFT) ||
!((event->val == KM_PRESS) && (event->type == LEFTMOUSE)))
@@ -1784,11 +1786,8 @@ int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidge
}
if (val) {
- // drawflags still global, for drawing call above
- drawflags = val;//manipulator_selectbuf(sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
-
- if (drawflags & MAN_TRANS_C) {
- switch (drawflags) {
+ if (val & MAN_TRANS_C) {
+ switch (val) {
case MAN_TRANS_C:
break;
case MAN_TRANS_X:
@@ -1824,8 +1823,8 @@ int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidge
WM_operator_name_call(C, "TRANSFORM_OT_translate", WM_OP_INVOKE_DEFAULT, ptr);
//wm_operator_invoke(C, WM_operatortype_find("TRANSFORM_OT_translate", 0), event, op->ptr, NULL, false);
}
- else if (drawflags & MAN_SCALE_C) {
- switch (drawflags) {
+ else if (val & MAN_SCALE_C) {
+ switch (val) {
case MAN_SCALE_X:
if (shift) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list