2009-10-20 Chris Toshok <toshok@ximian.com>
[moon.git] / src / multiscaleimage.h
blobc30eeb7b172e40664db38ae7a0b121d544384013
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * multiscaleimage.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007-2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __MULTISCALEIMAGE_H__
14 #define __MULTISCALEIMAGE_H__
16 #include <glib.h>
17 #include <cairo.h>
19 #include "multiscalesubimage.h"
20 #include "tilesource.h"
21 #include "eventargs.h"
22 #include "control.h"
23 #include "media.h"
24 #include "animation.h"
25 #include "ptr.h"
27 struct BitmapImageContext;
29 /* @Namespace=System.Windows.Controls */
30 class MultiScaleImage : public MediaBase {
31 friend class MultiScaleImagePropertyValueProvider;
33 GHashTable *cache;
34 bool cache_contains (Uri* filename, bool check_empty_tile);
35 bool subimages_sorted;
36 bool pending_motion_completed;
38 cairo_user_data_key_t width_key;
39 cairo_user_data_key_t height_key;
40 cairo_user_data_key_t full_opacity_at_key;
42 static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
43 static void downloader_failed (EventObject *sender, EventArgs *calldata, gpointer closure);
45 GList *bitmapimages;
46 BitmapImageContext *GetBitmapImageContext (BitmapImage *bitmapimage);
48 void RenderSingle (cairo_t *cr, Region *region);
49 void RenderCollection (cairo_t *cr, Region *region);
51 DOPtr<Storyboard> zoom_sb;
52 DOPtr<Storyboard> pan_sb;
53 DOPtr<Storyboard> fadein_sb;
54 DOPtr<DoubleAnimationUsingKeyFrames> zoom_animation;
55 DOPtr<PointAnimationUsingKeyFrames> pan_animation;
56 DOPtr<DoubleAnimation> fadein_animation;
58 void SetIsDownloading (bool value);
59 void SetIsIdle (bool value);
61 /* @PropertyType=double,DefaultValue=0.0,Version=2.0,GenerateManagedAccessors=false,ManagedFieldAccess=Private */
62 const static int TileFadeProperty;
63 /* @PropertyType=Point,DefaultValue=Point(0\,0),Version=2.0,GenerateGetter,GenerateManagedAccessors=false,ManagedFieldAccess=Private */
64 const static int InternalViewportOriginProperty;
65 /* @PropertyType=double,DefaultValue=1.0,Version=2.0,GenerateGetter,GenerateManagedAccessors=false,ManagedFieldAccess=Private */
66 const static int InternalViewportWidthProperty;
68 Point* GetInternalViewportOrigin ();
69 void SetInternalViewportOrigin (Point* p);
71 double GetInternalViewportWidth ();
72 void SetInternalViewportWidth (double width);
74 double *GetZoomAnimationEndPoint ();
75 void SetZoomAnimationEndPoint (double endpoint);
76 Point *GetPanAnimationEndPoint ();
77 void SetPanAnimationEndPoint (Point endpoint);
79 double zoom_target;
80 Point pan_target;
82 bool is_fading;
83 bool is_zooming;
84 bool is_panning;
86 protected:
87 virtual ~MultiScaleImage ();
89 public:
90 void EmitImageOpenSucceeded ();
91 /* @GenerateCBinding */
92 void EmitMotionFinished ();
93 /* @GenerateCBinding */
94 void EmitImageFailed ();
95 /* @GenerateCBinding */
96 void EmitImageOpenFailed ();
97 void FadeFinished ();
98 void ZoomFinished ();
99 void PanFinished ();
100 void TileOpened (BitmapImage *bitmapImage);
101 void TileFailed (BitmapImage *bitmapImage);
103 /* @PropertyType=bool,DefaultValue=true,Version=3.0,GenerateAccessors */
104 const static int AllowDownloadingProperty;
105 /* @PropertyType=double,ReadOnly,DefaultValue=1.0,Version=2.0,GenerateGetter */
106 const static int AspectRatioProperty;
107 /* @PropertyType=double,DefaultValue=1.0,Version=3.0,GenerateAccessors */
108 const static int BlurFactorProperty;
109 /* @PropertyType=bool,ReadOnly,DefaultValue=false,Version=3.0,GenerateGetter */
110 const static int IsDownloadingProperty;
111 /* @PropertyType=bool,ReadOnly,DefaultValue=true,Version=3.0,GenerateGetter */
112 const static int IsIdleProperty;
113 /* @PropertyType=MultiScaleTileSource,Version=2.0,GenerateAccessors */
114 const static int SourceProperty;
115 /* @PropertyType=MultiScaleSubImageCollection,AutoCreateValue,ReadOnly,Version=2.0,GenerateGetter,GenerateManagedAccessors=false */
116 const static int SubImagesProperty;
117 /* @PropertyType=bool,DefaultValue=true,Version=2.0,GenerateAccessors */
118 const static int UseSpringsProperty;
119 /* @PropertyType=Point,AlwaysChange,DefaultValue=Point(0\,0),Version=2.0,GenerateAccessors */
120 const static int ViewportOriginProperty;
121 /* @PropertyType=double,AlwaysChange,DefaultValue=1.0,Version=2.0,GenerateAccessors */
122 const static int ViewportWidthProperty;
125 /* @GenerateCBinding,GeneratePInvoke */
126 MultiScaleImage ();
129 // Overrides
131 virtual void Render (cairo_t *cr, Region *region, bool path_only = false);
132 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
133 virtual void OnCollectionChanged (Collection *col, CollectionChangedEventArgs *args);
134 virtual void OnCollectionItemChanged (Collection *col, DependencyObject *obj, PropertyChangedEventArgs *args);
137 // Methods
139 /* @GenerateCBinding,GeneratePInvoke */
140 void ZoomAboutLogicalPoint (double zoomIncrementFactor, double zoomCenterLogicalX, double zoomCenterLogicalY);
141 /* @GenerateCBinding,GeneratePInvoke */
142 Point ElementToLogicalPoint (Point elementPoint);
143 /* @GenerateCBinding,GeneratePInvoke */
144 Point LogicalToElementPoint (Point logicalPoint);
146 MultiScaleSubImage *GetIthSubImage (int index);
147 // There is no documentation in MSDN for this method, it only shows up in a few tests.
148 int LogicalToElementX (int x, int y);
149 // There is no documentation in MSDN for this method, it only shows up in a few tests.
150 int LogicalToElementY (int x, int y);
151 // There is no documentation in MSDN for this method, it only shows up in a few tests.
152 int GetSubImageCount ();
155 // Property Accessors
157 double GetAspectRatio ();
159 bool GetAllowDownloading ();
160 void SetAllowDownloading (bool value);
162 double GetBlurFactor ();
163 void SetBlurFactor (double value);
165 bool GetIsIdle ();
167 bool GetIsDownloading ();
169 MultiScaleTileSource* GetSource ();
170 void SetSource (MultiScaleTileSource* source);
172 bool GetUseSprings ();
173 void SetUseSprings (bool spring);
175 Point* GetViewportOrigin ();
176 void SetViewportOrigin (Point* p);
178 double GetViewportWidth ();
179 void SetViewportWidth (double width);
181 MultiScaleSubImageCollection *GetSubImages ();
184 // Events
186 /* @DelegateType=RoutedEventHandler */
187 const static int ImageFailedEvent;
188 /* @DelegateType=EventHandler<ExceptionRoutedEventArgs> */
189 const static int ImageOpenFailedEvent;
190 /* @DelegateType=RoutedEventHandler */
191 const static int ImageOpenSucceededEvent;
192 /* @DelegateType=RoutedEventHandler */
193 const static int MotionFinishedEvent;
194 /* @DelegateType=RoutedEventHandler */
195 const static int ViewportChangedEvent;
197 BitmapImageContext *GetFreeBitmapImageContext ();
198 void StopDownloading ();
199 void DownloadTile (BitmapImageContext *ctx, Uri *tile, void *user_data);
200 /* @GenerateCBinding */
201 void HandleDzParsed ();
203 /* @GenerateCBinding */
204 void OnSourcePropertyChanged ();
206 /* @GenerateCBinding */
207 void InvalidateTileLayer (int level, int tilePositionX, int tilePositionY, int tileLayer);
211 * MultiScaleImagePropertyValueProvider
214 class MultiScaleImagePropertyValueProvider : public FrameworkElementProvider {
215 private:
216 Value *viewport_origin;
217 Value *viewport_width;
219 Value *GetViewportOrigin ();
220 Value *GetViewportWidth ();
222 public:
223 MultiScaleImagePropertyValueProvider (MultiScaleImage *obj, PropertyPrecedence precedence);
224 virtual ~MultiScaleImagePropertyValueProvider ();
225 virtual Value *GetPropertyValue (DependencyProperty *property);
229 #endif /* __MULTISCALIMAGE_H__ */