Author: stephane
Date: 2007-12-06 15:01:08 -0500 (Thu, 06 Dec 2007)
New Revision: 90846

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/brush.cpp
   trunk/moon/src/media.cpp
   trunk/moon/test/xaml/test-relativetransform.xaml
Log:
2007-12-06  Stephane Delcroix  <[EMAIL PROTECTED]>

        * media.cpp:
        * brush.cpp: implement RelativeTransform for image brushes and 
        LinearGradientBrush. RadialGradientBrush still missing.


Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-12-06 19:22:52 UTC (rev 90845)
+++ trunk/moon/src/ChangeLog    2007-12-06 20:01:08 UTC (rev 90846)
@@ -1,3 +1,9 @@
+2007-12-06  Stephane Delcroix  <[EMAIL PROTECTED]>
+
+       * media.cpp:
+       * brush.cpp: implement RelativeTransform for image brushes and 
+       LinearGradientBrush. RadialGradientBrush still missing.
+
 2007-12-06  Chris Toshok  <[EMAIL PROTECTED]>
 
        * dependencyobject.h, dependencyobject.cpp: make

Modified: trunk/moon/src/brush.cpp
===================================================================
--- trunk/moon/src/brush.cpp    2007-12-06 19:22:52 UTC (rev 90845)
+++ trunk/moon/src/brush.cpp    2007-12-06 20:01:08 UTC (rev 90846)
@@ -102,6 +102,64 @@
        brush->SetValue (Brush::TransformProperty, Value (transform));
 }
 
