[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17085] branches/nurbs/blender/source/ blender: Ad knot editor into nurbs edit panel
Hamed Zaghaghi
hamed.zaghaghi at gmail.com
Wed Oct 15 19:58:03 CEST 2008
Revision: 17085
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17085
Author: zaghaghi
Date: 2008-10-15 19:58:03 +0200 (Wed, 15 Oct 2008)
Log Message:
-----------
Ad knot editor into nurbs edit panel
Modified Paths:
--------------
branches/nurbs/blender/source/blender/include/BIF_interface.h
branches/nurbs/blender/source/blender/include/butspace.h
branches/nurbs/blender/source/blender/makesdna/DNA_curve_types.h
branches/nurbs/blender/source/blender/src/buttons_editing.c
branches/nurbs/blender/source/blender/src/interface.c
branches/nurbs/blender/source/blender/src/interface_draw.c
Modified: branches/nurbs/blender/source/blender/include/BIF_interface.h
===================================================================
--- branches/nurbs/blender/source/blender/include/BIF_interface.h 2008-10-14 23:43:08 UTC (rev 17084)
+++ branches/nurbs/blender/source/blender/include/BIF_interface.h 2008-10-15 17:58:03 UTC (rev 17085)
@@ -165,6 +165,7 @@
#define ICONTOGN (34<<9)
#define FTPREVIEW (35<<9)
#define NUMABS (36<<9)
+#define BUT_FLOATBAND (37<<9)
#define BUTTYPE (63<<9)
Modified: branches/nurbs/blender/source/blender/include/butspace.h
===================================================================
--- branches/nurbs/blender/source/blender/include/butspace.h 2008-10-14 23:43:08 UTC (rev 17084)
+++ branches/nurbs/blender/source/blender/include/butspace.h 2008-10-15 17:58:03 UTC (rev 17085)
@@ -500,6 +500,7 @@
#define B_REFINECURVE 2135
#define B_SETRESOL 2136
#define B_SUBDIVCURVEV 2137
+#define B_SETKNOTS 2138
/* *********************** */
#define B_FONTBUTS 2300
Modified: branches/nurbs/blender/source/blender/makesdna/DNA_curve_types.h
===================================================================
--- branches/nurbs/blender/source/blender/makesdna/DNA_curve_types.h 2008-10-14 23:43:08 UTC (rev 17084)
+++ branches/nurbs/blender/source/blender/makesdna/DNA_curve_types.h 2008-10-15 17:58:03 UTC (rev 17085)
@@ -126,7 +126,7 @@
short knottypeu,knottypev;
char pad3;
char pad4;
- int pad5;
+ short cur_knotv,cur_knotu; /* current knot, will be used in knot editor */
// float *tessBuffer;
void *nurbanaPtr;
} Nurb;
Modified: branches/nurbs/blender/source/blender/src/buttons_editing.c
===================================================================
--- branches/nurbs/blender/source/blender/src/buttons_editing.c 2008-10-14 23:43:08 UTC (rev 17084)
+++ branches/nurbs/blender/source/blender/src/buttons_editing.c 2008-10-15 17:58:03 UTC (rev 17085)
@@ -3285,6 +3285,10 @@
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
allqueue(REDRAWVIEW3D, 0);
break;
+ case B_SETKNOTS:
+ DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
+ allqueue(REDRAWVIEW3D, 0);
+ break;
case B_SUBSURFTYPE:
/* fallthrough */
case B_MAKEDISP:
@@ -3493,6 +3497,80 @@
}
+static void draw_floatband_buts(uiBlock *block, float *floats, int count, short* cur, int xoffs, int yoffs, int redraw, int event)
+{
+ uiBut *bt;
+
+ if(floats==NULL) return;
+
+ bt= uiDefBut(block, BUT, redraw, "Add", 80+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Adds a new point");
+// uiButSetFunc(bt, colorband_add_cb, coba, NULL);
+
+ uiDefButS(block, NUM, redraw, "Cur:", 118+xoffs,95+yoffs,81,20, cur, 0.0, count-1, 0, 0, "Displays the active point");
+
+ uiDefButF(block, NUM, event, "Value:", 200+xoffs,95+yoffs,101,20, &(floats[*cur]),
+ (((*cur)<=0)?0.0:floats[(*cur)-1]),
+ (((*cur)>=count-1)?(float)count-1.0:floats[(*cur)+1]),
+ 10.0, 0, "Displays the active point value");
+
+ bt= uiDefBut(block, BUT, redraw, "Del", 302+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Deletes the active point");
+// uiButSetFunc(bt, colorband_del_cb, coba, NULL);
+
+ uiDefBut(block, BUT_FLOATBAND, event, "Knot Editor", 80+xoffs,60+yoffs,259, 34, floats, 0.00, (float)count, (float)(*cur), (float)count, "Change knot values.");
+
+}
+
+static void editing_panel_curve_knot_tools(Object *ob, Curve *cu)
+{
+ uiBlock *block;
+
+ Nurb *nu, *sel_nu = NULL;
+
+ /* finding selected nurb in editNurb */
+ nu= editNurb.first;
+ while(nu) {
+ if( isNurbsel(nu) && nu->bp ){
+ sel_nu = nu;
+ break;
+ }
+ nu= nu->next;
+ }
+
+ block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_knot_tools", UI_EMBOSS, UI_HELV, curarea->win);
+
+ uiNewPanelTabbed("Curve Tools", "Editing");
+
+ if(uiNewPanel(curarea, block, "Knot Editor", "Editing", 960, 0, 318, 204)==0) return;
+
+ /* there isn't any NURB selected */
+ if(sel_nu==NULL) return;
+
+ /* selected curve is not a NURB*/
+ if(!(ELEM(ob->type, OB_CURVE, OB_SURF))) return;
+
+ /* knotsu editor */
+ if ( ELEM(ob->type, OB_CURVE, OB_SURF) )
+ {
+ if(sel_nu->cur_knotu < 0 )
+ sel_nu->cur_knotu = 0;
+ else if (sel_nu->cur_knotu >= KNOTSU(sel_nu))
+ sel_nu->cur_knotu = KNOTSU(sel_nu)-1;
+ draw_floatband_buts(block, sel_nu->knotsu, KNOTSU(sel_nu), &(sel_nu->cur_knotu), 0,0, REDRAWALL, B_SETKNOTS);
+ }
+
+ /* knotsv editor */
+ if( ob->type == OB_SURF )
+ {
+ if(sel_nu->cur_knotv < 0 )
+ sel_nu->cur_knotv = 0;
+ else if (sel_nu->cur_knotv >= KNOTSV(sel_nu))
+ sel_nu->cur_knotv = KNOTSV(sel_nu)-1;
+
+ draw_floatband_buts(block, sel_nu->knotsv, KNOTSV(sel_nu), &(sel_nu->cur_knotv), 0,80, REDRAWALL, B_SETKNOTS);
+
+ }
+}
+
static void editing_panel_curve_tools1(Object *ob, Curve *cu)
{
uiBlock *block;
@@ -6721,6 +6799,7 @@
// editing_panel_shapes(ob);
if(G.obedit) {
editing_panel_curve_tools(ob, cu);
+ editing_panel_curve_knot_tools(ob, cu);
editing_panel_curve_tools1(ob, cu);
editing_panel_curve_tools2(ob, cu);
}
Modified: branches/nurbs/blender/source/blender/src/interface.c
===================================================================
--- branches/nurbs/blender/source/blender/src/interface.c 2008-10-14 23:43:08 UTC (rev 17084)
+++ branches/nurbs/blender/source/blender/src/interface.c 2008-10-15 17:58:03 UTC (rev 17085)
@@ -3560,6 +3560,72 @@
return but->retval;
}
+static int cmpfloatband (const void * a, const void * b)
+{
+ if ( *(float*)a > *(float*)b ) return 1;
+ else if ( *(float*)a < *(float*)b ) return -1;
+ else return 0;
+}
+
+static void do_floatband_evt(float *points, int size)
+{
+ if(points == NULL) return;
+
+ if(size <= 1) return;
+
+ qsort(points, size, sizeof(float), cmpfloatband);
+
+ addqueue(curarea->win, REDRAW, 0);
+}
+
+static int ui_do_but_FLOATBAND(uiBut *but)
+{
+ float* points= (float *)but->poin;
+ float dx, width= but->x2-but->x1;
+ int a;
+ int mindist= 12, xco;
+ short mval[2], mvalo[2];
+
+ uiGetMouse(mywinget(), mvalo);
+
+ if(G.qual & LR_CTRLKEY) {
+ /* no insertion currently through Ctrl+Click */
+ }
+ else {
+ /* first, activate new key when mouse is close */
+ for(a=0; a<((int)but->a2); a++) {
+ xco= but->x1 + ((points[a]-but->min)/(but->max-but->min) * width);
+ xco= ABS(xco-mvalo[0]);
+ if(a==(int)but->a1) xco+= 5; // selected one disadvantage
+ if(xco<mindist) {
+ but->a1=(float) a;
+ mindist= xco;
+ }
+ }
+
+
+ while(get_mbut() & L_MOUSE) {
+ uiGetMouse(mywinget(), mval);
+ if(mval[0]!=mvalo[0]) {
+ dx= mval[0]-mvalo[0];
+ dx= dx*(but->max-but->min)/width;
+ points[(int)but->a1] += dx;
+ CLAMP(points[(int)but->a1], but->min, but->max);
+
+ ui_draw_but(but);
+ ui_block_flush_back(but->block);
+
+ do_floatband_evt(points,(int)(but->a2));
+
+ mvalo[0]= mval[0];
+ }
+ BIF_wait_for_statechange();
+ }
+ }
+
+ return but->retval;
+}
+
/* button is presumed square */
/* if mouse moves outside of sphere, it does negative normal */
static int ui_do_but_NORMAL(uiBut *but)
@@ -4013,6 +4079,9 @@
case BUT_COLORBAND:
retval= ui_do_but_COLORBAND(but);
break;
+ case BUT_FLOATBAND:
+ retval= ui_do_but_FLOATBAND(but);
+ break;
case BUT_NORMAL:
retval= ui_do_but_NORMAL(but);
break;
Modified: branches/nurbs/blender/source/blender/src/interface_draw.c
===================================================================
--- branches/nurbs/blender/source/blender/src/interface_draw.c 2008-10-14 23:43:08 UTC (rev 17084)
+++ branches/nurbs/blender/source/blender/src/interface_draw.c 2008-10-15 17:58:03 UTC (rev 17085)
@@ -2098,6 +2098,80 @@
glEnd();
}
+static void ui_draw_but_FLOATBAND(uiBut *but)
+{
+ float *points= (float*)but->poin;
+
+ float x1, y1, sizex, sizey;
+ short cur = (short)(but->a1);
+ int count = (int)(but->a2);
+
+ float dx, v3[2], v1[2], v2[2], v1a[2], v2a[2];
+ int a;
+
+ if(points==NULL) return;
+
+ x1= but->x1;
+ y1= but->y1;
+ sizex= but->x2-but->x1;
+ sizey= but->y2-but->y1;
+
+ glColor3f(0.8, 0.8, 0.8);
+ glRectf(x1, y1, x1+sizex, y1+sizey);
+
+ /* outline */
+ v1[0]= x1; v1[1]= y1;
+
+ cpack(0x0);
+ glBegin(GL_LINE_LOOP);
+ glVertex2fv(v1);
+ v1[0]+= sizex;
+ glVertex2fv(v1);
+ v1[1]+= sizey;
+ glVertex2fv(v1);
+ v1[0]-= sizex;
+ glVertex2fv(v1);
+ glEnd();
+
+
+ /* help lines */
+ v1[0]= v2[0]=v3[0]= x1;
+ v1[1]= y1;
+ v1a[1]= y1+0.25*sizey;
+ v2[1]= y1+0.5*sizey;
+ v2a[1]= y1+0.75*sizey;
+ v3[1]= y1+sizey;
+
+
+ glBegin(GL_LINES);
+ for(a=0; a<count; a++) {
+ v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]=
+ x1+ (points[a]-but->min)/(but->max-but->min)*sizex;
+
+ if(a==cur) {
+ glColor3ub(0, 0, 0);
+ glVertex2fv(v1);
+ glVertex2fv(v3);
+ glEnd();
+
+ setlinestyle(2);
+ glBegin(GL_LINES);
+ glColor3ub(255, 255, 255);
+ glVertex2fv(v1);
+ glVertex2fv(v3);
+ glEnd();
+ setlinestyle(0);
+ glBegin(GL_LINES);
+ }
+ else {
+ glColor3ub(0, 0, 0);
+ glVertex2fv(v1);
+ glVertex2fv(v3);
+ }
+ }
+ glEnd();
+}
+
static void ui_draw_but_NORMAL(uiBut *but)
{
static GLuint displist=0;
@@ -2469,6 +2543,9 @@
case BUT_COLORBAND:
ui_draw_but_COLORBAND(but);
break;
+ case BUT_FLOATBAND:
+ ui_draw_but_FLOATBAND(but);
+ break;
case BUT_NORMAL:
ui_draw_but_NORMAL(but);
break;
More information about the Bf-blender-cvs
mailing list