merge from trunk - r17500 to HEAD
authorCampbell Barton <ideasman42@gmail.com>
Wed, 10 Dec 2008 09:45:48 +0000 (09:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 10 Dec 2008 09:45:48 +0000 (09:45 +0000)
1  2 
source/blender/include/butspace.h
source/blender/src/buttons_editing.c
source/blender/src/space.c

index 5612f56fee8c49b11af79d2cdb754622f9f97a4f,7019a3f6959f0b457e1546b3bdb0bc67fcf40c62..868d0c3e6c0db4a6d29ef8995f8f91f6bda54576
@@@ -103,6 -103,13 +103,13 @@@ extern void do_cambuts(unsigned short e
  extern void do_armbuts(unsigned short event);
  extern void do_uvcalculationbuts(unsigned short event);
  extern void weight_paint_buttons(struct uiBlock *);
+ extern void brush_buttons(struct uiBlock *block, short sima,
+                               int evt_nop, int evt_change,
+                               int evt_browse, int evt_local,
+                               int evt_del, int evt_keepdata,
+                               int evt_texbrowse, int evt_texdel);
  extern void particle_edit_buttons(struct uiBlock *);
  
  extern char *get_vertexgroup_menustr(struct Object *ob);      // used in object buttons
@@@ -446,8 -453,6 +453,8 @@@ void curvemap_buttons(struct uiBlock *b
  
  #define B_GEN_SKELETON                2085
  #define B_RETARGET_SKELETON   2086
 +#define B_SETTFACE_CLONE      2087
 +#define B_SETTFACE_MASK               2088
  
  /* *********************** */
  #define B_VGROUPBUTS          2100
index 3d8bdb749bc1356ccdb3c93cef8c298cb5938ec5,edf4660b71e3fadcb23b678e6e16f71fce1bfb30..65b992682de16134a624d6a0a84996524a33e615
  
  static float editbutweight= 1.0;
  float editbutvweight= 1;
 -static int actmcol= 0, acttface= 0, acttface_rnd = 0, actmcol_rnd = 0;
 +static int actmcol= 0, acttface= 0, acttface_rnd = 0, acttface_clone = 0, acttface_mask = 0, actmcol_rnd = 0;
  
  extern ListBase editNurb;
  
@@@ -722,10 -722,10 +722,10 @@@ static void delete_customdata_layer(voi
        Mesh *me= (Mesh*)data1;
        CustomData *data= (G.obedit)? &G.editMesh->fdata: &me->fdata;
        CustomDataLayer *layer= (CustomDataLayer*)data2;
 -      void *actlayerdata, *rndlayerdata, *layerdata=layer->data;
 +      void *actlayerdata, *rndlayerdata, *clonelayerdata, *masklayerdata, *layerdata=layer->data;
        int type= layer->type;
        int index= CustomData_get_layer_index(data, type);
 -      int i, actindex, rndindex;
 +      int i, actindex, rndindex, cloneindex, maskindex;
        
        /*ok, deleting a non-active layer needs to preserve the active layer indices.
          to do this, we store a pointer to the .data member of both layer and the active layer,
          layer. */
        actlayerdata = data->layers[CustomData_get_active_layer_index(data, type)].data;
        rndlayerdata = data->layers[CustomData_get_render_layer_index(data, type)].data;
 +      clonelayerdata = data->layers[CustomData_get_clone_layer_index(data, type)].data;
 +      masklayerdata = data->layers[CustomData_get_mask_layer_index(data, type)].data;
        CustomData_set_layer_active(data, type, layer - &data->layers[index]);
  
        /* Multires is handled seperately because the display data is separate
                CustomData_set_layer_render(data, type, rndindex);
        }
        
 +      if (clonelayerdata != layerdata) {
 +              /*find index. . .*/
 +              cloneindex = CustomData_get_layer_index(data, type);
 +              for (i=cloneindex; i<data->totlayer; i++) {
 +                      if (data->layers[i].data == clonelayerdata) {
 +                              cloneindex = i - cloneindex;
 +                              break;
 +                      }
 +              }
 +              
 +              /*set index. . .*/
 +              CustomData_set_layer_clone(data, type, cloneindex);
 +      }
 +      
 +      if (masklayerdata != layerdata) {
 +              /*find index. . .*/
 +              maskindex = CustomData_get_layer_index(data, type);
 +              for (i=maskindex; i<data->totlayer; i++) {
 +                      if (data->layers[i].data == masklayerdata) {
 +                              maskindex = i - maskindex;
 +                              break;
 +                      }
 +              }
 +              
 +              /*set index. . .*/
 +              CustomData_set_layer_mask(data, type, maskindex);
 +      }
        
        DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
        
  
  static int customdata_buttons(
        uiBlock *block, Mesh *me, CustomData *data,
 -      int type, int *activep, int *renderp,
 -      int setevt, int setevt_rnd, int newevt,
 -      char *label, char *shortlabel, char *browsetip, char *browsetip_rnd,
 +      int type, int *activep, int *renderp, int *clonep, int *maskp,
 +      int setevt, int setevt_rnd, int setevt_clone, int setevt_mask, int newevt,
 +      char *label, char *shortlabel, char *browsetip, char *browsetip_rnd, char *browsetip_clone, char *browsetip_mask,
        char *newtip, char *deltip, int x, int y)
  {
        CustomDataLayer *layer;
                layer= &data->layers[i];
  
                if(layer->type == type) {
 +                      int xi = 0;
                        *activep= layer->active + 1;
                        *renderp= layer->active_rnd + 1;
 +                      if (clonep) *clonep= layer->active_clone + 1;
 +                      if (maskp) *maskp= layer->active_mask + 1;
 +                      
                        
                        uiDefIconButI(block, ROW, setevt, ICON_VIEW3D, x,y,25,19, activep, 1.0, count, 0, 0, browsetip);
                        uiDefIconButI(block, ROW, setevt_rnd, ICON_SCENE, x+25,y,25,19, renderp, 1.0, count, 0, 0, browsetip_rnd);
 -                      but=uiDefBut(block, TEX, setevt, "", x+50,y,145,19, layer->name, 0.0, 31.0, 0, 0, label);
 +                      
 +                      if (clonep) {
 +                              uiDefIconButI(block, ROW, setevt_clone, ICON_TEXTURE, x+50,y,25,19, clonep, 1.0, count, 0, 0, browsetip_clone);
 +                              xi += 25;
 +                      }
 +                      
 +                      if (maskp) {
 +                              uiDefIconButI(block, ROW, setevt_mask, ICON_PAINT, x+50+xi,y,25,19, maskp, 1.0, count, 0, 0, browsetip_mask);
 +                              xi += 25;
 +                      }
 +                      
 +                      but=uiDefBut(block, TEX, setevt, "", x+50+xi,y,145-xi,19, layer->name, 0.0, 31.0, 0, 0, label);
                        uiButSetFunc(but, verify_customdata_name_func, data, layer);
                        but= uiDefIconBut(block, BUT, B_NOP, VICON_X, x+195,y,25,19, NULL, 0.0, 0.0, 0.0, 0.0, deltip);
                        uiButSetFunc(but, delete_customdata_layer, me, layer);
@@@ -946,14 -902,14 +946,14 @@@ static void editing_panel_mesh_type(Obj
        uiBlockEndAlign(block);
  
        fdata= (G.obedit)? &G.editMesh->fdata: &me->fdata;
 -      yco= customdata_buttons(block, me, fdata, CD_MTFACE, &acttface, &acttface_rnd,
 -              B_SETTFACE, B_SETTFACE_RND, B_NEWTFACE, "UV Texture", "UV Texture:",
 -              "Set active UV texture", "Set rendering UV texture", "Creates a new UV texture layer",
 +      yco= customdata_buttons(block, me, fdata, CD_MTFACE, &acttface, &acttface_rnd, (G.f & G_TEXTUREPAINT ? &acttface_clone : NULL), (G.f & G_TEXTUREPAINT ? &acttface_mask : NULL),
 +              B_SETTFACE, B_SETTFACE_RND, B_SETTFACE_CLONE, B_SETTFACE_MASK, B_NEWTFACE, "UV Texture", "UV Texture:",
-               "Set active UV texture", "Set rendering UV texture", "Set the layer used for texturepaint cloning", "Set the layer used for texturepaint masking", "Creates a new UV texture layer",
++              "Set active UV texture", "Set rendering UV texture", "Set the layer used for texturepaint cloning", "Set the texture paint stencil layer", "Creates a new UV texture layer",
                "Removes the current UV texture layer", 190, 130);
  
 -      yco= customdata_buttons(block, me, fdata, CD_MCOL, &actmcol, &actmcol_rnd,
 -              B_SETMCOL, B_SETMCOL_RND, B_NEWMCOL, "Vertex Color", "Vertex Color:",
 -              "Sets active vertex color layer", "Sets rendering vertex color layer", "Creates a new vertex color layer",
 +      yco= customdata_buttons(block, me, fdata, CD_MCOL, &actmcol, &actmcol_rnd, NULL, NULL,
 +              B_SETMCOL, B_SETMCOL_RND, B_NOP, B_NOP, B_NEWMCOL, "Vertex Color", "Vertex Color:",
 +              "Sets active vertex color layer", "Sets rendering vertex color layer", "", "", "Creates a new vertex color layer",
                "Removes the current vertex color layer", 190, yco-5);
  
        if(yco < 0)
@@@ -5008,22 -4964,7 +5008,22 @@@ void do_meshbuts(unsigned short event
                                allqueue(REDRAWBUTSEDIT, 0);
                        }
                        break;
 -                      
 +              case B_SETTFACE_CLONE:
 +                      if (G.obedit || me) {
 +                              CustomData *fdata= (G.obedit)? &em->fdata: &me->fdata;
 +                              CustomData_set_layer_clone(fdata, CD_MTFACE, acttface_clone-1);
 +                              BIF_undo_push("Set Clone UV Texture");
 +                              allqueue(REDRAWBUTSEDIT, 0);
 +                      }
 +                      break;
 +              case B_SETTFACE_MASK:
 +                      if (G.obedit || me) {
 +                              CustomData *fdata= (G.obedit)? &em->fdata: &me->fdata;
 +                              CustomData_set_layer_mask(fdata, CD_MTFACE, acttface_mask-1);
 +                              BIF_undo_push("Set Mask UV Texture");
 +                              allqueue(REDRAWBUTSEDIT, 0);
 +                      }
 +                      break;
                case B_FLIPNORM:
                        if(G.obedit) {
                                flip_editnormals();
@@@ -5429,7 -5370,7 +5429,7 @@@ char *get_vertexgroup_menustr(Object *o
                qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
                                                                 "qsort_ptr");
                for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
-                       printed = snprintf (qsort_ptr[index - 1], sizeof (dg->name), dg->name);
+                       printed = snprintf (qsort_ptr[index - 1], sizeof (dg->name), "%s", dg->name);
                        snprintf (qsort_ptr[index - 1]+printed, 6+1, "%%x%d|", index); // +1 to move the \0   see above 999 max here too
                }
                
@@@ -6329,6 -6270,94 +6329,125 @@@ void weight_paint_buttons(uiBlock *bloc
        }
  }
  
 -      int yco, xco, butw;
+ void brush_buttons(uiBlock *block, short sima,
+               int evt_nop, int evt_change,
+               int evt_browse, int evt_local,
+               int evt_del, int evt_keepdata,
+               int evt_texbrowse, int evt_texdel)
+ {
+       ToolSettings *settings= G.scene->toolsettings;
+       Brush *brush= settings->imapaint.brush;
+       ID *id;
 -      uiDefButS(block, ROW, evt_change, "Draw",               0,              yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_DRAW, 0, 0, "Draw brush");
 -      uiDefButS(block, ROW, evt_change, "Soften",             butw,   yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SOFTEN, 0, 0, "Soften brush");
 -      uiDefButS(block, ROW, evt_change, "Smear",              butw*2, yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SMEAR, 0, 0, "Smear brush");
 -      if (sima)
 -              uiDefButS(block, ROW, evt_change, "Clone",      butw*3, yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_CLONE, 0, 0, "Clone brush, use RMB to drag source image");
++      int yco, xco, butw, but_idx;
+       short *menupoin = sima ? &(G.sima->menunr) : &(G.buts->menunr);
++      short do_project = settings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE ? 0:1;
+       
+       yco= 160;
+       butw = sima ? 80 : 106;
+       
+       uiBlockBeginAlign(block);
 -
 -              uiDefButBitS(block, TOG|BIT, BRUSH_TORUS, evt_change, "Wrap",   xco+10,yco-25,butw,19, &brush->flag, 0, 0, 0, 0, "Enables torus wrapping");
 -
++      but_idx = 0;
++      uiDefButS(block, ROW, evt_change, "Draw",               butw*(but_idx++),yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_DRAW, 0, 0, "Draw brush");
++      if (sima || do_project==0)
++              uiDefButS(block, ROW, evt_change, "Soften",     butw*(but_idx++),       yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SOFTEN, 0, 0, "Soften brush");
++      uiDefButS(block, ROW, evt_change, "Smear",              butw*(but_idx++),       yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SMEAR, 0, 0, "Smear brush");
++      if (sima || do_project)
++              uiDefButS(block, ROW, evt_change, "Clone",      butw*(but_idx++),       yco,butw,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_CLONE, 0, 0, "Clone brush, use RMB to drag source image");
+       
+       uiBlockEndAlign(block);
+       yco -= 30;
+        
+       uiBlockSetCol(block, TH_BUT_SETTING2);
+       id= (ID*)settings->imapaint.brush;
+       xco= std_libbuttons(block, 0, yco, 0, NULL, evt_browse, ID_BR, 0, id, NULL, menupoin, 0, evt_local, evt_del, 0, evt_keepdata);
+       uiBlockSetCol(block, TH_AUTO);
+       if(brush && !brush->id.lib) {
+               butw= 320-(xco+10);
+               uiDefButS(block, MENU, evt_nop, "Mix %x0|Add %x1|Subtract %x2|Multiply %x3|Lighten %x4|Darken %x5|Erase Alpha %x6|Add Alpha %x7", xco+10,yco,butw,19, &brush->blend, 0, 0, 0, 0, "Blending method for applying brushes");
 -              uiDefButBitS(block, TOG|BIT, BRUSH_AIRBRUSH, evt_change, "Airbrush",    xco+10,yco-50,butw,19, &brush->flag, 0, 0, 0, 0, "Keep applying paint effect while holding mouse (spray)");
 -              uiDefButF(block, NUM, evt_nop, "Rate ", xco+10,yco-70,butw,19, &brush->rate, 0.01, 1.0, 0, 0, "Number of paints per second for Airbrush");
++      
+               uiBlockBeginAlign(block);
 -
 -              yco -= 25;
 -
++              uiDefButBitS(block, TOG|BIT, BRUSH_AIRBRUSH, evt_change, "Airbrush",    xco+10,yco-25,butw/2,19, &brush->flag, 0, 0, 0, 0, "Keep applying paint effect while holding mouse (spray)");
++              uiDefButF(block, NUM, evt_nop, "", xco+10 + butw/2,yco-25,butw/2,19, &brush->rate, 0.01, 1.0, 0, 0, "Number of paints per second for Airbrush");
+               uiBlockEndAlign(block);
++              
++              if (sima) {
++                      uiDefButBitS(block, TOG|BIT, BRUSH_TORUS, evt_change, "Wrap",   xco+10,yco-45,butw,19, &brush->flag, 0, 0, 0, 0, "Enables torus wrapping");
++                      yco -= 25;
++              }
++              else {
++                      yco -= 25;
++                      uiBlockBeginAlign(block);
++                      uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_DISABLE, B_REDR, "Project Paint",      xco+10,yco-25,butw,19, &settings->imapaint.flag, 0, 0, 0, 0, "Use projection painting for improved consistency in the brush strokes");
++                      
++                      if ((settings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE)==0) {
++                              
++                              
++                              /* Projection Painting */
++                              
++                              uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_XRAY, B_NOP, "Occlude",        xco+10,yco-45,butw/2,19, &settings->imapaint.flag, 0, 0, 0, 0, "Only paint onto the faces directly under the brush (slower)");
++                              uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_BACKFACE, B_NOP, "Cull",       xco+10+butw/2,yco-45,butw/2,19, &settings->imapaint.flag, 0, 0, 0, 0, "Ignore faces pointing away from the view (faster)");
++                              
++                              uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_FLAT, B_NOP, "Normal", xco+10,yco-65,butw/2,19, &settings->imapaint.flag, 0, 0, 0, 0, "Paint most on faces pointing towards the view");
++                              uiDefButS(block, NUM, B_NOP, "", xco+10 +(butw/2),yco-65,butw/2,19, &settings->imapaint.normal_angle, 10.0, 90.0, 0, 0, "Paint most on faces pointing towards the view acording to this angle)");
++                              
++                              uiDefButS(block, NUM, B_NOP, "Bleed: ", xco+10,yco-85,butw,19, &settings->imapaint.seam_bleed, 0.0, 8.0, 0, 0, "Extend paint beyond the faces UVs to reduce seams (in pixels, slower)");
++                              uiBlockEndAlign(block);
++                              
++                              uiBlockBeginAlign(block);
++                              uiDefButBitS(block, TOG|BIT, IMAGEPAINT_PROJECT_LAYER_MASK, B_NOP, "Stencil Layer",     xco+10,yco-110,butw-30,19, &settings->imapaint.flag, 0, 0, 0, 0, "Set the mask layer from the UV layer buttons");
++                              uiDefButBitS(block, TOG|BIT, IMAGEPAINT_PROJECT_LAYER_MASK_INV, B_NOP, "Inv",   xco+10 + butw-30,yco-110,30,19, &settings->imapaint.flag, 0, 0, 0, 0, "Invert the mask");
++                              uiBlockEndAlign(block);
++                              
++                      }
++                      uiBlockEndAlign(block);
++              }
++              
+               uiBlockBeginAlign(block);
+               uiDefButF(block, COL, B_VPCOLSLI, "",                                   0,yco,200,19, brush->rgb, 0, 0, 0, 0, "");
+               uiDefButF(block, NUMSLI, evt_nop, "Opacity ",           0,yco-20,180,19, &brush->alpha, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
+               uiDefButBitS(block, TOG|BIT, BRUSH_ALPHA_PRESSURE, evt_nop, "P",        180,yco-20,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
+               uiDefButI(block, NUMSLI, evt_nop, "Size ",              0,yco-40,180,19, &brush->size, 1, 200, 0, 0, "The size of the brush");
+               uiDefButBitS(block, TOG|BIT, BRUSH_SIZE_PRESSURE, evt_nop, "P", 180,yco-40,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
+               uiDefButF(block, NUMSLI, evt_nop, "Falloff ",           0,yco-60,180,19, &brush->innerradius, 0.0, 1.0, 0, 0, "The fall off radius of the brush");
+               uiDefButBitS(block, TOG|BIT, BRUSH_RAD_PRESSURE, evt_nop, "P",  180,yco-60,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
+               uiDefButF(block, NUMSLI, evt_nop, "Spacing ",0,yco-80,180,19, &brush->spacing, 1.0, 100.0, 0, 0, "Repeating paint on %% of brush diameter");
+       uiDefButBitS(block, TOG|BIT, BRUSH_SPACING_PRESSURE, evt_nop, "P",      180,yco-80,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
+               uiBlockEndAlign(block);
+               yco -= 110;
+               if(sima && settings->imapaint.tool == PAINT_TOOL_CLONE) {
+                       id= (ID*)brush->clone.image;
+                       uiBlockSetCol(block, TH_BUT_SETTING2);
+                       xco= std_libbuttons(block, 0, yco, 0, NULL, B_SIMACLONEBROWSE, ID_IM, 0, id, 0, menupoin, 0, 0, B_SIMACLONEDELETE, 0, 0);
+                       uiBlockSetCol(block, TH_AUTO);
+                       if(id) {
+                               butw= 320-(xco+5);
+                               uiDefButF(block, NUMSLI, evt_change, "B ",xco+5,yco,butw,19, &brush->clone.alpha , 0.0, 1.0, 0, 0, "Opacity of clone image display");
+                       }
+               }
+               else {
+                       MTex *mtex= brush->mtex[brush->texact];
+                       
+                       uiBlockSetCol(block, TH_BUT_SETTING2);
+                       id= (mtex)? (ID*)mtex->tex: NULL;
+                       xco= std_libbuttons(block, 0, yco, 0, NULL, evt_texbrowse, ID_TE, 0, id, NULL, menupoin, 0, 0, evt_texdel, 0, 0);
+                       /*uiDefButBitS(block, TOG|BIT, BRUSH_FIXED_TEX, evt_change, "Fixed",    xco+5,yco,butw,19, &brush->flag, 0, 0, 0, 0, "Keep texture origin in fixed position");*/
+                       uiBlockSetCol(block, TH_AUTO);
+               }
+       }
+       
+ #if 0
+               uiDefButBitS(block, TOG|BIT, IMAGEPAINT_DRAW_TOOL_DRAWING, B_SIMABRUSHCHANGE, "TD", 0,1,50,19, &settings->imapaint.flag.flag, 0, 0, 0, 0, "Enables brush shape while drawing");
+               uiDefButBitS(block, TOG|BIT, IMAGEPAINT_DRAW_TOOL, B_SIMABRUSHCHANGE, "TP", 50,1,50,19, &settings->imapaint.flag.flag, 0, 0, 0, 0, "Enables brush shape while not drawing");
+ #endif
+ }
  static void editing_panel_mesh_paint(void)
  {
        uiBlock *block;
                uiBlockEndAlign(block);
        }
        else { /* texture paint */
-               ToolSettings *settings= G.scene->toolsettings;
-               Brush *brush= settings->imapaint.brush;
-               ID *id;
-               int yco, xco, butw;
-               yco= 160;
-               uiBlockBeginAlign(block);
-               if ((settings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE)==0) {
-                       uiDefButS(block, ROW, B_SIMABRUSHCHANGE, "Draw",                0  ,yco,108,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_DRAW, 0, 0, "Draw brush");
-                       uiDefButS(block, ROW, B_SIMABRUSHCHANGE, "Smear",               108 ,yco,106,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SMEAR, 0, 0, "Smear brush"); 
-                       uiDefButS(block, ROW, B_SIMABRUSHCHANGE, "Clone",               214,yco,106,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_CLONE, 0, 0, "Clone brush, use RMB to drag source image");
-               }
-               else { 
-                       uiDefButS(block, ROW, B_BRUSHCHANGE, "Draw",            0  ,yco,108,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_DRAW, 0, 0, "Draw brush");
-                       uiDefButS(block, ROW, B_BRUSHCHANGE, "Soften",          108 ,yco,106,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SOFTEN, 0, 0, "Soften brush");
-                       uiDefButS(block, ROW, B_BRUSHCHANGE, "Smear",           214,yco,106,19, &settings->imapaint.tool, 7.0, PAINT_TOOL_SMEAR, 0, 0, "Smear brush");  
-               }       
-               
-               uiBlockEndAlign(block);
-               yco -= 30;
-               uiBlockSetCol(block, TH_BUT_SETTING2);
-               id= (ID*)settings->imapaint.brush;
-               xco= std_libbuttons(block, 0, yco, 0, NULL, B_BRUSHBROWSE, ID_BR, 0, id, NULL, &(G.buts->menunr), 0, B_BRUSHLOCAL, B_BRUSHDELETE, 0, B_BRUSHKEEPDATA);
-               uiBlockSetCol(block, TH_AUTO);
-               if(brush && !brush->id.lib) {
-                       MTex *mtex= brush->mtex[brush->texact];
-                       butw= 320-(xco+10);
-                       uiDefButS(block, MENU, B_NOP, "Mix %x0|Add %x1|Subtract %x2|Multiply %x3|Lighten %x4|Darken %x5|Erase Alpha %x6|Add Alpha %x7", xco+10,yco,butw,19, &brush->blend, 0, 0, 0, 0, "Blending method for applying brushes");
-                       // uiDefButBitS(block, TOG|BIT, BRUSH_TORUS, B_BRUSHCHANGE, "Wrap",     xco+10,yco-25,butw,19, &brush->flag, 0, 0, 0, 0, "Enables torus wrapping");
-                       uiBlockBeginAlign(block);
-                       uiDefButBitS(block, TOG|BIT, BRUSH_AIRBRUSH, B_BRUSHCHANGE, "Airbrush", xco+10,yco-25,butw,19, &brush->flag, 0, 0, 0, 0, "Keep applying paint effect while holding mouse (spray)");
-                       uiDefButF(block, NUM, B_NOP, "Rate ", xco+10,yco-45,butw,19, &brush->rate, 0.01, 1.0, 0, 0, "Number of paints per second for Airbrush");
-                       uiBlockEndAlign(block);
-                       
-                       uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_DISABLE, B_REDR, "Project Paint",      xco+10,yco-70,butw,19, &settings->imapaint.flag, 0, 0, 0, 0, "Use projection painting for improved consistency in the brush strokes");
-                       
-                       yco -= 50;
-                       
-                       if ((settings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE)==0) {
-                               //uiDefButBitS(block, TOG|BIT, BRUSH_TORUS, B_BRUSHCHANGE, "Wrap",      xco+10,yco-25,butw,19, &brush->flag, 0, 0, 0, 0, "Enables torus wrapping");
-                               
-                               /* Projection Painting */
-                               uiBlockBeginAlign(block);
-                               uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_XRAY, B_NOP, "Occlude",        xco+10,yco-45,butw/2,19, &settings->imapaint.flag, 0, 0, 0, 0, "Only paint onto the faces directly under the brush (slower)");
-                               uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_BACKFACE, B_NOP, "Cull",       xco+10+butw/2,yco-45,butw/2,19, &settings->imapaint.flag, 0, 0, 0, 0, "Ignore faces pointing away from the view (faster)");
-                               
-                               uiDefButBitS(block, TOGN|BIT, IMAGEPAINT_PROJECT_FLAT, B_NOP, "Normal", xco+10,yco-65,butw/2,19, &settings->imapaint.flag, 0, 0, 0, 0, "Paint most on faces pointing towards the view");
-                               uiDefButC(block, NUM, B_NOP, "", xco+10 +(butw/2),yco-65,butw/2,19, &settings->imapaint.normal_angle, 10.0, 90.0, 0, 0, "Paint most on faces pointing towards the view acording to this angle)");
-                               
-                               uiDefButC(block, NUM, B_NOP, "Bleed: ", xco+10,yco-85,butw,19, &settings->imapaint.seam_bleed, 0.0, 8.0, 0, 0, "Extend paint beyond the faces UVs to reduce seams (in pixels, slower)");
-                               uiBlockEndAlign(block);
-                               
-                               uiBlockBeginAlign(block);
-                               uiDefButBitS(block, TOG|BIT, IMAGEPAINT_PROJECT_LAYER_MASK, B_NOP, "Layer Mask",        xco+10,yco-110,butw-30,19, &settings->imapaint.flag, 0, 0, 0, 0, "Set the mask layer from the UV layer buttons");
-                               uiDefButBitS(block, TOG|BIT, IMAGEPAINT_PROJECT_LAYER_MASK_INV, B_NOP, "Inv",   xco+10 + butw-30,yco-110,30,19, &settings->imapaint.flag, 0, 0, 0, 0, "Invert the mask");
-                               uiBlockEndAlign(block);
-                               
-                       }
-                       
-                       uiBlockBeginAlign(block);
-                       uiDefButF(block, COL, B_VPCOLSLI, "",                                   0,yco,200,19, brush->rgb, 0, 0, 0, 0, "");
-                       uiDefButF(block, NUMSLI, B_NOP, "Opacity ",             0,yco-20,180,19, &brush->alpha, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
-                       uiDefButBitS(block, TOG|BIT, BRUSH_ALPHA_PRESSURE, B_NOP, "P",  180,yco-20,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
-                       uiDefButI(block, NUMSLI, B_NOP, "Size ",                0,yco-40,180,19, &brush->size, 1, 200, 0, 0, "The size of the brush");
-                       uiDefButBitS(block, TOG|BIT, BRUSH_SIZE_PRESSURE, B_NOP, "P",   180,yco-40,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
-                       uiDefButF(block, NUMSLI, B_NOP, "Falloff ",             0,yco-60,180,19, &brush->innerradius, 0.0, 1.0, 0, 0, "The fall off radius of the brush");
-                       uiDefButBitS(block, TOG|BIT, BRUSH_RAD_PRESSURE, B_NOP, "P",    180,yco-60,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
-                       uiDefButF(block, NUMSLI, B_NOP, "Spacing ",0,yco-80,180,19, &brush->spacing, 1.0, 100.0, 0, 0, "Repeating paint on %% of brush diameter");
-               uiDefButBitS(block, TOG|BIT, BRUSH_SPACING_PRESSURE, B_NOP, "P",        180,yco-80,20,19, &brush->flag, 0, 0, 0, 0, "Enables pressure sensitivity for tablets");
-                       uiBlockEndAlign(block);
-                       yco -= 110;
-                       if (settings->imapaint.tool == PAINT_TOOL_CLONE) {
-                               if ((settings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE)==0) {
-                                       butw = 130;
-                                       uiBlockBeginAlign(block);
-                                       uiDefButBitS(block, TOG|BIT, IMAGEPAINT_PROJECT_LAYER_CLONE, B_REDR, "Clone from Layer",        0,yco,butw,20, &settings->imapaint.flag, 0, 0, 0, 0, "Use another UV layer as clone source, otherwise use 3D the cursor as the source");
-                                       uiBlockEndAlign(block);
-                               }
-                       } else {
-                               uiBlockSetCol(block, TH_BUT_SETTING2);
-                               id= (mtex)? (ID*)mtex->tex: NULL;
-                               xco= std_libbuttons(block, 0, yco, 0, NULL, B_BTEXBROWSE, ID_TE, 0, id, NULL, &(G.buts->menunr), 0, 0, B_BTEXDELETE, 0, 0);
-                               /*uiDefButBitS(block, TOG|BIT, BRUSH_FIXED_TEX, B_BRUSHCHANGE, "Fixed", xco+5,yco,butw,19, &brush->flag, 0, 0, 0, 0, "Keep texture origin in fixed position");*/
-                               uiBlockSetCol(block, TH_AUTO);
-                       }
-               }
+               brush_buttons(block, 0, B_NOP, B_BRUSHCHANGE, B_BRUSHBROWSE, B_BRUSHLOCAL, B_BRUSHDELETE, B_BRUSHKEEPDATA, B_BTEXBROWSE, B_BTEXDELETE);
        }
  }
  
index cb31c3f29688f21486e7ee524c36b6a4e8215a94,e34624a25fecee7f03c4a14365d171a580a2979b..4267159baee6983e8444542ade0830d10e7905df
@@@ -1247,18 -1247,19 +1247,19 @@@ static void winqreadview3dspace(ScrAre
                if( uiDoBlocks(&curarea->uiblocks, event, 1)!=UI_NOTHING ) event= 0;
                
                if(event==UI_BUT_EVENT) do_butspace(val); /* temporal, view3d deserves own queue? */
-               
+ #ifndef DISABLE_PYTHON
+                       /* run any view3d event handler script links */
+               if(sa->scriptlink.totscript) {
+                       if(BPY_do_spacehandlers(sa, event, val, SPACEHANDLER_VIEW3D_EVENT))
+                               return; /* return if event was processed (swallowed) by handler(s) */
+               }
+ #endif
                /* - we consider manipulator a button, defaulting to leftmouse 
                 * - grease-pencil also defaults to leftmouse
                 */
                if(event==LEFTMOUSE) {
- #ifndef DISABLE_PYTHON
-                       /* run any view3d event handler script links */
-                       if (sa->scriptlink.totscript) {
-                               if (BPY_do_spacehandlers(sa, event, val, SPACEHANDLER_VIEW3D_EVENT))
-                                       return; /* return if event was processed (swallowed) by handler(s) */
-                       }
- #endif
                        if(gpencil_do_paint(sa, L_MOUSE)) return;
                        if(BIF_do_manipulator(sa)) return;
                }
                                        }
                                }
                        }
 +                      else if (!G.obedit && OBACT && G.f&G_TEXTUREPAINT){
 +                              if(G.scene->toolsettings->imapaint.brush &&
 +                                      event!=LEFTMOUSE && event!=RIGHTMOUSE && event!=MIDDLEMOUSE &&
 +                                      (event==MOUSEY || event==MOUSEX) && bwin_qtest(sa->win)==0) {
 +                                      allqueue(REDRAWVIEW3D, 0);
 +                              }
 +                      }
 +                      
  
                        /* Handle retopo painting */
                        if(retopo_mesh_paint_check()) {
                        }
                }
        }
-       
+ #ifndef DISABLE_PYTHON
+       else { /* val= 0 */
+               /* run any view3d release event handler script links */
+               if(sa->scriptlink.totscript) {
+                       if(BPY_do_spacehandlers(sa, event, 0, SPACEHANDLER_VIEW3D_EVENT_ALL))
+                               return; /* return if event was processed (swallowed) by handler(s) */
+               }
+       }
+ #endif
        if(doredraw) {
                scrarea_queue_winredraw(curarea);
                scrarea_queue_headredraw(curarea);