1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
20 #include "collection.h"
21 #include "imagesource.h"
37 enum BrushMappingMode
{
38 BrushMappingModeAbsolute
,
39 BrushMappingModeRelativeToBoundingBox
42 enum ColorInterpolationMode
{
43 ColorInterpolationModeScRgbLinearInterpolation
,
44 ColorInterpolationModeSRgbLinearInterpolation
47 enum GradientSpreadMethod
{
48 GradientSpreadMethodPad
,
49 GradientSpreadMethodReflect
,
50 GradientSpreadMethodRepeat
54 /* @Namespace=System.Windows.Media */
55 class Brush
: public DependencyObject
{
60 /* @PropertyType=double,DefaultValue=1.0,GenerateAccessors */
61 const static int OpacityProperty
;
62 /* @PropertyType=Transform,DefaultValue=new MatrixTransform (),GenerateAccessors */
63 const static int RelativeTransformProperty
;
64 /* @PropertyType=Transform,DefaultValue=new MatrixTransform (),GenerateAccessors */
65 const static int TransformProperty
;
67 // internal property - generic brush property change
68 // used only for notifying attachees
69 /* @PropertyType=bool,Access=Internal */
70 const static int ChangedProperty
;
72 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
75 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
77 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subobj_args
);
79 virtual void Fill (cairo_t
*cr
, bool preserve
= FALSE
);
80 virtual void Stroke (cairo_t
*cr
, bool preserve
= FALSE
);
82 // returns true if OpacityProperty == 1.0.
83 // subclasses override this to deal with their local coloring
84 virtual bool IsOpaque ();
86 // returns true if the brush is expected to change each render
87 // pass. subclasses should override this to handle
88 virtual bool IsAnimating ();
93 void SetOpacity (double opacity
);
96 void SetRelativeTransform (Transform
*transform
);
97 Transform
*GetRelativeTransform ();
99 void SetTransform (Transform
*transform
);
100 Transform
*GetTransform ();
104 /* @Namespace=System.Windows.Media */
105 class SolidColorBrush
: public Brush
{
107 virtual ~SolidColorBrush () {}
110 /* @PropertyType=Color,DefaultValue=Color (0x00000000),GenerateAccessors */
111 const static int ColorProperty
;
113 /* @GenerateCBinding,GeneratePInvoke */
115 SolidColorBrush (const char *color
);
117 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
119 virtual bool IsOpaque ();
122 // Property Accessors
124 void SetColor (Color
*color
);
129 /* @Namespace=System.Windows.Media */
130 class GradientStopCollection
: public DependencyObjectCollection
{
132 virtual ~GradientStopCollection ();
135 /* @GenerateCBinding,GeneratePInvoke */
136 GradientStopCollection ();
138 virtual Type::Kind
GetElementType() { return Type::GRADIENTSTOP
; }
142 /* @Namespace=System.Windows.Media */
143 class GradientStop
: public DependencyObject
{
145 virtual ~GradientStop ();
148 /* @PropertyType=Color,DefaultValue=Color (0x00000000),GenerateAccessors */
149 const static int ColorProperty
;
150 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
151 const static int OffsetProperty
;
153 /* @GenerateCBinding,GeneratePInvoke */
157 // Property Accessors
159 void SetColor (Color
*color
);
162 void SetOffset (double offset
);
167 // note: abstract in C#
168 /* @Namespace=System.Windows.Media */
169 /* @ContentProperty="GradientStops" */
170 class GradientBrush
: public Brush
{
172 virtual ~GradientBrush ();
175 /* @PropertyType=ColorInterpolationMode,DefaultValue=ColorInterpolationModeSRgbLinearInterpolation,GenerateAccessors */
176 const static int ColorInterpolationModeProperty
;
177 /* @PropertyType=GradientStopCollection,AutoCreateValue,GenerateAccessors */
178 const static int GradientStopsProperty
;
179 /* @PropertyType=BrushMappingMode,DefaultValue=BrushMappingModeRelativeToBoundingBox,GenerateAccessors */
180 const static int MappingModeProperty
;
181 /* @PropertyType=GradientSpreadMethod,DefaultValue=GradientSpreadMethodPad,GenerateAccessors */
182 const static int SpreadMethodProperty
;
184 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
187 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
188 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
189 virtual void SetupGradient (cairo_pattern_t
*pattern
, const Rect
&area
, bool single
= false);
191 virtual bool IsOpaque ();
194 // Property Accessors
196 void SetColorInterpolationMode (ColorInterpolationMode mode
);
197 ColorInterpolationMode
GetColorInterpolationMode ();
199 void SetGradientStops (GradientStopCollection
*collection
);
200 GradientStopCollection
*GetGradientStops ();
202 void SetMappingMode (BrushMappingMode mode
);
203 BrushMappingMode
GetMappingMode ();
205 void SetSpreadMethod (GradientSpreadMethod method
);
206 GradientSpreadMethod
GetSpreadMethod ();
210 /* @Namespace=System.Windows.Media */
211 class LinearGradientBrush
: public GradientBrush
{
213 virtual ~LinearGradientBrush ();
216 /* @PropertyType=Point,DefaultValue=Point(1\,1),GenerateAccessors */
217 const static int EndPointProperty
;
218 /* @PropertyType=Point,GenerateAccessors */
219 const static int StartPointProperty
;
221 /* @GenerateCBinding,GeneratePInvoke */
222 LinearGradientBrush ();
224 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
227 // Property Accessors
229 void SetEndPoint (Point
*point
);
230 Point
*GetEndPoint ();
232 void SetStartPoint (Point
*point
);
233 Point
*GetStartPoint ();
237 /* @Namespace=System.Windows.Media */
238 class RadialGradientBrush
: public GradientBrush
{
240 virtual ~RadialGradientBrush ();
243 /* @PropertyType=Point,DefaultValue=Point (0.5\, 0.5),GenerateAccessors */
244 const static int CenterProperty
;
245 /* @PropertyType=Point,DefaultValue=Point (0.5\, 0.5),GenerateAccessors */
246 const static int GradientOriginProperty
;
247 /* @PropertyType=double,DefaultValue=0.5,GenerateAccessors */
248 const static int RadiusXProperty
;
249 /* @PropertyType=double,DefaultValue=0.5,GenerateAccessors */
250 const static int RadiusYProperty
;
252 /* @GenerateCBinding,GeneratePInvoke */
253 RadialGradientBrush ();
255 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
258 // Property Accessors
260 void SetCenter (Point
*center
);
263 void SetGradientOrigin (Point
*origin
);
264 Point
*GetGradientOrigin ();
266 void SetRadiusX (double radius
);
267 double GetRadiusX ();
269 void SetRadiusY (double radius
);
270 double GetRadiusY ();
274 /* @Namespace=System.Windows.Media */
275 class TileBrush
: public Brush
{
277 virtual ~TileBrush ();
280 /* @PropertyType=AlignmentX,DefaultValue=AlignmentXCenter,GenerateAccessors */
281 const static int AlignmentXProperty
;
282 /* @PropertyType=AlignmentY,DefaultValue=AlignmentYCenter,GenerateAccessors */
283 const static int AlignmentYProperty
;
284 /* @PropertyType=Stretch,DefaultValue=StretchFill,GenerateAccessors */
285 const static int StretchProperty
;
287 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
289 virtual void Fill (cairo_t
*cr
, bool preserve
);
290 virtual void Stroke (cairo_t
*cr
, bool preserve
);
293 // Property Accessors
295 void SetAlignmentX (AlignmentX alignment
);
296 AlignmentX
GetAlignmentX ();
298 void SetAlignmentY (AlignmentY alignment
);
299 AlignmentY
GetAlignmentY ();
301 void SetStretch (Stretch stretch
);
302 Stretch
GetStretch ();
306 /* @Namespace=System.Windows.Media */
307 class ImageBrush
: public TileBrush
{
309 void DownloadProgress ();
311 void ImageFailed (ImageErrorEventArgs
*args
);
312 void SourcePixelDataChanged ();
314 static void download_progress (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
315 static void image_opened (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
316 static void image_failed (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
317 static void source_pixel_data_changed (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
320 virtual ~ImageBrush ();
323 /* @PropertyType=double,DefaultValue=0.0,ManagedAccess=Private,GenerateAccessors */
324 const static int DownloadProgressProperty
;
325 /* @PropertyType=ImageSource,GenerateAccessors */
326 const static int ImageSourceProperty
;
328 /* @GenerateManagedEvent=false */
329 const static int DownloadProgressChangedEvent
;
330 /* @DelegateType=EventHandler<ExceptionRoutedEventArgs> */
331 const static int ImageFailedEvent
;
333 /* @GenerateCBinding,GeneratePInvoke */
335 virtual void Dispose ();
337 void SetSource (Downloader
*downloader
, const char *PartName
);
338 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
339 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
341 virtual bool IsOpaque ();
344 // Property Accessors
346 void SetDownloadProgress (double progress
);
347 double GetDownloadProgress ();
349 void SetImageSource (ImageSource
*source
);
350 ImageSource
*GetImageSource ();
353 cairo_surface_t
*image_brush_create_similar (cairo_t
*cr
, int width
, int height
);
356 /* @Namespace=System.Windows.Media */
357 class VideoBrush
: public TileBrush
{
360 static void update_brush (EventObject
*, EventArgs
*, gpointer closure
);
363 virtual ~VideoBrush ();
366 /* @PropertyType=string,DefaultValue=\"\",GenerateAccessors */
367 const static int SourceNameProperty
;
369 /* @GenerateCBinding,GeneratePInvoke */
372 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
373 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subobj_args
);
374 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
376 virtual bool IsOpaque ();
377 virtual bool IsAnimating ();
382 /* @GenerateCBinding,GeneratePInvoke */
383 void SetSource (MediaElement
*source
);
386 // Property Accessors
388 void SetSourceName (const char *name
);
389 const char *GetSourceName ();
393 /* @Namespace=None */
394 /* @ManagedDependencyProperties=None */
395 /* @ManagedEvents=None */
396 class VisualBrush
: public TileBrush
{
397 cairo_surface_t
*surface
;
399 static void update_brush (EventObject
*, EventArgs
*, gpointer closure
);
402 virtual ~VisualBrush ();
405 /* @PropertyType=UIElement,GenerateAccessors */
406 const static int VisualProperty
;
408 /* @GenerateCBinding,GeneratePInvoke */
411 virtual void SetupBrush (cairo_t
*cr
, const Rect
&area
);
412 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
414 virtual bool IsOpaque ();
417 // Property Accessors
419 void SetVisual (UIElement
*visual
);
420 UIElement
*GetVisual ();
426 void image_brush_compute_pattern_matrix (cairo_matrix_t
*matrix
, double width
, double height
, int sw
, int sh
,
427 Stretch stretch
, AlignmentX align_x
, AlignmentY align_y
, Transform
*transform
,
428 Transform
*relative_transform
);
433 #endif /* __BRUSH_H__ */