-some knitpicking on low scale brushes
authorJens Ole Wund <bjornmose@gmx.net>
Tue, 31 Jan 2006 21:43:59 +0000 (21:43 +0000)
committerJens Ole Wund <bjornmose@gmx.net>
Tue, 31 Jan 2006 21:43:59 +0000 (21:43 +0000)
-- should do 'alpha' right now ..  down to brushes of 2 pixel size
-making AUX1/2 real air brushes .. must have been lost by brechts 'cleaning'

source/blender/img/intern/IMG_Api.cpp
source/blender/img/intern/IMG_BrushRGBA32.cpp
source/blender/img/intern/IMG_BrushRGBA32.h
source/blender/src/imagepaint.c

index c57e5e7c5a1cfed250ae58c3896cc15d0a81b114..e59d5bfa5860c10b49144e5b801fec8d938fed38 100644 (file)
@@ -67,7 +67,7 @@ void IMG_BrushSetInnerRaduisRatio(IMG_BrushPtr brush,float aspect)
                if (he > si) si = we;
                he = si/2;
                we = (TUns32)(aspect*si/2);
-               if (we < 2) we = 2;
+//             if (we < 2) we = 2;
 
 
                ((IMG_BrushRGBA32*)brush)->setRadii(we,he);
index 72e1c57ef63f5fbc1447619f4a74554b2c3fc29a..6678365d6da3f664d45dbbc1e99040266e7ccbb4 100644 (file)
@@ -63,7 +63,6 @@ void IMG_BrushRGBA32::setTransparency(float a)
 
 void IMG_BrushRGBA32::setRadii(TUns32 rI, TUns32 rO)
 {
-       if ((rI < 2) || (rO < 2)) return;
        m_ri = rI;
        m_ro = rO;
 
@@ -85,8 +84,9 @@ void IMG_BrushRGBA32::setRadii(TUns32 rI, TUns32 rO)
 
 void IMG_BrushRGBA32::updateImage()
 {
-    TUns32 cx = m_width >> 1;
-    TUns32 cy = m_height >> 1;
+    float fcx = m_width / 2.0f;
+    float fcy = m_height/ 2.0f ;
+
        
        // Prepare pixel values for this pixmap
        IMG_ColorRGBA c (m_color.m_r, m_color.m_g, m_color.m_b, 0.f);
@@ -102,30 +102,29 @@ void IMG_BrushRGBA32::updateImage()
                TPixelPtr desPtr = getPixelPtr(0, y);
                for (TUns32 x = 0; x < m_width; x++) {
                        // Calculate the distance between current pixel and center
-            float dX = (float)((TInt32)x) - ((TInt32)cx);
-            float dY = (float)((TInt32)y) - ((TInt32)cy);
+            float dX = (float)((TInt32)x - fcx);
+            float dY = (float)((TInt32)y - fcy);
             float d = (float) ::sqrt(dX*dX + dY*dY);
                        float a;
 
                        if (d <= m_ri) {
                                *desPtr = pIn;
                        }
-                       else if ((d < m_ro) && (m_ri < m_ro)) {
-                               // Calculate alpha, linear
-                a = (d - m_ri) / (m_ro - m_ri);
-                               // Now: 0 <= a <= 1
-                               //a = m_alpha + a * (1.f - m_alpha);
-                               a = (1.f - a) * m_alpha;
-                               // Now: m_alpha <= a <= 1
-#if 0
-                a = (float)::pow(a, 0.2);
-#endif
-                               // Store pixel
-                               *pa = (TUns8)(a * ((float)0xFF));
-                               *desPtr = p;
-                       }
-                       else {
-                               *desPtr = pOut;
+                       else { 
+                               if ((d < m_ro) && (m_ri < m_ro)) {
+                                       // Calculate alpha, linear
+                                       a = (d - m_ri) / (m_ro - m_ri);
+                                       // Now: 0 <= a <= 1
+                                       a = (float)::pow(a, 0.5f);
+                                       a = (1.f - a) * m_alpha;
+                                       // Now: m_alpha <= a <= 1
+                                       // Store pixel
+                                       *pa = (TUns8)(a * ((float)0xFF));
+                                       *desPtr = p;
+                               }
+                               else {
+                                       *desPtr = pOut;
+                               }
                        }
                        desPtr++;
                }
index 4c94131f52a30e7870167df1b347a971b541e349..90d4e124892f317b3a4bbb903388e10fbbac470c 100644 (file)
@@ -97,7 +97,7 @@ public:
         * @param       rI      inner radius
         * @param       rO      outer radius
         */
-       inline virtual void setRadii(TUns32& rI, TUns32& rO) const;
+       inline virtual void getRadii(TUns32& rI, TUns32& rO) const;
 
 protected:
        /**
@@ -113,7 +113,7 @@ protected:
 };
 
 
-inline void IMG_BrushRGBA32::setRadii(TUns32& rI, TUns32& rO) const
+inline void IMG_BrushRGBA32::getRadii(TUns32& rI, TUns32& rO) const
 {
        rI = m_ri;
        rO = m_ro;
index 7fa2f9c3cca7390aa0b603e7750d9839b02b83e2..23cd624703ec45b4205d2a039e2a1b5d0f59d938 100644 (file)
@@ -120,7 +120,9 @@ static int imagepaint_init(IMG_BrushPtr **brush, IMG_CanvasPtr **canvas, IMG_Can
                *clonecanvas= NULL;
        
        /* initialize paint settings */
-       if(Gip.current >= IMAGEPAINT_AIRBRUSH && Gip.current <= IMAGEPAINT_SOFTEN)
+       if((Gip.current == IMAGEPAINT_AIRBRUSH) ||
+          (Gip.current ==  IMAGEPAINT_AUX1) ||
+          (Gip.current ==  IMAGEPAINT_AUX2))
                Gip.flag |= IMAGEPAINT_TIMED;
        else
                Gip.flag &= ~IMAGEPAINT_TIMED;
@@ -184,6 +186,8 @@ static void imagepaint_paint_tool(IMG_BrushPtr *brush, IMG_CanvasPtr *canvas, IM
 
                IMG_CanvasCloneAt(canvas, clonecanvas, prevuv[0], prevuv[1], offx, offy, tool->size, tool->rgba[3], tool->innerradius);
        }
+       else if(Gip.flag & IMAGEPAINT_TIMED) 
+               IMG_CanvasDrawLineUVEX(canvas, brush,  uv[0], uv[1],uv[0], uv[1], torus);
        else
                IMG_CanvasDrawLineUVEX(canvas, brush, prevuv[0], prevuv[1], uv[0], uv[1], torus);
 }
@@ -195,7 +199,7 @@ void imagepaint_paint(short mousebutton)
        short prevmval[2], mval[2];
        double prevtime, curtime;
        float prevuv[2], uv[2];
-       int paint= 0, moved= 0;
+       int paint= 0, moved= 0, firsttouch=1 ;
        ImagePaintTool *tool= &Gip.tool[Gip.current];
 
        if(!imagepaint_init(&brush, &canvas, &clonecanvas))
@@ -215,10 +219,11 @@ void imagepaint_paint(short mousebutton)
                        /* see if need to draw because of timer */
                        curtime = PIL_check_seconds_timer();
 
-                       if((curtime - prevtime) > (5.0/tool->timing)) {
+                       if(((curtime - prevtime) > (5.0/tool->timing)) || firsttouch) {
                                prevtime= curtime;
                                paint= 1;
                        }
+                       else paint= 0;
                }
                else if(paint) {
                        /* check if we moved enough to draw */
@@ -244,6 +249,7 @@ void imagepaint_paint(short mousebutton)
                        prevmval[0]= mval[0];
                        prevmval[1]= mval[1];
                }
+               firsttouch = 0;
 
                if(paint)
                        imagepaint_redraw(0, paint);