Commit: f31819b5f6fbd34f48fa1a8863b28e75f4d151ac
Author: Julian Eisel
Date:   Thu Dec 24 23:37:11 2015 +0100
Branches: temp_widgets_c++_experiment
https://developer.blender.org/rBf31819b5f6fbd34f48fa1a8863b28e75f4d151ac

Correction to previous correction

Forgot to use 'git add'. Sry for the noise.

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

A       source/blender/windowmanager/widgets/wm_generic_widgets.c

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

diff --git a/source/blender/windowmanager/widgets/wm_generic_widgets.c 
b/source/blender/windowmanager/widgets/wm_generic_widgets.c
new file mode 100644
index 0000000..514dcea
--- /dev/null
+++ b/source/blender/windowmanager/widgets/wm_generic_widgets.c
@@ -0,0 +1,1639 @@
+/*
+ * ***** 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) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/widgets/wm_generic_widgets.c
+ *  \ingroup wm
+ *
+ * *****************************************************
+ *                GENERIC WIDGET LIBRARY                
+ * *****************************************************
+ */
+
+#include "RNA_types.h"
+#include "RNA_access.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_object_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_widget_types.h"
+
+#include "BLI_listbase.h"
+#include "BLI_utildefines.h"
+#include "BLI_math_matrix.h"
+#include "BLI_math.h"
+#include "BLI_rect.h"
+
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_object.h"
+
+#include "ED_view3d.h"
+#include "ED_screen.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+
+#include "GL/glew.h"
+#include "GPU_select.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "UI_interface.h"
+
+#include "widgets/3d_widgets/wm_widget_library.h"
+
+#include "wm.h"
+#include "WM_types.h"
+
+
+/* to use custom arrows exported to arrow_widget.c */
+//#define WIDGET_USE_CUSTOM_ARROWS
+/* to use custom dials exported to dial_widget.c */
+//#define WIDGET_USE_CUSTOM_DIAS
+
+
+/* -------------------------------------------------------------------- */
+/* Widget drawing */
+
+typedef struct WidgetDrawInfo {
+       int nverts;
+       int ntris;
+       float (*verts)[3];
+       float (*normals)[3];
+       unsigned short *indices;
+       bool init;
+} WidgetDrawInfo;
+
+
+#ifdef WIDGET_USE_CUSTOM_ARROWS
+WidgetDrawInfo arrow_head_draw_info = {0};
+#endif
+WidgetDrawInfo cube_draw_info = {0};
+#ifdef WIDGET_USE_CUSTOM_DIAS
+WidgetDrawInfo dial_draw_info = {0};
+#endif
+
+/**
+ * Main draw call for WidgetDrawInfo data
+ */
+static void widget_draw_intern(WidgetDrawInfo *info, const bool select)
+{
+       GLuint buf[3];
+
+       const bool use_lighting = !select && ((U.tw_flag & V3D_SHADED_WIDGETS) 
!= 0);
+
+       if (use_lighting)
+               glGenBuffers(3, buf);
+       else
+               glGenBuffers(2, buf);
+
+       glEnableClientState(GL_VERTEX_ARRAY);
+       glBindBuffer(GL_ARRAY_BUFFER, buf[0]);
+       glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * info->nverts, 
info->verts, GL_STATIC_DRAW);
+       glVertexPointer(3, GL_FLOAT, 0, NULL);
+
+       if (use_lighting) {
+               glEnableClientState(GL_NORMAL_ARRAY);
+               glBindBuffer(GL_ARRAY_BUFFER, buf[2]);
+               glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * info->nverts, 
info->normals, GL_STATIC_DRAW);
+               glNormalPointer(GL_FLOAT, 0, NULL);
+               glShadeModel(GL_SMOOTH);
+       }
+
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf[1]);
+       glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * (3 * 
info->ntris), info->indices, GL_STATIC_DRAW);
+
+       glEnable(GL_CULL_FACE);
+       glEnable(GL_DEPTH_TEST);
+
+       glDrawElements(GL_TRIANGLES, info->ntris * 3, GL_UNSIGNED_SHORT, NULL);
+
+       glDisable(GL_DEPTH_TEST);
+       glDisable(GL_CULL_FACE);
+
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+       glDisableClientState(GL_VERTEX_ARRAY);
+
+       if (use_lighting) {
+               glDisableClientState(GL_NORMAL_ARRAY);
+               glShadeModel(GL_FLAT);
+               glDeleteBuffers(3, buf);
+       }
+       else {
+               glDeleteBuffers(2, buf);
+       }
+}
+
+
+/* -------------------------------------------------------------------- */
+/* Widget defines */
+
+/** \name Arrow Widget
+ *
+ * 3D Widget
+ *
+ * \brief Simple arrow widget which is dragged into a certain direction.
+ * The arrow head can have varying shapes, e.g. cone, box, etc.
+ *
+ * \{ */
+
+/* ArrowWidget->flag */
+enum {
+       ARROW_UP_VECTOR_SET    = (1 << 0),
+       ARROW_CUSTOM_RANGE_SET = (1 << 1),
+};
+
+typedef struct ArrowWidget {
+       wmWidget widget;
+       int style;
+       int flag;
+
+       float len;          /* arrow line length */
+       float direction[3];
+       float up[3];
+       float aspect[2];    /* cone style only */
+
+       float range_fac;      /* factor for arrow min/max distance */
+       float offset;
+       /* property range and minimum for constrained arrows */
+       float range, min;
+} ArrowWidget;
+
+typedef struct ArrowInteraction {
+       float orig_value; /* initial property value */
+       float orig_origin[3];
+       float orig_mouse[2];
+       float orig_offset;
+       float orig_scale;
+
+       /* offset of last handling step */
+       float prev_offset;
+       /* Total offset added by precision tweaking.
+        * Needed to allow toggling precision on/off without causing jumps */
+       float precision_offset;
+} ArrowInteraction;
+
+/* factor for precision tweaking */
+#define ARROW_PRECISION_FAC 0.05f
+
+
+static void widget_arrow_get_final_pos(wmWidget *widget, float r_pos[3])
+{
+       ArrowWidget *arrow = (ArrowWidget *)widget;
+
+       mul_v3_v3fl(r_pos, arrow->direction, arrow->offset);
+       add_v3_v3(r_pos, arrow->widget.origin);
+}
+
+static void arrow_draw_geom(const ArrowWidget *arrow, const bool select)
+{
+       if (arrow->style & WIDGET_ARROW_STYLE_CROSS) {
+               glPushAttrib(GL_ENABLE_BIT);
+               glDisable(GL_LIGHTING);
+               glBegin(GL_LINES);
+               glVertex2f(-1.0, 0.f);
+               glVertex2f(1.0, 0.f);
+               glVertex2f(0.f, -1.0);
+               glVertex2f(0.f, 1.0);
+               glEnd();
+
+               glPopAttrib();
+       }
+       else if (arrow->style & WIDGET_ARROW_STYLE_CONE) {
+               const float unitx = arrow->aspect[0];
+               const float unity = arrow->aspect[1];
+               const float vec[4][3] = {
+                       {-unitx, -unity, 0},
+                       { unitx, -unity, 0},
+                       { unitx,  unity, 0},
+                       {-unitx,  unity, 0},
+               };
+
+               glLineWidth(arrow->widget.line_width);
+               glEnableClientState(GL_VERTEX_ARRAY);
+               glVertexPointer(3, GL_FLOAT, 0, vec);
+               glDrawArrays(GL_LINE_LOOP, 0, ARRAY_SIZE(vec));
+               glDisableClientState(GL_VERTEX_ARRAY);
+               glLineWidth(1.0);
+       }
+       else {
+#ifdef WIDGET_USE_CUSTOM_ARROWS
+               widget_draw_intern(&arrow_head_draw_info, select);
+#else
+               const float vec[2][3] = {
+                       {0.0f, 0.0f, 0.0f},
+                       {0.0f, 0.0f, arrow->len},
+               };
+
+               glLineWidth(arrow->widget.line_width);
+               glEnableClientState(GL_VERTEX_ARRAY);
+               glVertexPointer(3, GL_FLOAT, 0, vec);
+               glDrawArrays(GL_LINE_STRIP, 0, ARRAY_SIZE(vec));
+               glDisableClientState(GL_VERTEX_ARRAY);
+               glLineWidth(1.0);
+
+
+               /* *** draw arrow head *** */
+
+               glPushMatrix();
+
+               if (arrow->style & WIDGET_ARROW_STYLE_BOX) {
+                       const float size = 0.05f;
+
+                       /* translate to line end with some extra offset so box 
starts exactly where line ends */
+                       glTranslatef(0.0f, 0.0f, arrow->len + size);
+                       /* scale down to box size */
+                       glScalef(size, size, size);
+
+                       /* draw cube */
+                       widget_draw_intern(&cube_draw_info, select);
+               }
+               else {
+                       GLUquadricObj *qobj = gluNewQuadric();
+                       const float len = 0.25f;
+                       const float width = 0.06f;
+                       const bool use_lighting = select == false && 
((U.tw_flag & V3D_SHADED_WIDGETS) != 0);
+
+                       /* translate to line end */
+                       glTranslatef(0.0f, 0.0f, arrow->len);
+
+                       if (use_lighting) {
+                               glShadeModel(GL_SMOOTH);
+                       }
+
+                       gluQuadricDrawStyle(qobj, GLU_FILL);
+                       gluQuadricOrientation(qobj, GLU_INSIDE);
+                       gluDisk(qobj, 0.0, width, 8, 1);
+                       gluQuadricOrientation(qobj, GLU_OUTSIDE);
+                       gluCylinder(qobj, width, 0.0, len, 8, 1);
+
+                       if (use_lighting) {
+                               glShadeModel(GL_FLAT);
+                       }
+               }
+
+               glPopMatrix();
+#endif
+       }
+}
+
+static void arrow_draw_intern(ArrowWidget *arrow, const bool select, const 
bool highlight)
+{
+       const float up[3] = {0.0f, 0.0f, 1.0f};
+       float rot[3][3];
+       float mat[4][4];
+       float final_pos[3];
+
+       widget_arrow_get_final_pos(&arrow->widget, final_pos);
+
+       if (arrow->flag & ARROW_UP_VECTOR_SET) {
+               copy_v3_v3(rot[2], arrow->direction);
+               copy_v3_v3(rot[1], arrow->up);
+               cross_v3_v3v3(rot[0], arrow->up, arrow->direction);
+       }
+       else {
+               rotation_between_vecs_to_mat3(rot, up, arrow->direction);
+       }
+       copy_m4_m3(mat, rot);
+       copy_v3_v3(mat[3], final_pos);
+       mul_mat3_m4_fl(mat, arrow->widget.scale);
+
+       glPushMatrix();
+       glMultMatrixf(mat);
+
+       if (highlight && !(arrow->widget.flag & WM_WIDGET_DRAW_HOVER)) {
+               glColor4fv(arrow->widget.col_hi);
+       }
+       else {
+               glColor4fv(arrow->widget.col);
+       }
+
+       glEnable(GL_BLEND);
+       glTranslate3fv(arrow->widget.offset);
+       arrow_draw_geom(arrow, select);
+       glDisable(GL_BLEND);
+
+       glPopMatrix();
+
+       if (arrow->widget.interaction_data) {
+               ArrowInteraction *data = arrow->widget.interaction_data;
+
+               copy_m4_m3(mat, rot);
+               copy_v3_v3(mat[3], data->orig_origin);
+               mul_mat3_m4_fl(mat, data->orig_scale);
+
+               glPushMatrix();
+               glMultMatrixf(mat);
+
+               glEnable(GL_BLEND);
+               glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
+               glTranslate3fv(arrow->widget.offset);
+               arrow_draw_geom(arrow, select);
+               glDisable(GL_BLEND);
+
+               glPopMatrix();
+       }
+}
+
+static void widget_arrow_render_3d_intersect(const bContext *UNUSED(C), 
wmWidget *widget, int selectionbase)
+{
+       GPU_select_load_id(selectionbase);
+       arrow_draw_intern((ArrowWidget *)widget, true, false);
+}
+
+static void widget_arrow_draw(const bContext *UNUSED(C), wmWidget *widget)
+{
+       arrow_draw_intern((ArrowWidget *)widget, false, (widget->flag & 
WM_WIDGET_HIGHLIGHT) != 0);
+}
+
+/**
+ * Calculate arrow offset independent from prop min value,
+ * meaning the range will not be offset by min value first.
+

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to