public void SettingStateOnParentDoesNotPropagateToChildNonAnimatedIcon() { AnimatedIcon animatedIcon = null; Grid parentGrid = null; Grid childGrid = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentGrid = new Grid(); childGrid = new Grid(); parentGrid.Children.Add(childGrid); childGrid.Children.Add(animatedIcon); Content = parentGrid; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { string stateString = "Test State"; AnimatedIcon.SetState(parentGrid, stateString); Verify.AreNotEqual(stateString, AnimatedIcon.GetState(animatedIcon)); Verify.AreNotEqual(stateString, AnimatedIcon.GetState(childGrid)); }); }
public void ForegroundInheritsFromParent() { AnimatedIcon animatedIcon = null; ContentControl parentContentControl = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentContentControl = new ContentControl(); parentContentControl.Content = animatedIcon; Content = parentContentControl; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { var foregroundBrush = new SolidColorBrush(Colors.Red); parentContentControl.Foreground = foregroundBrush; Verify.AreEqual(foregroundBrush, animatedIcon.Foreground); var newForegroundBrush = new SolidColorBrush(Colors.Blue); animatedIcon.Foreground = newForegroundBrush; Verify.AreEqual(newForegroundBrush, animatedIcon.Foreground); }); }
private void AnimatedIconTestHooks_LastAnimationSegmentChanged(AnimatedIcon sender, object args) { if (sender == GetAnimatedIcon()) { m_transitionTextBlock.Text = AnimatedIconTestHooks.GetLastAnimationSegment(sender); } }
static string InternalGetStockIdFromAnimation(RuntimeAddin addin, string id, Gtk.IconSize size) { if (!id.StartsWith("animation:", StringComparison.Ordinal)) { return(id); } id = id.Substring(10); Dictionary <string, string> hash; int addinId; if (addin != null) { addinId = GetAddinId(addin); hash = addinIcons[addinId]; } else { addinId = -1; hash = iconSpecToStockId; } string stockId = "__asm" + addinId + "__" + id + "__" + size; if (!hash.ContainsKey(stockId)) { var aicon = new AnimatedIcon(addin, id, size); AddToAnimatedIconFactory(stockId, aicon); hash[stockId] = stockId; icons [stockId] = aicon.FirstFrame; } return(stockId); }
public void AnimatedIconSourceTest() { AnimatedIconSource iconSource = null; IRichAnimatedVisualSource source = null; RunOnUIThread.Execute(() => { iconSource = new AnimatedIconSource(); source = new Controls_02_UpDown_Dropdown(); // IconSource.Foreground should be null to allow foreground inheritance from // the parent to work. Verify.AreEqual(iconSource.Foreground, null); Log.Comment("Validate the defaults match BitmapIcon."); var icon = new AnimatedIcon(); Verify.AreEqual(icon.Source, iconSource.Source); Log.Comment("Validate that you can change the properties."); iconSource.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); iconSource.Source = source; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.IsTrue(iconSource.Foreground is SolidColorBrush); Verify.AreEqual(Windows.UI.Colors.Red, (iconSource.Foreground as SolidColorBrush).Color); Verify.AreEqual(source, iconSource.Source); }); }
public void AddingAnimatedIconToGridWithoutAStateDoesNotPropogateState() { // This is not actually a desired behavior. Ideally we would be able to set // the AnimatedIcon.State property on any ancestor of an animated icon at any // time and that would reach the icon. However this is challenging to do // efficiently so instead we require that the parent have an AnimatedIcon.State // value when the icon is loaded. AnimatedIcon animatedIcon = null; Grid parentGrid = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentGrid = new Grid(); parentGrid.Children.Add(animatedIcon); Content = parentGrid; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { string stateString = "Test State"; AnimatedIcon.SetState(parentGrid, stateString); Verify.AreNotEqual(stateString, AnimatedIcon.GetState(animatedIcon)); }); }
public void SettingStateOnGrandParentPropagatesToGrandChildAnimatedIcon() { AnimatedIcon animatedIcon = null; Grid parentGrid = null; Grid grandParentGrid = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentGrid = new Grid(); grandParentGrid = new Grid(); parentGrid.Children.Add(animatedIcon); grandParentGrid.Children.Add(parentGrid); AnimatedIcon.SetState(grandParentGrid, "Initial State"); Content = grandParentGrid; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { string stateString = "Test State"; AnimatedIcon.SetState(grandParentGrid, stateString); Verify.AreEqual(stateString, AnimatedIcon.GetState(animatedIcon)); }); }
void SetStatusIcon(IconId stockId, double alpha = 1.0) { animatedStatusIcon = null; if (statusIconAnimation != null) { statusIconAnimation.Dispose(); statusIconAnimation = null; } if (stockId.IsNull) { statusIconView.Visible = false; return; } if (ImageService.IsAnimation(stockId, Gtk.IconSize.Menu)) { animatedStatusIcon = ImageService.GetAnimatedIcon(stockId, Gtk.IconSize.Menu); statusIconView.Image = animatedStatusIcon.FirstFrame.WithAlpha(alpha); statusIconAnimation = animatedStatusIcon.StartAnimation(p => { statusIconView.Image = p.WithAlpha(alpha); }); } else { statusIconView.Image = ImageService.GetIcon(stockId).WithSize(Xwt.IconSize.Small).WithAlpha(alpha); } statusIconView.Visible = true; }
public void CanChangeSourceAfterState() { AnimatedIcon animatedIcon = null; Grid parentGrid = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentGrid = new Grid(); parentGrid.Children.Add(animatedIcon); Content = parentGrid; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { animatedIcon.Source = new Controls_02_UpDown_Dropdown(); AnimatedIcon.SetState(parentGrid, "Normal"); animatedIcon.Source = new Controls_07_Settings(); AnimatedIcon.SetState(parentGrid, "Hover"); animatedIcon.Source = null; AnimatedIcon.SetState(parentGrid, ""); }); }
public void ChangingSourcePropertyChangesRenderSize() { AnimatedIcon icon = null; RunOnUIThread.Execute(() => { icon = new AnimatedIcon(); Content = new StackPanel() { Children = { icon } }; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { // Icon height will be zero if the source property is not set. Verify.IsTrue(Math.Abs(icon.ActualHeight) < 0.1); icon.Source = new AnimatedChevronDownSmallVisualSource(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { // Icon will have a height if the AnimatedIcon also updated the visual tree to rerender. Verify.IsTrue(Math.Abs(icon.ActualHeight) > 10); }); }
public void CanChangeSourceAfterState() { AnimatedIcon animatedIcon = null; Grid parentGrid = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentGrid = new Grid(); parentGrid.Children.Add(animatedIcon); Content = parentGrid; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { animatedIcon.Source = new AnimatedChevronDownSmallVisualSource(); AnimatedIcon.SetState(parentGrid, "Normal"); animatedIcon.Source = new AnimatedSettingsVisualSource(); AnimatedIcon.SetState(parentGrid, "PointerOver"); animatedIcon.Source = null; AnimatedIcon.SetState(parentGrid, ""); }); }
private void CreateIcon() { if (Icon != null || !_isSelectionEnabled) { return; } Icon = GetTemplateChild(nameof(Icon)) as AnimatedIcon; ElementCompositionPreview.SetIsTranslationEnabled(Icon, true); RegisterPropertyChangedCallback(BackgroundProperty, OnBackgroundChanged); OnBackgroundChanged(this, BackgroundProperty); if (IsAlbumChild) { if (_message.Content is MessagePhoto or MessageVideo) { Icon.VerticalAlignment = VerticalAlignment.Top; Icon.HorizontalAlignment = HorizontalAlignment.Right; Icon.Margin = new Thickness(0, 4, 6, 0); } else { Icon.VerticalAlignment = VerticalAlignment.Bottom; Icon.HorizontalAlignment = HorizontalAlignment.Left; Icon.Margin = new Thickness(28, 0, 0, 4); } Grid.SetColumn(Icon, 1); }
static void LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null; AnimatedIcon animatedIcon = null; if (!string.IsNullOrEmpty(iconCodon.Resource) || !string.IsNullOrEmpty(iconCodon.File)) { // using the stream directly produces a gdk warning. byte[] buffer; Stream stream; if (iconCodon.Resource != null) { stream = iconCodon.Addin.GetResource(iconCodon.Resource); } else { stream = File.OpenRead(iconCodon.Addin.GetFilePath(iconCodon.File)); } using (stream) { if (stream == null || stream.Length < 0) { LoggingService.LogError("Did not find resource '{0}' in addin '{1}' for icon '{2}'", iconCodon.Resource, iconCodon.Addin.Id, iconCodon.StockId); return; } buffer = new byte [stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } pixbuf = new Gdk.Pixbuf(buffer); } else if (!string.IsNullOrEmpty(iconCodon.IconId)) { var id = GetStockIdForImageSpec(iconCodon.Addin, iconCodon.IconId, iconCodon.IconSize); pixbuf = GetPixbuf(id, iconCodon.IconSize); // This may be an animation, get it animationFactory.TryGetValue(id, out animatedIcon); } else if (!string.IsNullOrEmpty(iconCodon.Animation)) { string id = GetStockIdForImageSpec(iconCodon.Addin, "animation:" + iconCodon.Animation, iconCodon.IconSize); pixbuf = GetPixbuf(id, iconCodon.IconSize); // This *should* be an animation animationFactory.TryGetValue(id, out animatedIcon); } Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconCodon.IconSize; if (pixbuf != null) { AddToIconFactory(iconCodon.StockId, pixbuf, size); } if (animatedIcon != null) { AddToAnimatedIconFactory(iconCodon.StockId, animatedIcon); } } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", iconCodon.StockId), ex); } }
public AnimatedTreeStoreIconInfo(Gtk.TreeStore treeStore, Gtk.TreeIter iter, int column, AnimatedIcon anim, string iconId) { TreeStore = treeStore; Iter = iter; Column = column; AnimatedIcon = anim; IconId = iconId; TreeStore.RowDeleted += HandleRowDeleted; StartAnimation(); }
static Xwt.Drawing.Image LoadStockIcon(RuntimeAddin addin, string stockId, string resource, string imageFile, string iconId, Gtk.IconSize iconSize, string animation, bool forceWildcard) { try { AnimatedIcon animatedIcon = null; Func <Stream[]> imageLoader = null; Xwt.Drawing.Image img = null; if (!string.IsNullOrEmpty(resource) || !string.IsNullOrEmpty(imageFile)) { if (resource != null) { CustomImageLoader loader; if (!imageLoaders.TryGetValue(addin, out loader)) { loader = imageLoaders [addin] = new CustomImageLoader(addin); } img = Xwt.Drawing.Image.FromCustomLoader(loader, resource); } else { img = Xwt.Drawing.Image.FromFile(addin.GetFilePath(imageFile)); } } else if (!string.IsNullOrEmpty(iconId)) { var id = GetStockIdForImageSpec(addin, iconId, iconSize); img = GetIcon(id, iconSize); // This may be an animation, get it animationFactory.TryGetValue(id, out animatedIcon); } else if (!string.IsNullOrEmpty(animation)) { string id = GetStockIdForImageSpec(addin, "animation:" + animation, iconSize); img = GetIcon(id, iconSize); // This *should* be an animation animationFactory.TryGetValue(id, out animatedIcon); } if (animatedIcon != null) { AddToAnimatedIconFactory(stockId, animatedIcon); } if (imageLoader != null) { img.SetStreamSource(imageLoader); } return(img); } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", stockId), ex); return(null); } }
public AnimatedImageInfo(Gtk.Image img, AnimatedIcon anim) { Image = img; AnimatedIcon = anim; img.Realized += HandleRealized; img.Unrealized += HandleUnrealized; img.Destroyed += HandleDestroyed; if (img.IsRealized) { StartAnimation(); } }
public MDSpinner(Gtk.IconSize size, Image idleImage = null) { Content = imageView = new Xwt.ImageView(); if (size == Gtk.IconSize.Menu) { spinner = ImageService.GetAnimatedIcon("md-spinner-16", size); } else { spinner = ImageService.GetAnimatedIcon("md-spinner-18", size); } IdleImage = idleImage; }
public void ChangingVisualTrees() { AnimatedIcon animatedIcon = null; Grid parentGrid = null; Grid grandParentGrid = null; Grid newParentGrid = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); parentGrid = new Grid(); grandParentGrid = new Grid(); newParentGrid = new Grid(); parentGrid.Children.Add(animatedIcon); grandParentGrid.Children.Add(parentGrid); AnimatedIcon.SetState(parentGrid, "Initial State"); Content = grandParentGrid; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { string stateString = "Test State"; AnimatedIcon.SetState(parentGrid, stateString); Verify.AreEqual(stateString, AnimatedIcon.GetState(animatedIcon)); parentGrid.Children.Clear(); newParentGrid.Children.Add(animatedIcon); grandParentGrid.Children.Clear(); grandParentGrid.Children.Add(newParentGrid); AnimatedIcon.SetState(newParentGrid, "Initial State"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { string state2String = "Test State2"; AnimatedIcon.SetState(newParentGrid, state2String); Verify.AreEqual(state2String, AnimatedIcon.GetState(animatedIcon)); string badStateString = "Bad State"; AnimatedIcon.SetState(parentGrid, badStateString); Verify.AreNotEqual(badStateString, AnimatedIcon.GetState(animatedIcon)); }); }
public void AnimatedIconSourceTest() { AnimatedIconSource iconSource = null; IAnimatedVisualSource2 source = null; AnimatedIcon animatedIcon = null; RunOnUIThread.Execute(() => { iconSource = new AnimatedIconSource(); source = new AnimatedChevronDownSmallVisualSource(); animatedIcon = iconSource.CreateIconElement() as AnimatedIcon; // IconSource.Foreground should be null to allow foreground inheritance from // the parent to work. Verify.AreEqual(iconSource.Foreground, null); //Verify.AreEqual(animatedIcon.Foreground, null); Verify.AreEqual(iconSource.MirroredWhenRightToLeft, false); Verify.AreEqual(animatedIcon.MirroredWhenRightToLeft, false); Log.Comment("Validate the defaults match BitmapIcon."); var icon = new AnimatedIcon(); Verify.AreEqual(icon.Source, iconSource.Source); Verify.AreEqual(animatedIcon.Source, iconSource.Source); Verify.AreEqual(icon.MirroredWhenRightToLeft, iconSource.MirroredWhenRightToLeft); Log.Comment("Validate that you can change the properties."); iconSource.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); iconSource.Source = source; iconSource.MirroredWhenRightToLeft = true; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.IsTrue(iconSource.Foreground is SolidColorBrush); Verify.IsTrue(animatedIcon.Foreground is SolidColorBrush); Verify.AreEqual(Windows.UI.Colors.Red, (iconSource.Foreground as SolidColorBrush).Color); Verify.AreEqual(Windows.UI.Colors.Red, (animatedIcon.Foreground as SolidColorBrush).Color); Verify.AreEqual(source, iconSource.Source); Verify.AreEqual(source, animatedIcon.Source); Verify.IsTrue(iconSource.MirroredWhenRightToLeft); Verify.IsTrue(animatedIcon.MirroredWhenRightToLeft); }); }
void LoadPixbuf(IconId image) { // We dont need to load the same image twice if (currentIcon == image && iconLoaded) { return; } currentIcon = image; iconAnimation = null; // clean up previous running animation if (currentIconAnimation != null) { currentIconAnimation.Dispose(); currentIconAnimation = null; } // if we have nothing, use the default icon if (image == IconId.Null) { image = "md-status-steady"; } // load image now if (ImageService.IsAnimation(image, Gtk.IconSize.Menu)) { iconAnimation = ImageService.GetAnimatedIcon(image, Gtk.IconSize.Menu); renderArg.CurrentPixbuf = iconAnimation.FirstFrame.WithSize(14, 14); currentIconAnimation = iconAnimation.StartAnimation(delegate(Xwt.Drawing.Image p) { renderArg.CurrentPixbuf = p.WithSize(14, 14); QueueDraw(); }); } else { renderArg.CurrentPixbuf = ImageService.GetIcon(image).WithSize(14, 14); } iconLoaded = true; }
void LoadPixbuf(IconId iconId) { // We dont need to load the same image twice if (icon == iconId && iconLoaded) { return; } icon = iconId; iconAnimation = null; // clean up previous running animation if (xwtAnimation != null) { xwtAnimation.Dispose(); xwtAnimation = null; } // if we have nothing, use the default icon if (iconId == IconId.Null) { iconId = Stock.StatusSteady; } // load image now if (ImageService.IsAnimation(iconId, Gtk.IconSize.Menu)) { iconAnimation = ImageService.GetAnimatedIcon(iconId, Gtk.IconSize.Menu); image = iconAnimation.FirstFrame.ToNSImage(); xwtAnimation = iconAnimation.StartAnimation(p => { image = p.ToNSImage(); ReconstructString(); }); } else { image = ImageService.GetIcon(iconId).ToNSImage(); } iconLoaded = true; }
private void IconSourceChanged() { if (m_iconPresenter != null) { AnimatedIcon animatedIcon = new AnimatedIcon(); AnimatedIconSource source = (AnimatedIconSource)IconSource; if (source.Source != null) { animatedIcon.Source = source.Source; } if (source.FallbackIconSource != null) { animatedIcon.FallbackIconSource = source.FallbackIconSource; } if (source.Foreground != null) { animatedIcon.Foreground = source.Foreground; } m_iconPresenter.Child = animatedIcon; } }
public void CanSetStateOnAnimatedIconDirectlyWithoutPropagationToChild() { AnimatedIcon animatedIcon = null; RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); Content = animatedIcon; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { string stateString = "Test State"; AnimatedIcon.SetState(animatedIcon, stateString); Verify.AreEqual(stateString, AnimatedIcon.GetState(animatedIcon)); Verify.AreNotEqual(stateString, AnimatedIcon.GetState(VisualTreeHelper.GetChild(animatedIcon, 0))); }); }
public void ShowMessage(IconId iconId, string message, bool isMarkup) { Message = message; StatusText.ToolTip = message; if (iconId.IsNull) { iconId = BrandingService.StatusSteadyIconId; } // don't reload same icon if (currentIcon == iconId) { return; } currentIcon = iconId; if (xwtAnimation != null) { xwtAnimation.Dispose(); xwtAnimation = null; } if (ImageService.IsAnimation(currentIcon, Gtk.IconSize.Menu)) { animatedIcon = ImageService.GetAnimatedIcon(currentIcon, Gtk.IconSize.Menu); StatusImage = animatedIcon.FirstFrame; xwtAnimation = animatedIcon.StartAnimation(p => { StatusImage = p; }); } else { StatusImage = currentIcon.GetStockIcon().WithSize(Xwt.IconSize.Small); } }
private void Button_PointerEntered(object sender, PointerRoutedEventArgs e) { AnimatedIcon.SetState(this.SearchAnimatedIcon, "PointerOver"); }
static string InternalGetStockIdFromAnimation(RuntimeAddin addin, string id, Gtk.IconSize size) { if (!id.StartsWith ("animation:")) return id; id = id.Substring (10); Dictionary<string, string> hash; int addinId; if (addin != null) { addinId = GetAddinId (addin); hash = addinIcons[addinId]; } else { addinId = -1; hash = iconSpecToStockId; } string stockId = "__asm" + addinId + "__" + id + "__" + size; if (!hash.ContainsKey (stockId)) { var aicon = new AnimatedIcon (addin, id, size); AddToIconFactory (stockId, aicon.FirstFrame, size); AddToAnimatedIconFactory (stockId, aicon); hash[stockId] = stockId; } return stockId; }
public AnimatedImageInfo(Gtk.Image img, AnimatedIcon anim) { Image = img; AnimatedIcon = anim; img.Realized += HandleRealized; img.Unrealized += HandleUnrealized; img.Destroyed += HandleDestroyed; if (img.IsRealized) StartAnimation (); }
public void TransitionFallbackLogic() { AnimatedIcon animatedIcon = null; var layoutUpdatedEvent = new AutoResetEvent(false); RunOnUIThread.Execute(() => { animatedIcon = new AnimatedIcon(); animatedIcon.Source = new MockIAnimatedIconSource2(); Content = animatedIcon; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { animatedIcon.LayoutUpdated += AnimatedIcon_LayoutUpdated; AnimatedIcon.SetState(animatedIcon, "a"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "b"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { Verify.AreEqual("aTob_Start", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("aTob_End", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "c"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { Verify.AreEqual("bToc_Start", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); // bToc_End is undefined in MockIAnimatedIconSource2 Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "d"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { // cTod_Start is undefined in MockIAnimatedIconSource2 Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("cTod_End", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "e"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { // dToe_Start and dToe_End are undefined in MockIAnimatedIconSource2, the first backup is dToe Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("dToe", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "f"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { // eTof_Start, eTof_End, and eTof are undefined in MockIAnimatedIconSource2, the second backup is f Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("f", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "b"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { // fTob_Start, fTob_End, fTob and b are all undefined in MockIAnimatedIconSource2, the third backup is any // marker which ends with the string "Tob_End" Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("aTob_End", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "0.12345"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { // bTo0.12345_Start, bTo0.12345_End, bTo0.12345, and 0.12345 are all undefined in MockIAnimatedIconSource2, and // there are no markers which end with the string "To0.12345_End" so finally we attempt to interpret the state as // a float to get the position to animate to. Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("0.12345", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); layoutUpdatedEvent.Reset(); AnimatedIcon.SetState(animatedIcon, "Failure"); Content.UpdateLayout(); }); IdleSynchronizer.Wait(); layoutUpdatedEvent.WaitOne(); RunOnUIThread.Execute(() => { // 0.12345ToFailure_Start, 0.12345ToFailure_End, 0.12345ToFailure, and Failure are all undefined in MockIAnimatedIconSource2, and // there are no markers which end with the string "ToFailure_End" and Failure is not a float, so we have failed to find a marker. Verify.AreEqual("", AnimatedIconTestHooks.GetLastAnimationSegmentStart(animatedIcon)); Verify.AreEqual("0.0", AnimatedIconTestHooks.GetLastAnimationSegmentEnd(animatedIcon)); }); void AnimatedIcon_LayoutUpdated(object sender, object e) { layoutUpdatedEvent.Set(); } }
private void Button_PointerExited(object sender, PointerRoutedEventArgs e) { AnimatedIcon.SetState(this.SearchAnimatedIcon, "Normal"); }
static void AddToAnimatedIconFactory(string stockId, AnimatedIcon aicon) { animationFactory [stockId] = aicon; }
public ServiceWidget(bool showDetails = false) { InnerBackgroundColor = Styles.BaseBackgroundColor; BorderWidth = 1; CornerRadius = new BorderCornerRadius(6, 6, 6, 6); Padding = 30; image = new ImageView(); image.MarginBottom = 2; title = new Label(); title.Font = Xwt.Drawing.Font.SystemFont.WithSize(16); statusWidget = new HBox(); statusWidget.Spacing = 3; statusIcon = new ImageView(); statusText = new Label() { Font = Font.WithSize(12), TextColor = Styles.SecondaryTextColor, }; statusWidget.PackStart(statusIcon); statusWidget.PackStart(statusText); statusWidget.Visible = false; statusWidget.MarginLeft = 5; addButton = new Button(); addButton.BackgroundColor = Styles.BaseSelectionBackgroundColor; addButton.LabelColor = Styles.BaseSelectionTextColor; addButton.MinWidth = 128; addButton.MinHeight = 34; addButton.Visible = false; addButton.Clicked += HandleAddButtonClicked; if (ImageService.IsAnimation("md-spinner-16", Gtk.IconSize.Menu)) { animatedStatusIcon = ImageService.GetAnimatedIcon("md-spinner-16", Gtk.IconSize.Menu); } var header = new HBox(); header.Spacing = 5; header.PackStart(image); header.PackStart(title); header.PackStart(statusWidget); var vbox = new VBox(); vbox.Spacing = 6; vbox.PackStart(header); description = new MarkupView { Selectable = false, LineSpacing = 6, MinWidth = 640, BackgroundColor = Styles.BaseBackgroundColor, }; platforms = new Label(); platforms.TextColor = Styles.SecondaryTextColor; platformWidget = new HBox(); platformWidget.PackStart(new Label { Text = GettextCatalog.GetString("Platforms:"), TextColor = Styles.SecondaryTextColor }, marginRight: 20); platformWidget.PackStart(platforms); vbox.PackStart(description, false, hpos: WidgetPlacement.Start); vbox.PackStart(platformWidget, false); var container = new HBox { Spacing = 0 }; container.PackStart(vbox, true); container.PackEnd(addButton, vpos: WidgetPlacement.Start); Content = container; ShowDetails = showDetails; UpdateAccessibility(); }
static Xwt.Drawing.Image LoadStockIcon(RuntimeAddin addin, string stockId, string resource, string imageFile, string iconId, Gtk.IconSize iconSize, string animation, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null, pixbuf2x = null; AnimatedIcon animatedIcon = null; Func <Stream[]> imageLoader = null; if (!string.IsNullOrEmpty(resource) || !string.IsNullOrEmpty(imageFile)) { // using the stream directly produces a gdk warning. byte[] buffer; if (resource != null) { imageLoader = delegate { var stream = addin.GetResource(resource); var stream2x = addin.GetResource2x(resource); if (stream2x == null) { return new [] { stream } } ; else { return new [] { stream, stream2x } }; }; } else { imageLoader = delegate { var file = addin.GetFilePath(imageFile); var stream = File.OpenRead(file); Stream stream2x = null; var file2x = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "@2x" + Path.GetExtension(file)); if (File.Exists(file2x)) { stream2x = File.OpenRead(file2x); } else { file2x = file + "@2x"; if (File.Exists(file2x)) { stream2x = File.OpenRead(file2x); } } if (stream2x == null) { return new [] { stream } } ; else { return new [] { stream, stream2x } }; }; } var streams = imageLoader(); var st = streams[0]; var st2x = streams.Length > 1 ? streams[1] : null; using (st) { if (st == null || st.Length < 0) { LoggingService.LogError("Did not find resource '{0}' in addin '{1}' for icon '{2}'", resource, addin.Id, stockId); return(null); } buffer = new byte [st.Length]; st.Read(buffer, 0, (int)st.Length); } pixbuf = new Gdk.Pixbuf(buffer); using (st2x) { if (st2x != null && st2x.Length >= 0) { buffer = new byte [st2x.Length]; st2x.Read(buffer, 0, (int)st2x.Length); pixbuf2x = new Gdk.Pixbuf(buffer); } } } else if (!string.IsNullOrEmpty(iconId)) { var id = GetStockIdForImageSpec(addin, iconId, iconSize); pixbuf = GetPixbuf(id, iconSize); pixbuf2x = Get2xIconVariant(pixbuf); // This may be an animation, get it animationFactory.TryGetValue(id, out animatedIcon); } else if (!string.IsNullOrEmpty(animation)) { string id = GetStockIdForImageSpec(addin, "animation:" + animation, iconSize); pixbuf = GetPixbuf(id, iconSize); // This *should* be an animation animationFactory.TryGetValue(id, out animatedIcon); } Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconSize; if (pixbuf != null) { AddToIconFactory(stockId, pixbuf, pixbuf2x, size); } if (animatedIcon != null) { AddToAnimatedIconFactory(stockId, animatedIcon); } var img = Xwt.Toolkit.CurrentEngine.WrapImage(pixbuf); if (pixbuf2x != null) { var img2x = Xwt.Toolkit.CurrentEngine.WrapImage(pixbuf2x); img = Xwt.Drawing.Image.CreateMultiResolutionImage(new [] { img, img2x }); } if (imageLoader != null) { img.SetStreamSource(imageLoader); } return(img); } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", stockId), ex); return(null); } }