Keying Sets: Initial commit of skeleton code
[blender.git] / source / blender / editors / space_view3d / view3d_buttons.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31 #include <math.h>
32 #include <float.h>
33
34 #include "DNA_action_types.h"
35 #include "DNA_armature_types.h"
36 #include "DNA_curve_types.h"
37 #include "DNA_camera_types.h"
38 #include "DNA_lamp_types.h"
39 #include "DNA_lattice_types.h"
40 #include "DNA_meta_types.h"
41 #include "DNA_mesh_types.h"
42 #include "DNA_meshdata_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_space_types.h"
45 #include "DNA_scene_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_userdef_types.h"
48 #include "DNA_view3d_types.h"
49 #include "DNA_world_types.h"
50
51 #include "MEM_guardedalloc.h"
52
53 #include "BLI_arithb.h"
54 #include "BLI_blenlib.h"
55 #include "BLI_editVert.h"
56 #include "BLI_rand.h"
57
58 #include "BKE_action.h"
59 #include "BKE_context.h"
60 #include "BKE_curve.h"
61 #include "BKE_customdata.h"
62 #include "BKE_depsgraph.h"
63 #include "BKE_object.h"
64 #include "BKE_global.h"
65 #include "BKE_scene.h"
66 #include "BKE_screen.h"
67 #include "BKE_utildefines.h"
68
69 #include "BIF_gl.h"
70 #include "BIF_transform.h"
71
72 #include "WM_api.h"
73 #include "WM_types.h"
74
75 #include "RNA_access.h"
76 #include "RNA_define.h"
77
78 #include "ED_armature.h"
79 #include "ED_curve.h"
80 #include "ED_editparticle.h"
81 #include "ED_keyframing.h"
82 #include "ED_mesh.h"
83 #include "ED_object.h"
84 #include "ED_screen.h"
85 #include "ED_types.h"
86 #include "ED_util.h"
87
88 #include "UI_interface.h"
89 #include "UI_resources.h"
90 #include "UI_view2d.h"
91
92 #include "view3d_intern.h"      // own include
93
94
95 /* ******************* view3d space & buttons ************** */
96 #define B_NOP           1
97 #define B_REDR          2
98 #define B_OBJECTPANELROT        1007
99 #define B_OBJECTPANELMEDIAN 1008
100 #define B_ARMATUREPANEL1        1009
101 #define B_ARMATUREPANEL2        1010
102 #define B_OBJECTPANELPARENT 1011
103 #define B_OBJECTPANEL           1012
104 #define B_ARMATUREPANEL3        1013
105 #define B_OBJECTPANELSCALE      1014
106 #define B_OBJECTPANELDIMS       1015
107 #define B_TRANSFORMSPACEADD     1016
108 #define B_TRANSFORMSPACECLEAR   1017
109 #define B_SETPT_AUTO    2125
110 #define B_SETPT_VECTOR  2126
111 #define B_SETPT_ALIGN   2127
112 #define B_SETPT_FREE    2128
113 #define B_RECALCMBALL   2501
114
115 #define B_WEIGHT0_0             2840
116 #define B_WEIGHT1_4             2841
117 #define B_WEIGHT1_2             2842
118 #define B_WEIGHT3_4             2843
119 #define B_WEIGHT1_0             2844
120
121 #define B_OPA1_8                2845
122 #define B_OPA1_4                2846
123 #define B_OPA1_2                2847
124 #define B_OPA3_4                2848
125 #define B_OPA1_0                2849
126
127 #define B_CLR_WPAINT    2850
128
129 #define B_IDNAME                3000
130
131 /* temporary struct for storing transform properties */
132 typedef struct {
133         float ob_eul[4];        // used for quat too....
134         float ob_scale[3]; // need temp space due to linked values
135         float ob_dims[3];
136         short link_scale;
137         float ve_median[5];
138         int curdef;
139         float *defweightp;
140 } TransformProperties;
141
142
143 /* is used for both read and write... */
144 static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d, Object *ob, float lim)
145 {
146         MDeformVert *dvert=NULL;
147         TransformProperties *tfp= v3d->properties_storage;
148         float median[5], ve_median[5];
149         int tot, totw, totweight, totedge;
150         char defstr[320];
151         
152         median[0]= median[1]= median[2]= median[3]= median[4]= 0.0;
153         tot= totw= totweight= totedge= 0;
154         defstr[0]= 0;
155
156         if(ob->type==OB_MESH) {
157                 Mesh *me= ob->data;
158                 EditMesh *em = me->edit_mesh;
159                 EditVert *eve, *evedef=NULL;
160                 EditEdge *eed;
161                 
162                 eve= em->verts.first;
163                 while(eve) {
164                         if(eve->f & SELECT) {
165                                 evedef= eve;
166                                 tot++;
167                                 VecAddf(median, median, eve->co);
168                         }
169                         eve= eve->next;
170                 }
171                 eed= em->edges.first;
172                 while(eed) {
173                         if((eed->f & SELECT)) {
174                                 totedge++;
175                                 median[3]+= eed->crease;
176                         }
177                         eed= eed->next;
178                 }
179
180                 /* check for defgroups */
181                 if(evedef)
182                         dvert= CustomData_em_get(&em->vdata, evedef->data, CD_MDEFORMVERT);
183                 if(tot==1 && dvert && dvert->totweight) {
184                         bDeformGroup *dg;
185                         int i, max=1, init=1;
186                         char str[320];
187                         
188                         for (i=0; i<dvert->totweight; i++){
189                                 dg = BLI_findlink (&ob->defbase, dvert->dw[i].def_nr);
190                                 if(dg) {
191                                         max+= BLI_snprintf(str, sizeof(str), "%s %%x%d|", dg->name, dvert->dw[i].def_nr); 
192                                         if(max<320) strcat(defstr, str);
193                                 }
194                                 else printf("oh no!\n");
195                                 if(tfp->curdef==dvert->dw[i].def_nr) {
196                                         init= 0;
197                                         tfp->defweightp= &dvert->dw[i].weight;
198                                 }
199                         }
200                         
201                         if(init) {      // needs new initialized 
202                                 tfp->curdef= dvert->dw[0].def_nr;
203                                 tfp->defweightp= &dvert->dw[0].weight;
204                         }
205                 }
206         }
207         else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
208                 Curve *cu= ob->data;
209                 Nurb *nu;
210                 BPoint *bp;
211                 BezTriple *bezt;
212                 int a;
213                 
214                 nu= cu->editnurb->first;
215                 while(nu) {
216                         if((nu->type & 7)==CU_BEZIER) {
217                                 bezt= nu->bezt;
218                                 a= nu->pntsu;
219                                 while(a--) {
220                                         if(bezt->f2 & SELECT) {
221                                                 VecAddf(median, median, bezt->vec[1]);
222                                                 tot++;
223                                                 median[4]+= bezt->weight;
224                                                 totweight++;
225                                         }
226                                         else {
227                                                 if(bezt->f1 & SELECT) {
228                                                         VecAddf(median, median, bezt->vec[0]);
229                                                         tot++;
230                                                 }
231                                                 if(bezt->f3 & SELECT) {
232                                                         VecAddf(median, median, bezt->vec[2]);
233                                                         tot++;
234                                                 }
235                                         }
236                                         bezt++;
237                                 }
238                         }
239                         else {
240                                 bp= nu->bp;
241                                 a= nu->pntsu*nu->pntsv;
242                                 while(a--) {
243                                         if(bp->f1 & SELECT) {
244                                                 VecAddf(median, median, bp->vec);
245                                                 median[3]+= bp->vec[3];
246                                                 totw++;
247                                                 tot++;
248                                                 median[4]+= bp->weight;
249                                                 totweight++;
250                                         }
251                                         bp++;
252                                 }
253                         }
254                         nu= nu->next;
255                 }
256         }
257         else if(ob->type==OB_LATTICE) {
258                 Lattice *lt= ob->data;
259                 BPoint *bp;
260                 int a;
261                 
262                 a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
263                 bp= lt->editlatt->def;
264                 while(a--) {
265                         if(bp->f1 & SELECT) {
266                                 VecAddf(median, median, bp->vec);
267                                 tot++;
268                                 median[4]+= bp->weight;
269                                 totweight++;
270                         }
271                         bp++;
272                 }
273         }
274         
275         if(tot==0) return;
276
277         median[0] /= (float)tot;
278         median[1] /= (float)tot;
279         median[2] /= (float)tot;
280         if(totedge) median[3] /= (float)totedge;
281         else if(totw) median[3] /= (float)totw;
282         if(totweight) median[4] /= (float)totweight;
283         
284         if(v3d->flag & V3D_GLOBAL_STATS)
285                 Mat4MulVecfl(ob->obmat, median);
286         
287         if(block) {     // buttons
288                 int but_y;
289                 if((ob->parent) && (ob->partype == PARBONE))    but_y = 135;
290                 else                                                                                    but_y = 150;
291                 
292                 uiBlockBeginAlign(block);
293                 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            160, but_y, 70, 19, &v3d->flag, 0, 0, 0, 0, "Displays global values");
294                 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            230, but_y, 70, 19, &v3d->flag, 0, 0, 0, 0, "Displays local values");
295                 uiBlockEndAlign(block);
296                 
297                 memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
298                 
299                 uiBlockBeginAlign(block);
300                 if(tot==1) {
301                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex X:", 10, 110, 290, 19, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
302                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Y:", 10, 90, 290, 19, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
303                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Z:", 10, 70, 290, 19, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
304                         if(totw==1)
305                                 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex W:", 10, 50, 290, 19, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
306                         uiBlockEndAlign(block);
307         
308                         if(defstr[0]) {
309                                 uiDefBut(block, LABEL, 1, "Vertex Deform Groups",               10, 40, 290, 20, NULL, 0.0, 0.0, 0, 0, "");
310
311                                 uiBlockBeginAlign(block);
312                                 uiDefButF(block, NUM, B_NOP, "Weight:",                 10, 20, 150, 19, tfp->defweightp, 0.0f, 1.0f, 10, 3, "Weight value");
313                                 uiDefButI(block, MENU, B_REDR, defstr,  160, 20, 140, 19, &tfp->curdef, 0.0, 0.0, 0, 0, "Current Vertex Group");
314                                 uiBlockEndAlign(block);
315                         }
316                         else if(totweight)
317                                 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   10, 20, 290, 19, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
318
319                 }
320                 else {
321                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median X:", 10, 110, 290, 19, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
322                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Y:", 10, 90, 290, 19, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
323                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Z:", 10, 70, 290, 19, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
324                         if(totw==tot)
325                                 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median W:", 10, 50, 290, 19, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
326                         uiBlockEndAlign(block);
327                         if(totweight)
328                                 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   10, 20, 290, 19, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
329                 }
330                 
331                 if(ob->type==OB_CURVE && (totw==0)) { /* bez curves have no w */
332                         uiBlockBeginAlign(block);
333                         uiDefBut(block, BUT,B_SETPT_AUTO,"Auto",        10, 44, 72, 19, 0, 0, 0, 0, 0, "Auto handles (Shift H)");
334                         uiDefBut(block, BUT,B_SETPT_VECTOR,"Vector",82, 44, 73, 19, 0, 0, 0, 0, 0, "Vector handles (V)");
335                         uiDefBut(block, BUT,B_SETPT_ALIGN,"Align",155, 44, 73, 19, 0, 0, 0, 0, 0, "Align handles (H Toggles)");
336                         uiDefBut(block, BUT,B_SETPT_FREE,"Free",        227, 44, 72, 19, 0, 0, 0, 0, 0, "Align handles (H Toggles)");
337                         uiBlockEndAlign(block);
338                 }
339                 
340                 if(totedge==1)
341                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease W:", 10, 30, 290, 19, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
342                 else if(totedge>1)
343                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Crease W:",  10, 30, 290, 19, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
344                 
345         }
346         else {  // apply
347                 memcpy(ve_median, tfp->ve_median, sizeof(tfp->ve_median));
348                 
349                 if(v3d->flag & V3D_GLOBAL_STATS) {
350                         Mat4Invert(ob->imat, ob->obmat);
351                         Mat4MulVecfl(ob->imat, median);
352                         Mat4MulVecfl(ob->imat, ve_median);
353                 }
354                 VecSubf(median, ve_median, median);
355                 median[3]= ve_median[3]-median[3];
356                 median[4]= ve_median[4]-median[4];
357                 
358                 if(ob->type==OB_MESH) {
359                         Mesh *me= ob->data;
360                         EditMesh *em = me->edit_mesh;
361                         EditVert *eve;
362                         EditEdge *eed;
363                         
364                         eve= em->verts.first;
365                         while(eve) {
366                                 if(eve->f & SELECT) {
367                                         VecAddf(eve->co, eve->co, median);
368                                 }
369                                 eve= eve->next;
370                         }
371                         
372                         for(eed= em->edges.first; eed; eed= eed->next) {
373                                 if(eed->f & SELECT) {
374                                         /* ensure the median can be set to zero or one */
375                                         if(ve_median[3]==0.0f) eed->crease= 0.0f;
376                                         else if(ve_median[3]==1.0f) eed->crease= 1.0f;
377                                         else {
378                                                 eed->crease+= median[3];
379                                                 CLAMP(eed->crease, 0.0, 1.0);
380                                         }
381                                 }
382                         }
383                         
384                         recalc_editnormals(em);
385                 }
386                 else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
387                         Curve *cu= ob->data;
388                         Nurb *nu;
389                         BPoint *bp;
390                         BezTriple *bezt;
391                         int a;
392                         
393                         nu= cu->editnurb->first;
394                         while(nu) {
395                                 if((nu->type & 7)==1) {
396                                         bezt= nu->bezt;
397                                         a= nu->pntsu;
398                                         while(a--) {
399                                                 if(bezt->f2 & SELECT) {
400                                                         VecAddf(bezt->vec[0], bezt->vec[0], median);
401                                                         VecAddf(bezt->vec[1], bezt->vec[1], median);
402                                                         VecAddf(bezt->vec[2], bezt->vec[2], median);
403                                                         bezt->weight+= median[4];
404                                                 }
405                                                 else {
406                                                         if(bezt->f1 & SELECT) {
407                                                                 VecAddf(bezt->vec[0], bezt->vec[0], median);
408                                                         }
409                                                         if(bezt->f3 & SELECT) {
410                                                                 VecAddf(bezt->vec[2], bezt->vec[2], median);
411                                                         }
412                                                 }
413                                                 bezt++;
414                                         }
415                                 }
416                                 else {
417                                         bp= nu->bp;
418                                         a= nu->pntsu*nu->pntsv;
419                                         while(a--) {
420                                                 if(bp->f1 & SELECT) {
421                                                         VecAddf(bp->vec, bp->vec, median);
422                                                         bp->vec[3]+= median[3];
423                                                         bp->weight+= median[4];
424                                                 }
425                                                 bp++;
426                                         }
427                                 }
428                                 test2DNurb(nu);
429                                 testhandlesNurb(nu); /* test for bezier too */
430
431                                 nu= nu->next;
432                         }
433                 }
434                 else if(ob->type==OB_LATTICE) {
435                         Lattice *lt= ob->data;
436                         BPoint *bp;
437                         int a;
438                         
439                         a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
440                         bp= lt->editlatt->def;
441                         while(a--) {
442                                 if(bp->f1 & SELECT) {
443                                         VecAddf(bp->vec, bp->vec, median);
444                                         bp->weight+= median[4];
445                                 }
446                                 bp++;
447                         }
448                 }
449                 
450 //              ED_undo_push(C, "Transform properties");
451         }
452 }
453
454 /* assumes armature active */
455 static void validate_bonebutton_cb(bContext *C, void *bonev, void *namev)
456 {
457         Object *ob= CTX_data_active_object(C);
458         
459         if(ob && ob->type==OB_ARMATURE) {
460                 Bone *bone= bonev;
461                 char oldname[32], newname[32];
462                 
463                 /* need to be on the stack */
464                 BLI_strncpy(newname, bone->name, 32);
465                 BLI_strncpy(oldname, (char *)namev, 32);
466                 /* restore */
467                 BLI_strncpy(bone->name, oldname, 32);
468                 
469                 armature_bone_rename(ob->data, oldname, newname); // editarmature.c
470         }
471 }
472
473 static void v3d_posearmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
474 {
475         uiBut *but;
476         bArmature *arm;
477         bPoseChannel *pchan;
478         Bone *bone= NULL;
479         TransformProperties *tfp= v3d->properties_storage;
480
481         arm = ob->data;
482         if (!arm || !ob->pose) return;
483
484         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
485                 bone = pchan->bone;
486                 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
487                         break;
488         }
489         if (!pchan || !bone) return;
490
491         if((ob->parent) && (ob->partype == PARBONE))
492                 but= uiDefBut (block, TEX, B_NOP, "Bone:",                              160, 130, 140, 19, bone->name, 1, 31, 0, 0, "");
493         else
494                 but= uiDefBut(block, TEX, B_NOP, "Bone:",                               160, 140, 140, 19, bone->name, 1, 31, 0, 0, "");
495         uiButSetFunc(but, validate_bonebutton_cb, bone, NULL);
496         
497         QuatToEul(pchan->quat, tfp->ob_eul);
498         tfp->ob_eul[0]*= 180.0/M_PI;
499         tfp->ob_eul[1]*= 180.0/M_PI;
500         tfp->ob_eul[2]*= 180.0/M_PI;
501         
502         uiBlockBeginAlign(block);
503         uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, B_REDR, ICON_UNLOCKED,   10,140,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
504         uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocX:",        30, 140, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
505         uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, B_REDR, ICON_UNLOCKED,   10,120,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
506         uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocY:",        30, 120, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
507         uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, B_REDR, ICON_UNLOCKED,   10,100,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
508         uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocZ:",        30, 100, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
509
510         uiBlockBeginAlign(block);
511         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   10,70,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
512         uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotX:",        30, 70, 120, 19, tfp->ob_eul, -1000.0, 1000.0, 100, 3, "");
513         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   10,50,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
514         uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotY:",        30, 50, 120, 19, tfp->ob_eul+1, -1000.0, 1000.0, 100, 3, "");
515         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   10,30,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
516         uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotZ:",        30, 30, 120, 19, tfp->ob_eul+2, -1000.0, 1000.0, 100, 3, "");
517         
518         uiBlockBeginAlign(block);
519         uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, B_REDR, ICON_UNLOCKED, 160,70,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
520         uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleX:",      180, 70, 120, 19, pchan->size, -lim, lim, 10, 3, "");
521         uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, B_REDR, ICON_UNLOCKED, 160,50,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
522         uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleY:",      180, 50, 120, 19, pchan->size+1, -lim, lim, 10, 3, "");
523         uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, B_REDR, ICON_UNLOCKED, 160,30,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
524         uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleZ:",      180, 30, 120, 19, pchan->size+2, -lim, lim, 10, 3, "");
525         uiBlockEndAlign(block);
526 }
527
528 static void v3d_editarmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
529 {
530         bArmature *arm= ob->data;
531         EditBone *ebone;
532         uiBut *but;
533         TransformProperties *tfp= v3d->properties_storage;
534         
535         ebone= arm->edbo->first;
536
537         for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
538                 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
539                         break;
540         }
541
542         if (!ebone)
543                 return;
544         
545         if((ob->parent) && (ob->partype == PARBONE))
546                 but= uiDefBut(block, TEX, B_NOP, "Bone:", 160, 130, 140, 19, ebone->name, 1, 31, 0, 0, "");
547         else
548                 but= uiDefBut(block, TEX, B_NOP, "Bone:",                       160, 150, 140, 19, ebone->name, 1, 31, 0, 0, "");
549 // XXX  uiButSetFunc(but, validate_editbonebutton_cb, ebone, NULL);
550
551         uiBlockBeginAlign(block);
552         uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadX:",       10, 70, 140, 19, ebone->head, -lim, lim, 10, 3, "");
553         uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadY:",       10, 50, 140, 19, ebone->head+1, -lim, lim, 10, 3, "");
554         uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadZ:",       10, 30, 140, 19, ebone->head+2, -lim, lim, 10, 3, "");
555         uiBlockBeginAlign(block);
556         uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailX:",       160, 70, 140, 19, ebone->tail, -lim, lim, 10, 3, "");
557         uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailY:",       160, 50, 140, 19, ebone->tail+1, -lim, lim, 10, 3, "");
558         uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailZ:",       160, 30, 140, 19, ebone->tail+2, -lim, lim, 10, 3, "");
559         uiBlockEndAlign(block);
560         
561         tfp->ob_eul[0]= 180.0*ebone->roll/M_PI;
562         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:",        10, 100, 140, 19, tfp->ob_eul, -lim, lim, 1000, 3, "");
563
564         uiDefButBitI(block, TOG, BONE_EDITMODE_LOCKED, B_REDR, "Lock", 160, 100, 140, 19, &(ebone->flag), 0, 0, 0, 0, "Prevents bone from being transformed in edit mode");
565         
566         uiBlockBeginAlign(block);
567         uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailRadius:",  10, 150, 140, 19, &ebone->rad_tail, 0, lim, 10, 3, "");
568         if (ebone->parent && ebone->flag & BONE_CONNECTED )
569                 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadRadius:",  10, 130, 140, 19, &ebone->parent->rad_tail, 0, lim, 10, 3, "");
570         else
571                 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadRadius:",  10, 130, 140, 19, &ebone->rad_head, 0, lim, 10, 3, "");
572         uiBlockEndAlign(block);
573 }
574
575 static void v3d_editmetaball_buts(uiBlock *block, Object *ob, float lim)
576 {
577         MetaElem *lastelem= NULL; // XXX
578
579         if(lastelem) {
580                 uiBlockBeginAlign(block);
581                 uiDefButF(block, NUM, B_RECALCMBALL, "LocX:", 10, 70, 140, 19, &lastelem->x, -lim, lim, 100, 3, "");
582                 uiDefButF(block, NUM, B_RECALCMBALL, "LocY:", 10, 50, 140, 19, &lastelem->y, -lim, lim, 100, 3, "");
583                 uiDefButF(block, NUM, B_RECALCMBALL, "LocZ:", 10, 30, 140, 19, &lastelem->z, -lim, lim, 100, 3, "");
584
585                 uiBlockBeginAlign(block);
586                 if(lastelem->type!=MB_BALL)
587                         uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 160, 70, 140, 19, &lastelem->expx, 0, lim, 100, 3, "");
588                 if((lastelem->type!=MB_BALL) && (lastelem->type!=MB_TUBE))
589                         uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 160, 50, 140, 19, &lastelem->expy, 0, lim, 100, 3, "");
590                 if((lastelem->type==MB_ELIPSOID) || (lastelem->type==MB_CUBE))
591                         uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 160, 30, 140, 19, &lastelem->expz, 0, lim, 100, 3, "");
592
593                 uiBlockEndAlign(block); 
594
595                 uiBlockBeginAlign(block);
596                 uiDefButF(block, NUM, B_RECALCMBALL, "Radius:", 10, 120, 140, 19, &lastelem->rad, 0, lim, 100, 3, "Size of the active metaball");
597                 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 10, 100, 140, 19, &lastelem->s, 0, 10, 100, 3, "Stiffness of the active metaball");
598                 uiBlockEndAlign(block);
599                 
600                 uiDefButS(block, MENU, B_RECALCMBALL, "Type%t|Ball%x0|Tube%x4|Plane%x5|Elipsoid%x6|Cube%x7", 160, 120, 140, 19, &lastelem->type, 0.0, 0.0, 0, 0, "Set active element type");
601                 
602         }
603 }
604
605 /* test if 'ob' is a parent somewhere in par's parents */
606 static int test_parent_loop(Object *par, Object *ob)
607 {
608         if(par == NULL) return 0;
609         if(ob == par) return 1;
610         return test_parent_loop(par->parent, ob);
611 }
612
613 static void do_view3d_region_buttons(bContext *C, void *arg, int event)
614 {
615         Scene *scene= CTX_data_scene(C);
616         Object *obedit= CTX_data_edit_object(C);
617         View3D *v3d= CTX_wm_view3d(C);
618         BoundBox *bb;
619         Object *ob= OBACT;
620         TransformProperties *tfp= v3d->properties_storage;
621         VPaint *wpaint= scene->toolsettings->wpaint;
622         
623         switch(event) {
624         
625         case B_REDR:
626                 ED_area_tag_redraw(CTX_wm_area(C));
627                 return; /* no notifier! */
628                 
629         case B_OBJECTPANEL:
630                 DAG_object_flush_update(scene, ob, OB_RECALC_OB);
631                 break;
632                 
633         case B_OBJECTPANELROT:
634                 if(ob) {
635                         ob->rot[0]= M_PI*tfp->ob_eul[0]/180.0;
636                         ob->rot[1]= M_PI*tfp->ob_eul[1]/180.0;
637                         ob->rot[2]= M_PI*tfp->ob_eul[2]/180.0;
638                         DAG_object_flush_update(scene, ob, OB_RECALC_OB);
639                 }
640                 break;
641
642         case B_OBJECTPANELSCALE:
643                 if(ob) {
644
645                         /* link scale; figure out which axis changed */
646                         if (tfp->link_scale) {
647                                 float ratio, tmp, max = 0.0;
648                                 int axis;
649                                 
650                                 axis = 0;
651                                 max = fabs(tfp->ob_scale[0] - ob->size[0]);
652                                 tmp = fabs(tfp->ob_scale[1] - ob->size[1]);
653                                 if (tmp > max) {
654                                         axis = 1;
655                                         max = tmp;
656                                 }
657                                 tmp = fabs(tfp->ob_scale[2] - ob->size[2]);
658                                 if (tmp > max) {
659                                         axis = 2;
660                                         max = tmp;
661                                 }
662                         
663                                 if (ob->size[axis] != tfp->ob_scale[axis]) {
664                                         if (fabs(ob->size[axis]) > FLT_EPSILON) {
665                                                 ratio = tfp->ob_scale[axis] / ob->size[axis];
666                                                 ob->size[0] *= ratio;
667                                                 ob->size[1] *= ratio;
668                                                 ob->size[2] *= ratio;
669                                         }
670                                 }
671                         }
672                         else {
673                                 VECCOPY(ob->size, tfp->ob_scale);
674                                 
675                         }
676                         DAG_object_flush_update(scene, ob, OB_RECALC_OB);
677                 }
678                 break;
679
680         case B_OBJECTPANELDIMS:
681                 bb= object_get_boundbox(ob);
682                 if(bb) {
683                         float old_dims[3], scale[3], ratio, len[3];
684                         int axis;
685
686                         Mat4ToSize(ob->obmat, scale);
687
688                         len[0] = bb->vec[4][0] - bb->vec[0][0];
689                         len[1] = bb->vec[2][1] - bb->vec[0][1];
690                         len[2] = bb->vec[1][2] - bb->vec[0][2];
691
692                         old_dims[0] = fabs(scale[0]) * len[0];
693                         old_dims[1] = fabs(scale[1]) * len[1];
694                         old_dims[2] = fabs(scale[2]) * len[2];
695
696                         /* for each axis changed */
697                         for (axis = 0; axis<3; axis++) {
698                                 if (fabs(old_dims[axis] - tfp->ob_dims[axis]) > 0.0001) {
699                                         if (old_dims[axis] > 0.0) {
700                                                 ratio = tfp->ob_dims[axis] / old_dims[axis]; 
701                                                 if (tfp->link_scale) {
702                                                         ob->size[0] *= ratio;
703                                                         ob->size[1] *= ratio;
704                                                         ob->size[2] *= ratio;
705                                                         break;
706                                                 }
707                                                 else {
708                                                         ob->size[axis] *= ratio;
709                                                 }
710                                         }
711                                         else {
712                                                 if (len[axis] > 0) {
713                                                         ob->size[axis] = tfp->ob_dims[axis] / len[axis];
714                                                 }
715                                         }
716                                 }
717                         }
718                         
719                         /* prevent multiple B_OBJECTPANELDIMS events to keep scaling, cycling with TAB on buttons can cause that */
720                         VECCOPY(tfp->ob_dims, old_dims);
721                         
722                         DAG_object_flush_update(scene, ob, OB_RECALC_OB);
723                 }
724                 break;
725         
726         case B_OBJECTPANELMEDIAN:
727                 if(ob) {
728                         v3d_editvertex_buts(C, NULL, v3d, ob, 1.0);
729                         DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
730                 }
731                 break;
732                 
733                 /* note; this case also used for parbone */
734         case B_OBJECTPANELPARENT:
735                 if(ob) {
736                         if(ob->id.lib || test_parent_loop(ob->parent, ob) ) 
737                                 ob->parent= NULL;
738                         else {
739                                 DAG_scene_sort(scene);
740                                 DAG_object_flush_update(scene, ob, OB_RECALC_OB);
741                         }
742                 }
743                 break;
744                 
745         case B_ARMATUREPANEL1:
746                 {
747                         bArmature *arm= obedit->data;
748                         EditBone *ebone, *child;
749                         
750                         for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
751                                 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
752                                         break;
753                         }
754                         if (ebone) {
755                                 ebone->roll= M_PI*tfp->ob_eul[0]/180.0;
756                                 //      Update our parent
757                                 if (ebone->parent && ebone->flag & BONE_CONNECTED){
758                                         VECCOPY (ebone->parent->tail, ebone->head);
759                                 }
760                         
761                                 //      Update our children if necessary
762                                 for (child = arm->edbo->first; child; child=child->next){
763                                         if (child->parent == ebone && (child->flag & BONE_CONNECTED)){
764                                                 VECCOPY (child->head, ebone->tail);
765                                         }
766                                 }
767                                 if(arm->flag & ARM_MIRROR_EDIT) {
768                                         EditBone *eboflip= ED_armature_bone_get_mirrored(arm->edbo, ebone);
769                                         if(eboflip) {
770                                                 eboflip->roll= -ebone->roll;
771                                                 eboflip->head[0]= -ebone->head[0];
772                                                 eboflip->tail[0]= -ebone->tail[0];
773                                                 
774                                                 //      Update our parent
775                                                 if (eboflip->parent && eboflip->flag & BONE_CONNECTED){
776                                                         VECCOPY (eboflip->parent->tail, eboflip->head);
777                                                 }
778                                                 
779                                                 //      Update our children if necessary
780                                                 for (child = arm->edbo->first; child; child=child->next){
781                                                         if (child->parent == eboflip && (child->flag & BONE_CONNECTED)){
782                                                                 VECCOPY (child->head, eboflip->tail);
783                                                         }
784                                                 }
785                                         }
786                                 }
787                         }
788                 }
789                 break;
790         case B_ARMATUREPANEL3:  // rotate button on channel
791                 {
792                         bArmature *arm;
793                         bPoseChannel *pchan;
794                         Bone *bone;
795                         float eul[3];
796                         
797                         arm = ob->data;
798                         if (!arm || !ob->pose) return;
799                                 
800                         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
801                                 bone = pchan->bone;
802                                 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
803                                         break;
804                         }
805                         if (!pchan) return;
806                         
807                         /* make a copy to eul[3], to allow TAB on buttons to work */
808                         eul[0]= M_PI*tfp->ob_eul[0]/180.0;
809                         eul[1]= M_PI*tfp->ob_eul[1]/180.0;
810                         eul[2]= M_PI*tfp->ob_eul[2]/180.0;
811                         EulToQuat(eul, pchan->quat);
812                 }
813                 /* no break, pass on */
814         case B_ARMATUREPANEL2:
815                 {
816                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
817                         DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
818                 }
819                 break;
820         case B_TRANSFORMSPACEADD:
821                 BIF_manageTransformOrientation(C, 1, 0);
822                 break;
823         case B_TRANSFORMSPACECLEAR:
824                 BIF_clearTransformOrientation(C);
825                 break;
826                 
827         case B_WEIGHT0_0:
828                 wpaint->weight = 0.0f;
829                 break;
830                 
831         case B_WEIGHT1_4:
832                 wpaint->weight = 0.25f;
833                 break;
834         case B_WEIGHT1_2:
835                 wpaint->weight = 0.5f;
836                 break;
837         case B_WEIGHT3_4:
838                 wpaint->weight = 0.75f;
839                 break;
840         case B_WEIGHT1_0:
841                 wpaint->weight = 1.0f;
842                 break;
843                 
844         case B_OPA1_8:
845                 wpaint->a = 0.125f;
846                 break;
847         case B_OPA1_4:
848                 wpaint->a = 0.25f;
849                 break;
850         case B_OPA1_2:
851                 wpaint->a = 0.5f;
852                 break;
853         case B_OPA3_4:
854                 wpaint->a = 0.75f;
855                 break;
856         case B_OPA1_0:
857                 wpaint->a = 1.0f;
858                 break;
859         case B_CLR_WPAINT:
860 //              if(!multires_level1_test()) {
861         {
862                         bDeformGroup *defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
863                         if(defGroup) {
864                                 Mesh *me= ob->data;
865                                 int a;
866                                 for(a=0; a<me->totvert; a++)
867                                         remove_vert_defgroup (ob, defGroup, a);
868                                 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
869                         }
870                 }
871                 break;
872                 
873         }
874
875         /* default for now */
876         WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
877 }
878
879 void removeTransformOrientation_func(bContext *C, void *target, void *unused)
880 {
881         BIF_removeTransformOrientation(C, (TransformOrientation *) target);
882 }
883
884 void selectTransformOrientation_func(bContext *C, void *target, void *unused)
885 {
886         BIF_selectTransformOrientation(C, (TransformOrientation *) target);
887 }
888
889 static void view3d_panel_transform_spaces(const bContext *C, ARegion *ar, short cntrl)
890 {
891         Scene *scene= CTX_data_scene(C);
892         Object *obedit= CTX_data_edit_object(C);
893         View3D *v3d= CTX_wm_view3d(C);
894         ListBase *transform_spaces = &scene->transform_spaces;
895         TransformOrientation *ts = transform_spaces->first;
896         uiBlock *block;
897         uiBut *but;
898         int xco = 20, yco = 70, height = 140;
899         int index;
900
901         block= uiBeginBlock(C, ar, "view3d_panel_transform", UI_EMBOSS, UI_HELV);
902         if(uiNewPanel(C, ar, block, "Transform Orientations", "View3d", 1000, 0, 318, height)==0) return;
903
904         uiNewPanelHeight(block, height);
905
906         uiBlockBeginAlign(block);
907         
908         if (obedit)
909                 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the selected element as a Transform Orientation");
910         else
911                 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the active object as a Transform Orientation");
912
913         uiDefBut(block, BUT, B_TRANSFORMSPACECLEAR, "Clear", xco + 80,120,80,20, 0, 0, 0, 0, 0, "Removal all Transform Orientations");
914         
915         uiBlockEndAlign(block);
916         
917         uiBlockBeginAlign(block);
918         
919         uiDefButS(block, ROW, REDRAWHEADERS, "Global",  xco,            90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_GLOBAL,0, 0, "Global Transform Orientation");
920         uiDefButS(block, ROW, REDRAWHEADERS, "Local",   xco + 40,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_LOCAL, 0, 0, "Local Transform Orientation");
921         uiDefButS(block, ROW, REDRAWHEADERS, "Normal",  xco + 80,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_NORMAL,0, 0, "Normal Transform Orientation");
922         uiDefButS(block, ROW, REDRAWHEADERS, "View",            xco + 120,      90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_VIEW,    0, 0, "View Transform Orientation");
923         
924         for (index = V3D_MANIP_CUSTOM, ts = transform_spaces->first ; ts ; ts = ts->next, index++) {
925
926                 UI_ThemeColor(TH_BUT_ACTION);
927                 if (v3d->twmode == index) {
928                         but = uiDefIconButS(block,ROW, REDRAWHEADERS, ICON_CHECKBOX_HLT, xco,yco,XIC,YIC, &v3d->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
929                 }
930                 else {
931                         but = uiDefIconButS(block,ROW, REDRAWHEADERS, ICON_CHECKBOX_DEHLT, xco,yco,XIC,YIC, &v3d->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
932                 }
933                 uiButSetFunc(but, selectTransformOrientation_func, ts, NULL);
934                 uiDefBut(block, TEX, 0, "", xco+=XIC, yco,100+XIC,20, &ts->name, 0, 30, 0, 0, "Edits the name of this Transform Orientation");
935                 but = uiDefIconBut(block, BUT, B_REDR, ICON_X, xco+=100+XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes this Transform Orientation");
936                 uiButSetFunc(but, removeTransformOrientation_func, ts, NULL);
937
938                 xco = 20;
939                 yco -= 25;
940         }
941         uiBlockEndAlign(block);
942         
943         if(yco < 0) uiNewPanelHeight(block, height-yco);
944         uiEndBlock(C, block);
945 }
946
947 static void weight_paint_buttons(Scene *scene, uiBlock *block)
948 {
949         VPaint *wpaint= scene->toolsettings->wpaint;
950         Object *ob;
951         ob= OBACT;
952         
953         if(ob==NULL || ob->type!=OB_MESH) return;
954         
955         uiBlockBeginAlign(block);
956         uiDefButF(block, NUMSLI, B_REDR, "Weight:",10,170,225,19, &wpaint->weight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
957         
958         uiDefBut(block, BUT, B_WEIGHT0_0 , "0",                  10,150,45,19, 0, 0, 0, 0, 0, "");
959         uiDefBut(block, BUT, B_WEIGHT1_4 , "1/4",                55,150,45,19, 0, 0, 0, 0, 0, "");
960         uiDefBut(block, BUT, B_WEIGHT1_2 , "1/2",                100,150,45,19, 0, 0, 0, 0, 0, "");
961         uiDefBut(block, BUT, B_WEIGHT3_4 , "3/4",                145,150,45,19, 0, 0, 0, 0, 0, "");
962         uiDefBut(block, BUT, B_WEIGHT1_0 , "1",                  190,150,45,19, 0, 0, 0, 0, 0, "");
963         
964         uiDefButF(block, NUMSLI, B_NOP, "Opacity ",             10,130,225,19, &wpaint->a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
965         
966         uiDefBut(block, BUT, B_OPA1_8 , "1/8",          10,110,45,19, 0, 0, 0, 0, 0, "");
967         uiDefBut(block, BUT, B_OPA1_4 , "1/4",          55,110,45,19, 0, 0, 0, 0, 0, "");
968         uiDefBut(block, BUT, B_OPA1_2 , "1/2",          100,110,45,19, 0, 0, 0, 0, 0, "");
969         uiDefBut(block, BUT, B_OPA3_4 , "3/4",          145,110,45,19, 0, 0, 0, 0, 0, "");
970         uiDefBut(block, BUT, B_OPA1_0 , "1",            190,110,45,19, 0, 0, 0, 0, 0, "");
971         
972         uiDefButF(block, NUMSLI, B_NOP, "Size ",        10,90,225,19, &wpaint->size, 2.0, 64.0, 0, 0, "The size of the brush");
973         
974         uiBlockBeginAlign(block);
975         uiDefButS(block, ROW, B_NOP, "Mix",             250,170,60,17, &wpaint->mode, 1.0, 0.0, 0, 0, "Mix the vertex colors");
976         uiDefButS(block, ROW, B_NOP, "Add",             250,152,60,17, &wpaint->mode, 1.0, 1.0, 0, 0, "Add the vertex colors");
977         uiDefButS(block, ROW, B_NOP, "Sub",             250,134,60,17, &wpaint->mode, 1.0, 2.0, 0, 0, "Subtract from the vertex color");
978         uiDefButS(block, ROW, B_NOP, "Mul",             250,116,60,17, &wpaint->mode, 1.0, 3.0, 0, 0, "Multiply the vertex color");
979         uiDefButS(block, ROW, B_NOP, "Blur",            250, 98,60,17, &wpaint->mode, 1.0, 4.0, 0, 0, "Blur the weight with surrounding values");
980         uiDefButS(block, ROW, B_NOP, "Lighter", 250, 80,60,17, &wpaint->mode, 1.0, 5.0, 0, 0, "Paint over darker areas only");
981         uiDefButS(block, ROW, B_NOP, "Darker",          250, 62,60,17, &wpaint->mode, 1.0, 6.0, 0, 0, "Paint over lighter areas only");
982         uiBlockEndAlign(block);
983         
984         /* draw options same as below */
985         uiBlockBeginAlign(block);
986         if (FACESEL_PAINT_TEST) {
987                 Mesh *me= ob->data;
988                 uiDefButBitI(block, TOG, ME_DRAWFACES, B_REDR, "Faces", 10,45,60,19, &me->drawflag, 0, 0, 0, 0, "Displays all faces as shades");
989                 uiDefButBitI(block,TOG, ME_DRAWEDGES, B_REDR,"Edges",70,45,60,19, &me->drawflag, 2.0, 0, 0, 0,  "Displays edges of visible faces");
990                 uiDefButBitI(block,TOG, ME_HIDDENEDGES, B_REDR,"Hidden Edges",130,45,100,19, &me->drawflag, 2.0, 1.0, 0, 0,  "Displays edges of hidden faces");
991         } else{ 
992                 uiDefButBitC(block, TOG, OB_DRAWWIRE, B_REDR, "Wire",   10,45,75,19, &ob->dtx, 0, 0, 0, 0, "Displays the active object's wireframe in shaded drawing modes");
993         }
994         uiBlockEndAlign(block);
995         
996         uiBlockBeginAlign(block);
997         uiDefButBitS(block, TOG, VP_AREA, 0, "All Faces",       10,20,60,19, &wpaint->flag, 0, 0, 0, 0, "Paint on all faces inside brush (otherwise only on face under mouse cursor)");
998         uiDefButBitS(block, TOG, VP_SOFT, 0, "Vert Dist", 70,20,60,19, &wpaint->flag, 0, 0, 0, 0, "Use distances to vertices (instead of all vertices of face)");
999         uiDefButBitS(block, TOGN, VP_HARD, 0, "Soft",           130,20,60,19, &wpaint->flag, 0, 0, 0, 0, "Use a soft brush");
1000         uiDefButBitS(block, TOG, VP_NORMALS, 0, "Normals",      190,20,60,19, &wpaint->flag, 0, 0, 0, 0, "Applies the vertex normal before painting");
1001         uiDefButBitS(block, TOG, VP_SPRAY, 0, "Spray",          250,20,55,19, &wpaint->flag, 0, 0, 0, 0, "Keep applying paint effect while holding mouse");
1002         uiBlockEndAlign(block);
1003         
1004         if(ob) {
1005                 uiBlockBeginAlign(block);
1006                 uiDefButBitS(block, TOG, VP_ONLYVGROUP, B_REDR, "Vgroup",               10,0,100,19, &wpaint->flag, 0, 0, 0, 0, "Only paint on vertices in the selected vertex group.");
1007                 uiDefButBitS(block, TOG, VP_MIRROR_X, B_REDR, "X-Mirror",       110,0,100,19, &wpaint->flag, 0, 0, 0, 0, "Mirrored Paint, applying on mirrored Weight Group name");
1008                 uiDefBut(block, BUT, B_CLR_WPAINT, "Clear",                                     210,0,100,19, NULL, 0, 0, 0, 0, "Removes reference to this deform group from all vertices");
1009                 uiBlockEndAlign(block);
1010         }
1011 }
1012
1013 static void sculptmode_draw_interface_tools(Scene *scene, uiBlock *block, unsigned short cx, unsigned short cy)
1014 {
1015 #if 0   
1016         Sculpt *sd= scene->toolsettings->sculpt;
1017         
1018         uiBlockBeginAlign(block);
1019         
1020         uiDefBut(block,LABEL,B_NOP,"Brush",cx,cy,90,19,NULL,0,0,0,0,"");
1021         cy-= 20;
1022         
1023         uiBlockBeginAlign(block);       
1024         uiDefButS(block,ROW,B_REDR,"Draw",cx,cy,67,19,&sd->brush_type,14.0,DRAW_BRUSH,0,0,"Draw lines on the model");
1025         uiDefButS(block,ROW,REDRAWBUTSEDIT,"Smooth",cx+67,cy,67,19,&sd->brush_type,14.0,SMOOTH_BRUSH,0,0,"Interactively smooth areas of the model");
1026         uiDefButS(block,ROW,B_REDR,"Pinch",cx+134,cy,67,19,&sd->brush_type,14.0,PINCH_BRUSH,0,0,"Interactively pinch areas of the model");
1027         uiDefButS(block,ROW,B_REDR,"Inflate",cx+201,cy,67,19,&sd->brush_type,14,INFLATE_BRUSH,0,0,"Push vertices along the direction of their normals");
1028         cy-= 20;
1029         uiDefButS(block,ROW,B_REDR,"Grab", cx,cy,89,19,&sd->brush_type,14,GRAB_BRUSH,0,0,"Grabs a group of vertices and moves them with the mouse");
1030         uiDefButS(block,ROW,B_REDR,"Layer", cx+89,cy,89,19,&sd->brush_type,14, LAYER_BRUSH,0,0,"Adds a layer of depth");
1031         uiDefButS(block,ROW,B_REDR,"Flatten", cx+178,cy,90,19,&sd->brush_type,14, FLATTEN_BRUSH,0,0,"Interactively flatten areas of the model");
1032         cy-= 25;
1033         uiBlockEndAlign(block);
1034         
1035         uiBlockBeginAlign(block);
1036         uiDefBut(block,LABEL,B_NOP,"Shape",cx,cy,90,19,NULL,0,0,0,0,"");
1037         cy-= 20;
1038
1039         uiBlockBeginAlign(block);
1040         if(sd->brush_type != SMOOTH_BRUSH && sd->brush_type != GRAB_BRUSH && sd->brush_type != FLATTEN_BRUSH) {
1041                 uiDefButC(block,ROW,B_NOP,"Add",cx,cy,89,19,&sculptmode_brush()->dir,15.0,1.0,0, 0,"Add depth to model [Shift]");
1042                 uiDefButC(block,ROW,B_NOP,"Sub",cx+89,cy,89,19,&sculptmode_brush()->dir,15.0,2.0,0, 0,"Subtract depth from model [Shift]");
1043         }
1044         if(sd->brush_type!=GRAB_BRUSH)
1045                 uiDefButBitC(block, TOG, SCULPT_BRUSH_AIRBRUSH, B_NOP, "Airbrush", cx+178,cy,89,19, &sculptmode_brush()->flag,0,0,0,0, "Brush makes changes without waiting for the mouse to move");
1046         cy-= 20;
1047         uiDefButS(block,NUMSLI,B_NOP,"Size: ",cx,cy,268,19,&sculptmode_brush()->size,1.0,200.0,0,0,"Set brush radius in pixels");
1048         cy-= 20;
1049         if(sd->brush_type!=GRAB_BRUSH)
1050                 uiDefButC(block,NUMSLI,B_NOP,"Strength: ",cx,cy,268,19,&sculptmode_brush()->strength,1.0,100.0,0,0,"Set brush strength");
1051         cy-= 25;
1052         uiBlockEndAlign(block);
1053         
1054         uiBlockBeginAlign(block);
1055         uiDefBut( block,LABEL,B_NOP,"Symmetry",cx,cy,90,19,NULL,0,0,0,0,"");
1056         cy-= 20;
1057         uiBlockBeginAlign(block);
1058         uiDefButBitC(block, TOG, SYMM_X, B_NOP, "X", cx,cy,40,19, &sd->symm, 0,0,0,0, "Mirror brush across X axis");
1059         uiDefButBitC(block, TOG, SYMM_Y, B_NOP, "Y", cx+40,cy,40,19, &sd->symm, 0,0,0,0, "Mirror brush across Y axis");
1060         uiDefButBitC(block, TOG, SYMM_Z, B_NOP, "Z", cx+80,cy,40,19, &sd->symm, 0,0,0,0, "Mirror brush across Z axis");
1061         uiBlockEndAlign(block);
1062         
1063         
1064         cy+= 20;
1065         uiBlockBeginAlign(block);
1066         uiDefBut( block,LABEL,B_NOP,"LockAxis",cx+140,cy,90,19,NULL,0,0,0,0,"");
1067         cy-= 20;
1068         uiBlockBeginAlign(block);
1069         uiDefButBitC(block, TOG, AXISLOCK_X, B_NOP, "X", cx+140,cy,40,19, &sd->axislock, 0,0,0,0, "Constrain X axis");
1070         uiDefButBitC(block, TOG, AXISLOCK_Y, B_NOP, "Y", cx+180,cy,40,19, &sd->axislock, 0,0,0,0, "Constrain Y axis");
1071         uiDefButBitC(block, TOG, AXISLOCK_Z, B_NOP, "Z", cx+220,cy,40,19, &sd->axislock, 0,0,0,0, "Constrain Z axis");
1072         uiBlockEndAlign(block);
1073                 
1074         cx+= 210;
1075 #endif
1076 }
1077
1078
1079 static void view3d_panel_object(const bContext *C, ARegion *ar, short cntrl)    // VIEW3D_HANDLER_OBJECT
1080 {
1081         Scene *scene= CTX_data_scene(C);
1082         Object *obedit= CTX_data_edit_object(C);
1083         View3D *v3d= CTX_wm_view3d(C);
1084         uiBlock *block;
1085         uiBut *bt;
1086         Object *ob= OBACT;
1087         TransformProperties *tfp;
1088         float lim;
1089         static char hexcol[128];
1090         
1091         if(ob==NULL) return;
1092
1093         /* make sure we got storage */
1094         if(v3d->properties_storage==NULL)
1095                 v3d->properties_storage= MEM_callocN(sizeof(TransformProperties), "TransformProperties");
1096         tfp= v3d->properties_storage;
1097         
1098         block= uiBeginBlock(C, ar, "view3d_panel_object", UI_EMBOSS, UI_HELV);
1099         uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
1100         
1101         if((G.f & G_SCULPTMODE) && !obedit) {
1102                 if(!uiNewPanel(C, ar, block, "Transform Properties", "View3d", 10, 230, 318, 234))
1103                         return;
1104         } else if(G.f & G_PARTICLEEDIT && !obedit){
1105                 if(!uiNewPanel(C, ar, block, "Transform Properties", "View3d", 10, 230, 318, 234))
1106                         return;
1107         } else {
1108                 if(!uiNewPanel(C, ar, block, "Transform Properties", "View3d", 10, 230, 318, 204))
1109                         return;
1110         }
1111
1112 // XXX  uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
1113         
1114         if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
1115         }
1116         else {
1117                 bt= uiDefBut(block, TEX, B_IDNAME, "OB: ",      10,180,140,20, ob->id.name+2, 0.0, 21.0, 0, 0, "");
1118 // XXX          uiButSetFunc(bt, test_idbutton_cb, ob->id.name, NULL);
1119
1120                 if((G.f & G_PARTICLEEDIT)==0) {
1121                         uiBlockBeginAlign(block);
1122 // XXX                  uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", 160, 180, 140, 20, &ob->parent, "Parent Object"); 
1123                         if((ob->parent) && (ob->partype == PARBONE)) {
1124                                 bt= uiDefBut(block, TEX, B_OBJECTPANELPARENT, "ParBone:", 160, 160, 140, 20, ob->parsubstr, 0, 30, 0, 0, "");
1125 // XXX                          uiButSetCompleteFunc(bt, autocomplete_bone, (void *)ob->parent);
1126                         }
1127                         else {
1128                                 strcpy(ob->parsubstr, "");
1129                         }
1130                         uiBlockEndAlign(block);
1131                 }
1132         }
1133
1134         lim= 10000.0f*MAX2(1.0, v3d->grid);
1135
1136         if(ob==obedit) {
1137                 if(ob->type==OB_ARMATURE) v3d_editarmature_buts(block, v3d, ob, lim);
1138                 if(ob->type==OB_MBALL) v3d_editmetaball_buts(block, ob, lim);
1139                 else v3d_editvertex_buts(C, block, v3d, ob, lim);
1140         }
1141         else if(ob->flag & OB_POSEMODE) {
1142                 v3d_posearmature_buts(block, v3d, ob, lim);
1143         }
1144         else if(G.f & G_WEIGHTPAINT) {
1145                 uiNewPanelTitle(block, "Weight Paint Properties");
1146                 weight_paint_buttons(scene, block);
1147         }
1148         else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT)) {
1149                 static float hsv[3], old[3];    // used as temp mem for picker
1150                 float *rgb= NULL;
1151                 ToolSettings *settings= scene->toolsettings;
1152
1153                 if(G.f & G_VERTEXPAINT) rgb= &settings->vpaint->r;
1154                 else if(settings->imapaint.brush) rgb= settings->imapaint.brush->rgb;
1155                 
1156                 uiNewPanelTitle(block, "Paint Properties");
1157                 if (rgb)
1158                         /* 'f' is for floating panel */
1159                         uiBlockPickerButtons(block, rgb, hsv, old, hexcol, 'f', B_REDR);
1160         }
1161         else if(G.f & G_SCULPTMODE) {
1162                 uiNewPanelTitle(block, "Sculpt Properties");
1163                 sculptmode_draw_interface_tools(scene, block, 10, 150);
1164         } 
1165         else if(G.f & G_PARTICLEEDIT){
1166                 uiNewPanelTitle(block, "Particle Edit Properties");
1167 // XXX          particle_edit_buttons(block);
1168         } 
1169         else {
1170                 BoundBox *bb = NULL;
1171
1172                 uiBlockBeginAlign(block);
1173                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, B_REDR, ICON_UNLOCKED,   10,150,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1174                 uiDefButF(block, NUM, B_OBJECTPANEL, "LocX:",           30, 150, 120, 19, &(ob->loc[0]), -lim, lim, 100, 3, "");
1175                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, B_REDR, ICON_UNLOCKED,   10,130,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1176                 uiDefButF(block, NUM, B_OBJECTPANEL, "LocY:",           30, 130, 120, 19, &(ob->loc[1]), -lim, lim, 100, 3, "");
1177                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, B_REDR, ICON_UNLOCKED,   10,110,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1178                 uiDefButF(block, NUM, B_OBJECTPANEL, "LocZ:",           30, 110, 120, 19, &(ob->loc[2]), -lim, lim, 100, 3, "");
1179                 
1180                 tfp->ob_eul[0]= 180.0*ob->rot[0]/M_PI;
1181                 tfp->ob_eul[1]= 180.0*ob->rot[1]/M_PI;
1182                 tfp->ob_eul[2]= 180.0*ob->rot[2]/M_PI;
1183                 
1184                 uiBlockBeginAlign(block);
1185                 if ((ob->parent) && (ob->partype == PARBONE)) {
1186                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   160,130,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1187                         uiDefButF(block, NUM, B_OBJECTPANELROT, "RotX:",        180, 130, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
1188                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   160,110,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1189                         uiDefButF(block, NUM, B_OBJECTPANELROT, "RotY:",        180, 110, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
1190                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   160,90,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1191                         uiDefButF(block, NUM, B_OBJECTPANELROT, "RotZ:",        180, 90, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
1192
1193                 }
1194                 else {
1195                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   160,150,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1196                         uiDefButF(block, NUM, B_OBJECTPANELROT, "RotX:",        180, 150, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
1197                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   160,130,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1198                         uiDefButF(block, NUM, B_OBJECTPANELROT, "RotY:",        180, 130, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
1199                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   160,110,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1200                         uiDefButF(block, NUM, B_OBJECTPANELROT, "RotZ:",        180, 110, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
1201                 }
1202
1203                 tfp->ob_scale[0]= ob->size[0];
1204                 tfp->ob_scale[1]= ob->size[1];
1205                 tfp->ob_scale[2]= ob->size[2];
1206
1207                 uiBlockBeginAlign(block);
1208                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, B_REDR, ICON_UNLOCKED, 10,80,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1209                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleX:",            30, 80, 120, 19, &(tfp->ob_scale[0]), -lim, lim, 10, 3, "");
1210                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, B_REDR, ICON_UNLOCKED, 10,60,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1211                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleY:",            30, 60, 120, 19, &(tfp->ob_scale[1]), -lim, lim, 10, 3, "");
1212                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, B_REDR, ICON_UNLOCKED, 10,40,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1213                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleZ:",            30, 40, 120, 19, &(tfp->ob_scale[2]), -lim, lim, 10, 3, "");
1214                 uiBlockEndAlign(block);
1215                 
1216                 uiDefButS(block, TOG, B_REDR, "Link Scale",             10, 10, 140, 19, &(tfp->link_scale), 0, 1, 0, 0, "Scale values vary proportionally in all directions");
1217
1218                 bb= object_get_boundbox(ob);
1219                 if (bb) {
1220                         float scale[3];
1221
1222                         Mat4ToSize(ob->obmat, scale);
1223
1224                         tfp->ob_dims[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
1225                         tfp->ob_dims[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
1226                         tfp->ob_dims[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
1227
1228                         uiBlockBeginAlign(block);
1229                         if ((ob->parent) && (ob->partype == PARBONE)) {
1230                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimX:",               160, 60, 140, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate bounding box size");
1231                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimY:",               160, 40, 140, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate bounding box size");
1232                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimZ:",               160, 20, 140, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate bounding box size");
1233
1234                         }
1235                         else {
1236                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimX:",               160, 80, 140, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate bounding box size");
1237                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimY:",               160, 60, 140, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate bounding box size");
1238                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimZ:",               160, 40, 140, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate bounding box size");
1239                         }
1240
1241                         uiBlockEndAlign(block);
1242                 }
1243         }
1244 // XXX  uiClearButLock();
1245         uiEndBlock(C, block);
1246 }
1247
1248 static void view3d_panel_background(const bContext *C, ARegion *ar, short cntrl)        // VIEW3D_HANDLER_BACKGROUND
1249 {
1250         View3D *v3d= CTX_wm_view3d(C);
1251         uiBlock *block;
1252
1253         block= uiBeginBlock(C, ar, "view3d_panel_background", UI_EMBOSS, UI_HELV);
1254         if(uiNewPanel(C, ar, block, "Background Image", "View3d", 340, 10, 318, 204)==0) return;
1255
1256         if(v3d->flag & V3D_DISPBGPIC) {
1257                 if(v3d->bgpic==NULL) {
1258                         v3d->bgpic= MEM_callocN(sizeof(BGpic), "bgpic");
1259                         v3d->bgpic->size= 5.0;
1260                         v3d->bgpic->blend= 0.5;
1261                         v3d->bgpic->iuser.fie_ima= 2;
1262                         v3d->bgpic->iuser.ok= 1;
1263                 }
1264         }
1265         
1266         if(!(v3d->flag & V3D_DISPBGPIC)) {
1267                 uiDefButBitS(block, TOG, V3D_DISPBGPIC, B_REDR, "Use Background Image", 10, 180, 150, 20, &v3d->flag, 0, 0, 0, 0, "Display an image in the background of this 3D View");
1268                 uiDefBut(block, LABEL, 1, " ",  160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
1269         }
1270         else {
1271                 uiBlockBeginAlign(block);
1272                 uiDefButBitS(block, TOG, V3D_DISPBGPIC, B_REDR, "Use", 10, 225, 50, 20, &v3d->flag, 0, 0, 0, 0, "Display an image in the background of this 3D View");
1273                 uiDefButF(block, NUMSLI, B_REDR, "Blend:",      60, 225, 150, 20, &v3d->bgpic->blend, 0.0,1.0, 0, 0, "Set the transparency of the background image");
1274                 uiDefButF(block, NUM, B_REDR, "Size:",          210, 225, 100, 20, &v3d->bgpic->size, 0.1, 250.0*v3d->grid, 100, 0, "Set the size (width) of the background image");
1275
1276                 uiDefButF(block, NUM, B_REDR, "X Offset:",      10, 205, 150, 20, &v3d->bgpic->xof, -250.0*v3d->grid,250.0*v3d->grid, 10, 2, "Set the horizontal offset of the background image");
1277                 uiDefButF(block, NUM, B_REDR, "Y Offset:",      160, 205, 150, 20, &v3d->bgpic->yof, -250.0*v3d->grid,250.0*v3d->grid, 10, 2, "Set the vertical offset of the background image");
1278                 
1279 // XXX          uiblock_image_panel(block, &v3d->bgpic->ima, &v3d->bgpic->iuser, B_REDR, B_REDR);
1280                 uiBlockEndAlign(block);
1281         }
1282         uiEndBlock(C, block);
1283 }
1284
1285
1286 static void view3d_panel_properties(const bContext *C, ARegion *ar, short cntrl)        // VIEW3D_HANDLER_SETTINGS
1287 {
1288         Scene *scene= CTX_data_scene(C);
1289         View3D *v3d= CTX_wm_view3d(C);
1290         uiBlock *block;
1291         float *curs;
1292
1293         block= uiBeginBlock(C, ar, "view3d_panel_properties", UI_EMBOSS, UI_HELV);
1294         if(uiNewPanel(C, ar, block, "View Properties", "View3d", 340, 30, 318, 254)==0) return;
1295         uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
1296
1297         /* to force height */
1298         uiNewPanelHeight(block, 264);
1299
1300         uiDefBut(block, LABEL, 1, "Grid:",                                      10, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
1301         uiBlockBeginAlign(block);
1302         uiDefButF(block, NUM, B_REDR, "Spacing:",               10, 200, 140, 19, &v3d->grid, 0.001, 100.0, 10, 0, "Set the distance between grid lines");
1303         uiDefButS(block, NUM, B_REDR, "Lines:",         10, 180, 140, 19, &v3d->gridlines, 0.0, 100.0, 100, 0, "Set the number of grid lines in perspective view");
1304         uiDefButS(block, NUM, B_REDR, "Divisions:",             10, 160, 140, 19, &v3d->gridsubdiv, 1.0, 100.0, 100, 0, "Set the number of grid lines");
1305         uiBlockEndAlign(block);
1306
1307         uiDefBut(block, LABEL, 1, "3D Display:",                                                        160, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
1308         uiDefButBitS(block, TOG, V3D_SHOW_FLOOR, B_REDR, "Grid Floor",160, 200, 150, 19, &v3d->gridflag, 0, 0, 0, 0, "Show the grid floor in free camera mode");
1309         uiDefButBitS(block, TOG, V3D_SHOW_X, B_REDR, "X Axis",          160, 176, 48, 19, &v3d->gridflag, 0, 0, 0, 0, "Show the X Axis line");
1310         uiDefButBitS(block, TOG, V3D_SHOW_Y, B_REDR, "Y Axis",          212, 176, 48, 19, &v3d->gridflag, 0, 0, 0, 0, "Show the Y Axis line");
1311         uiDefButBitS(block, TOG, V3D_SHOW_Z, B_REDR, "Z Axis",          262, 176, 48, 19, &v3d->gridflag, 0, 0, 0, 0, "Show the Z Axis line");
1312
1313         uiDefBut(block, LABEL, 1, "View Camera:",                       10, 140, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
1314         
1315         uiDefButF(block, NUM, B_REDR, "Lens:",          10, 120, 140, 19, &v3d->lens, 10.0, 120.0, 100, 0, "The lens angle in perspective view");
1316         uiBlockBeginAlign(block);
1317         uiDefButF(block, NUM, B_REDR, "Clip Start:",    10, 96, 140, 19, &v3d->near, v3d->grid/100.0, 100.0, 10, 0, "Set the beginning of the range in which 3D objects are displayed (perspective view)");
1318         uiDefButF(block, NUM, B_REDR, "Clip End:",      10, 76, 140, 19, &v3d->far, 1.0, 10000.0*v3d->grid, 100, 0, "Set the end of the range in which 3D objects are displayed (perspective view)");
1319         uiBlockEndAlign(block);
1320
1321         uiDefBut(block, LABEL, 1, "3D Cursor:",                         160, 150, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
1322
1323         uiBlockBeginAlign(block);
1324         curs= give_cursor(scene, v3d);
1325         uiDefButF(block, NUM, B_REDR, "X:",                     160, 130, 150, 22, curs, -10000.0*v3d->grid, 10000.0*v3d->grid, 10, 0, "X co-ordinate of the 3D cursor");
1326         uiDefButF(block, NUM, B_REDR, "Y:",                     160, 108, 150, 22, curs+1, -10000.0*v3d->grid, 10000.0*v3d->grid, 10, 0, "Y co-ordinate of the 3D cursor");
1327         uiDefButF(block, NUM, B_REDR, "Z:",                     160, 86, 150, 22, curs+2, -10000.0*v3d->grid, 10000.0*v3d->grid, 10, 0, "Z co-ordinate of the 3D cursor");
1328         uiBlockEndAlign(block);
1329
1330         uiDefBut(block, LABEL, 1, "Display:",                           10, 50, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
1331         uiBlockBeginAlign(block);
1332         uiDefButBitS(block, TOG, V3D_SELECT_OUTLINE, B_REDR, "Outline Selected", 10, 30, 140, 19, &v3d->flag, 0, 0, 0, 0, "Highlight selected objects with an outline, in Solid, Shaded or Textured viewport shading modes");
1333         uiDefButBitS(block, TOG, V3D_DRAW_CENTERS, B_REDR, "All Object Centers", 10, 10, 140, 19, &v3d->flag, 0, 0, 0, 0, "Draw the center points on all objects");
1334         uiDefButBitS(block, TOGN, V3D_HIDE_HELPLINES, B_REDR, "Relationship Lines", 10, -10, 140, 19, &v3d->flag, 0, 0, 0, 0, "Draw dashed lines indicating Parent, Constraint, or Hook relationships");
1335         uiDefButBitS(block, TOG, V3D_SOLID_TEX, B_REDR, "Solid Tex", 10, -30, 140, 19, &v3d->flag2, 0, 0, 0, 0, "Display textures in Solid draw type (Shift T)");
1336         uiBlockEndAlign(block);
1337
1338         uiDefBut(block, LABEL, 1, "View Locking:",                              160, 60, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
1339         uiBlockBeginAlign(block);
1340 // XXX  uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Object:", 160, 40, 140, 19, &v3d->ob_centre, "Lock view to center to this Object"); 
1341         uiDefBut(block, TEX, B_REDR, "Bone:",                                           160, 20, 140, 19, v3d->ob_centre_bone, 1, 31, 0, 0, "If view locked to Object, use this Bone to lock to view to");
1342
1343 // XXX
1344 //      uiDefBut(block, LABEL, 1, "Keyframe Display:",                          160, -2, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
1345 //      uiBlockBeginAlign(block);
1346 //      uiDefButBitS(block, TOG, ANIMFILTER_ACTIVE, B_REDR, "Active",160, -22, 50, 19, &v3d->keyflags, 0, 0, 0, 0, "Show keyframes for active element only (i.e. active bone or active material)");
1347 //      uiDefButBitS(block, TOG, ANIMFILTER_MUTED, B_REDR, "Muted",210, -22, 50, 19, &v3d->keyflags, 0, 0, 0, 0, "Show keyframes in muted channels");
1348 //      uiDefButBitS(block, TOG, ANIMFILTER_LOCAL, B_REDR, "Local",260, -22, 50, 19, &v3d->keyflags, 0, 0, 0, 0, "Show keyframes directly connected to datablock");
1349 //      if ((v3d->keyflags & ANIMFILTER_LOCAL)==0) {
1350 //              uiDefButBitS(block, TOGN, ANIMFILTER_NOMAT, B_REDR, "Material",160, -42, 75, 19, &v3d->keyflags, 0, 0, 0, 0, "Show keyframes for any available Materials");
1351 //              uiDefButBitS(block, TOGN, ANIMFILTER_NOSKEY, B_REDR, "ShapeKey",235, -42, 75, 19, &v3d->keyflags, 0, 0, 0, 0, "Show keyframes for any available Shape Keys");
1352 //      }
1353         uiBlockEndAlign(block); 
1354         
1355         uiEndBlock(C, block);
1356 }
1357
1358 #if 0
1359 static void view3d_panel_preview(bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_PREVIEW
1360 {
1361         uiBlock *block;
1362         View3D *v3d= sa->spacedata.first;
1363         int ofsx, ofsy;
1364         
1365         block= uiBeginBlock(C, ar, "view3d_panel_preview", UI_EMBOSS, UI_HELV);
1366         uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
1367         uiSetPanelHandler(VIEW3D_HANDLER_PREVIEW);  // for close and esc
1368         
1369         ofsx= -150+(sa->winx/2)/v3d->blockscale;
1370         ofsy= -100+(sa->winy/2)/v3d->blockscale;
1371         if(uiNewPanel(C, ar, block, "Preview", "View3d", ofsx, ofsy, 300, 200)==0) return;
1372
1373         uiBlockSetDrawExtraFunc(block, BIF_view3d_previewdraw);
1374         
1375         if(scene->recalc & SCE_PRV_CHANGED) {
1376                 scene->recalc &= ~SCE_PRV_CHANGED;
1377                 //printf("found recalc\n");
1378                 BIF_view3d_previewrender_free(sa->spacedata.first);
1379                 BIF_preview_changed(0);
1380         }
1381 }
1382 #endif
1383
1384 static void view3d_panel_gpencil(const bContext *C, ARegion *ar, short cntrl)   // VIEW3D_HANDLER_GREASEPENCIL
1385 {
1386         View3D *v3d= CTX_wm_view3d(C);
1387         uiBlock *block;
1388
1389         block= uiBeginBlock(C, ar, "view3d_panel_gpencil", UI_EMBOSS, UI_HELV);
1390         if (uiNewPanel(C, ar, block, "Grease Pencil", "View3d", 100, 30, 318, 204)==0) return;
1391
1392         /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */
1393         if (v3d->flag2 & V3D_DISPGP) {
1394 //              if (v3d->gpd == NULL)
1395 // XXX                  gpencil_data_setactive(ar, gpencil_data_addnew());
1396         }
1397         
1398         if (v3d->flag2 & V3D_DISPGP) {
1399 // XXX          bGPdata *gpd= v3d->gpd;
1400                 short newheight;
1401                 
1402                 /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1403                 /* so first we make it default height */
1404                 uiNewPanelHeight(block, 204);
1405                 
1406                 /* draw button for showing gpencil settings and drawings */
1407                 uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &v3d->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View (draw using Shift-LMB)");
1408                 
1409                 /* extend the panel if the contents won't fit */
1410 //              newheight= draw_gpencil_panel(block, gpd, ar); 
1411                 uiNewPanelHeight(block, newheight);
1412         }
1413         else {
1414                 uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &v3d->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View");
1415                 uiDefBut(block, LABEL, 1, " ",  160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
1416         }
1417         uiEndBlock(C, block);
1418 }
1419
1420
1421 void view3d_buttons_area_defbuts(const bContext *C, ARegion *ar)
1422 {
1423         
1424         view3d_panel_object(C, ar, 0);
1425         view3d_panel_properties(C, ar, 0);
1426         view3d_panel_background(C, ar, 0);
1427         // XXX view3d_panel_preview(C, ar, 0);
1428         view3d_panel_transform_spaces(C, ar, 0);
1429         if(0)
1430                 view3d_panel_gpencil(C, ar, 0);
1431         
1432         uiDrawPanels(C, 1);             /* 1 = align */
1433         uiMatchPanelsView2d(ar); /* sets v2d->totrct */
1434         
1435 }
1436
1437
1438 static int view3d_properties(bContext *C, wmOperator *op)
1439 {
1440         ScrArea *sa= CTX_wm_area(C);
1441         ARegion *ar= view3d_has_buttons_region(sa);
1442         
1443         if(ar) {
1444                 ar->flag ^= RGN_FLAG_HIDDEN;
1445                 
1446                 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
1447                 ED_area_tag_redraw(sa);
1448         }
1449         return OPERATOR_FINISHED;
1450 }
1451
1452 void VIEW3D_OT_properties(wmOperatorType *ot)
1453 {
1454         ot->name= "Properties";
1455         ot->idname= "VIEW3D_OT_properties";
1456         
1457         ot->exec= view3d_properties;
1458         ot->poll= ED_operator_view3d_active;
1459         
1460         /* flags */
1461         ot->flag= 0;
1462 }