+void
+compute_relative_transform (cairo_matrix_t *matrix, double width, double 
height, Transform *relative_transform, bool invert)
+{
+       // note about de-relativisation of transforms
+       //
+       // applying a transormation with a different center than 0,0 is equ. to 
: translate the center to 0,0, 
+       // apply the transform, re-translate. So, finding the (relative) center 
for the transform is solving
+       // the following linear equation
+       //
+       // |  1   0  0 |   | xx yx 0 |   | 1  0  0 |   | xx yx 0 |
+       // |  0   1  0 | x | xy yy 0 | x | 0  1  0 | = | xy yy 0 |
+       // | -rx -ry 1 |   | 0  0  1 |   | rx ry 1 |   | xo y0 1 |
+       //
+       // the de-relativized translation is then tx = width * rx and ty = 
height * ry
+       //
+       // (at that point, I don't know which method is faster: let cairo 
recompute T1 x M x T2 or 
+       // substitute the new x0 and y0 in the matrix)
+       //
+       // end of note
+
+       cairo_matrix_t tm;
+       double rx, ry, tx, ty;
+       transform_get_transform (relative_transform, &tm);
+       //printf ("relative_transform       xx: %f, yx: %f, xy: %f, yy: %f, x0: 
%f, y0: %f\n", tm.xx, tm.yx, tm.xy, tm.yy, tm.x0, tm.y0);
+       if (tm.xx != 1.0) {
+               if (tm.yy - tm.xx*tm.yy + tm.xy*tm.yx + tm.xx != 1 ) {
+                       ry = (tm.y0 - tm.xx * tm.y0 + tm.yx * tm.x0) / (1 - 
tm.xx - tm.yy + tm.yy * tm.yy - tm.xy * tm.yx);
+                       rx = (tm.x0 + tm.xy * ry) / (1 - tm.xx);
+               } else { //yy - xxyy + xyyx + xx == 1
+                       //indetermined case
+                       rx = ry = 0;
+               }
+       } else { //xx == 1
+               if (tm.xy != 0) {
+                       ry = -tm.x0 / tm.xy;
+                       if (tm.yx != 0) {
+                               rx = (tm.x0 * tm.yy / tm.xy - tm.y0 - tm.x0 / 
tm.xy) / tm.yx;
+                       } else { //yx ==0
+                               //indetermined case
+                               rx = 0;                                 
+                       }
+               } else { //xy == 0
+                       //indetermined case
+                       rx = ry = 0;    
+               }
+       }
+
+
+       tx = rx * width;
+       ty = ry * height;
+       tm.x0 = (1 - tm.xx) * tx - tm.xy * ty;
+       tm.y0 = (1 - tm.yy) * ty - tm.yx * tx;
+       //printf ("de-relativized_transform xx: %f, yx: %f, xy: %f, yy: %f, x0: 
%f, y0: %f\n", tm.xx, tm.yx, tm.xy, tm.yy, tm.x0, tm.y0);
+       if (invert)
+               cairo_matrix_invert (&tm);
+       cairo_matrix_multiply (matrix, &tm, matrix);    
+}
+
 /*
  * Combine UIElement Opacity (including all parents) with Brush Opacity
  * NOTE: sadly we cannot handle Opacity at this level, each brush sub-type 
needs to handle it
@@ -452,6 +510,11 @@
                cairo_matrix_multiply (&matrix, &matrix, &tm);
        }
        
+       Transform *relative_transform = brush_get_relative_transform (this);
+       if (relative_transform) {
+               compute_relative_transform (&matrix, width, height, 
relative_transform, FALSE);
+       }
+       
        cairo_matrix_invert (&matrix);
        cairo_pattern_set_matrix (pattern, &matrix);
        
@@ -576,6 +639,11 @@
                // TODO - optimization, check for empty/identity matrix too ?
                cairo_matrix_multiply (&matrix, &matrix, &tm);
        }
+
+       //Transform *relative_transform = brush_get_relative_transform (this);
+       //if (relative_transform)
+       //      compute_relative_transform (&matrix, width, height, 
relative_transform, TRUE);
+       
        cairo_status_t status = cairo_matrix_invert (&matrix);
        if (status != CAIRO_STATUS_SUCCESS) {
                printf ("Moonlight: Error inverting matrix falling back\n");
@@ -834,7 +902,7 @@
 
 void
 image_brush_compute_pattern_matrix (cairo_matrix_t *matrix, double width, 
double height, int sw, int sh, 
-       Stretch stretch, AlignmentX align_x, AlignmentY align_y, Transform 
*transform)
+       Stretch stretch, AlignmentX align_x, AlignmentY align_y, Transform 
*transform, Transform *relative_transform)
 {
        // scale required to "fit" for both axes
        double sx = sw / width;
@@ -898,11 +966,16 @@
                }
        }
 
-       if (transform) {
+       if (transform || relative_transform) {
                cairo_matrix_t tm;
-               transform_get_transform (transform, &tm);
-               cairo_matrix_invert (&tm);
-               cairo_matrix_multiply (matrix, &tm, matrix);
+               if (transform) {
+                       transform_get_transform (transform, &tm);
+                       cairo_matrix_invert (&tm);
+                       cairo_matrix_multiply (matrix, &tm, matrix);
+               }
+               if (relative_transform) {
+                       compute_relative_transform (matrix, width, height, 
relative_transform, TRUE);
+               }
        }
 }
 
@@ -925,11 +998,13 @@
        AlignmentY ay = tile_brush_get_alignment_y (this);
        
        Transform *transform = brush_get_transform (this);
-       
+
+       Transform *relative_transform = brush_get_relative_transform (this);
+
        cairo_pattern_t *pattern = image_brush_create_pattern (cr, surface, 
image->GetWidth (), image->GetHeight (), opacity);
        
        cairo_matrix_t matrix;
-       image_brush_compute_pattern_matrix (&matrix, width, height, 
image->GetWidth (), image->GetHeight (), stretch, ax, ay, transform);
+       image_brush_compute_pattern_matrix (&matrix, width, height, 
image->GetWidth (), image->GetHeight (), stretch, ax, ay, transform, 
relative_transform);
        cairo_pattern_set_matrix (pattern, &matrix);
        
        cairo_set_source (cr, pattern);
@@ -961,6 +1036,7 @@
 {
        MediaPlayer *mplayer = media ? media->mplayer : NULL;
        Transform *transform = brush_get_transform (this);
+       Transform *relative_transform = brush_get_relative_transform (this);
        AlignmentX ax = tile_brush_get_alignment_x (this);
        AlignmentY ay = tile_brush_get_alignment_y (this);
        Stretch stretch = tile_brush_get_stretch (this);
@@ -1003,7 +1079,7 @@
                opacity = 1.0;
        
        pattern = image_brush_create_pattern (cr, surface, mplayer->width, 
mplayer->height, opacity);
-       image_brush_compute_pattern_matrix (&matrix, width, height, 
mplayer->width, mplayer->height, stretch, ax, ay, transform);
+       image_brush_compute_pattern_matrix (&matrix, width, height, 
mplayer->width, mplayer->height, stretch, ax, ay, transform, 
relative_transform);
        cairo_pattern_set_matrix (pattern, &matrix);
        
        cairo_set_source (cr, pattern);
@@ -1114,13 +1190,14 @@
        AlignmentY ay = tile_brush_get_alignment_y (this);
        
        Transform *transform = brush_get_transform (this);
+       Transform *relative_transform = brush_get_relative_transform (this);
        
        cairo_pattern_t *pattern = image_brush_create_pattern (cr, surface, 
(int)bounds.w, (int)bounds.h, opacity);
 
        cairo_matrix_t matrix;
        image_brush_compute_pattern_matrix (&matrix, width, height,
                                            (int)bounds.w, (int)bounds.h,
-                                           stretch, ax, ay, transform);
+                                           stretch, ax, ay, transform, 
relative_transform);
 
        cairo_pattern_set_matrix (pattern, &matrix);
 

Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp    2007-12-06 19:22:52 UTC (rev 90845)
+++ trunk/moon/src/media.cpp    2007-12-06 20:01:08 UTC (rev 90846)
@@ -30,7 +30,7 @@
 // still too ugly to be exposed in the header files ;-)
 cairo_pattern_t *image_brush_create_pattern (cairo_t *cairo, cairo_surface_t 
*surface, int sw, int sh, double opacity);
 void image_brush_compute_pattern_matrix (cairo_matrix_t *matrix, double width, 
double height, int sw, int sh, 
-                                        Stretch stretch, AlignmentX align_x, 
AlignmentY align_y, Transform *transform);
+                                        Stretch stretch, AlignmentX align_x, 
AlignmentY align_y, Transform *transform, Transform *relative_transform);
 
 
 // MediaBase
@@ -501,7 +501,7 @@
        
        if (recalculate_matrix) {
                image_brush_compute_pattern_matrix (&matrix, w, h, 
mplayer->width, mplayer->height, stretch,
-                                                   AlignmentXCenter, 
AlignmentYCenter, NULL);
+                                                   AlignmentXCenter, 
AlignmentYCenter, NULL, NULL);
                recalculate_matrix = false;
        }
        
@@ -1513,7 +1513,7 @@
 
        cairo_matrix_t matrix;
        image_brush_compute_pattern_matrix (&matrix, w, h, surface->width, 
surface->height, stretch, 
-               AlignmentXCenter, AlignmentYCenter, NULL);
+               AlignmentXCenter, AlignmentYCenter, NULL, NULL);
        
        cairo_pattern_set_matrix (pattern, &matrix);
        cairo_set_source (cr, pattern);

Modified: trunk/moon/test/xaml/test-relativetransform.xaml
===================================================================
--- trunk/moon/test/xaml/test-relativetransform.xaml    2007-12-06 19:22:52 UTC 
(rev 90845)
+++ trunk/moon/test/xaml/test-relativetransform.xaml    2007-12-06 20:01:08 UTC 
(rev 90846)
@@ -2,7 +2,7 @@
   xmlns="http://schemas.microsoft.com/client/2007";
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml";
   Width="400" Height="400">
-  <Rectangle Width="63" Height="76" Canvas.Top="10" Canvas.Left="10">
+<!--  <Rectangle Width="63" Height="76" Canvas.Top="10" Canvas.Left="10">
     <Rectangle.Fill>
      <ImageBrush ImageSource="mono.png" >
        <ImageBrush.RelativeTransform>
@@ -99,5 +99,31 @@
      </LinearGradientBrush.Transform>
     </LinearGradientBrush>
    </Rectangle.Fill>
+  </Rectangle>-->
+  <Rectangle Canvas.Top="192" Canvas.Left="156" Width="63" Height="76">
+   <Rectangle.Fill>
+    <RadialGradientBrush StartPoint=".5,0.5" EndPoint="1,1">
+     <RadialGradientBrush.GradientStops>
+      <GradientStop Color="Blue" Offset="0" />
+      <GradientStop Color="Red" Offset="1" />
+     </RadialGradientBrush.GradientStops> 
+     <RadialGradientBrush.RelativeTransform>
+      <RotateTransform CenterX="0.5" CenterY="0.5" Angle="45" />
+     </RadialGradientBrush.RelativeTransform>
+    </RadialGradientBrush>
+   </Rectangle.Fill>
   </Rectangle>
+  <Rectangle Canvas.Top="192" Canvas.Left="229" Width="63" Height="76">
+   <Rectangle.Fill>
+    <RadialGradientBrush StartPoint=".5,0.5" EndPoint="1,1">
+     <RadialGradientBrush.GradientStops>
+      <GradientStop Color="Blue" Offset="0" />
+      <GradientStop Color="Red" Offset="1" />
+     </RadialGradientBrush.GradientStops> 
+     <RadialGradientBrush.Transform>
+      <RotateTransform CenterX="31.5" CenterY="38" Angle="45" />
+     </RadialGradientBrush.Transform>
+    </RadialGradientBrush>
+   </Rectangle.Fill>
+  </Rectangle>
 </Canvas>

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to