protected override void OnApplyTemplate() { m_layoutRoot = (Grid)GetTemplateChild("LayoutRoot"); m_imageViewer = (Image)GetTemplateChild("ImageViewer"); m_imageThumb = (FrameworkElement)GetTemplateChild("ImageThumb"); m_imageThumb.ManipulationDelta += ImageThumb_ManipulationDelta; m_imageThumb.PointerWheelChanged += ImageThumb_PointerWheelChanged; m_outerClip = (Geometry)GetTemplateChild("OuterClip"); m_innerClip = (Geometry)GetTemplateChild("InnerClip"); m_thumbsContainer = (Grid)GetTemplateChild("ThumbsContainer"); m_imageThumbTransform = (CompositeTransform)GetTemplateChild("ImageThumbTransform"); var leftThumb = (ImageCropperThumb)GetTemplateChild("LeftThumb"); if (leftThumb != null) { leftThumb.PointerEntered += WEThumb_PointerEntered; leftThumb.PointerExited += Thumb_PointerExited; leftThumb.PointerPressed += Thumb_PointerPressed; leftThumb.PointerReleased += Thumb_PointerReleased; leftThumb.PointerMoved += LeftThumb_PointerMoved; } var topThumb = (ImageCropperThumb)GetTemplateChild("TopThumb"); if (topThumb != null) { topThumb.PointerEntered += NSThumb_PointerEntered; topThumb.PointerExited += Thumb_PointerExited; topThumb.PointerPressed += Thumb_PointerPressed; topThumb.PointerReleased += Thumb_PointerReleased; topThumb.PointerMoved += TopThumb_PointerMoved; } var rightThumb = (ImageCropperThumb)GetTemplateChild("RightThumb"); if (rightThumb != null) { rightThumb.PointerEntered += WEThumb_PointerEntered; rightThumb.PointerExited += Thumb_PointerExited; rightThumb.PointerPressed += Thumb_PointerPressed; rightThumb.PointerReleased += Thumb_PointerReleased; rightThumb.PointerMoved += RightThumb_PointerMoved; } var bottomThumb = (ImageCropperThumb)GetTemplateChild("BottomThumb"); if (bottomThumb != null) { bottomThumb.PointerEntered += NSThumb_PointerEntered; bottomThumb.PointerExited += Thumb_PointerExited; bottomThumb.PointerPressed += Thumb_PointerPressed; bottomThumb.PointerReleased += Thumb_PointerReleased; bottomThumb.PointerMoved += BottomThumb_PointerMoved; } var topLeftThumb = (ImageCropperThumb)GetTemplateChild("TopLeftThumb"); if (topLeftThumb != null) { topLeftThumb.PointerEntered += NWSEThumb_PointerEntered; topLeftThumb.PointerExited += Thumb_PointerExited; topLeftThumb.PointerPressed += Thumb_PointerPressed; topLeftThumb.PointerReleased += Thumb_PointerReleased; topLeftThumb.PointerMoved += TopLeftThumb_PointerMoved; } var topRightThumb = (ImageCropperThumb)GetTemplateChild("TopRightThumb"); if (topLeftThumb != null) { topRightThumb.PointerEntered += NESWThumb_PointerEntered; topRightThumb.PointerExited += Thumb_PointerExited; topRightThumb.PointerPressed += Thumb_PointerPressed; topRightThumb.PointerReleased += Thumb_PointerReleased; topRightThumb.PointerMoved += TopRightThumb_PointerMoved; } var bottomLeftThumb = (ImageCropperThumb)GetTemplateChild("BottomLeftThumb"); if (bottomLeftThumb != null) { bottomLeftThumb.PointerEntered += NESWThumb_PointerEntered; bottomLeftThumb.PointerExited += Thumb_PointerExited; bottomLeftThumb.PointerPressed += Thumb_PointerPressed; bottomLeftThumb.PointerReleased += Thumb_PointerReleased; bottomLeftThumb.PointerMoved += BottomLeftThumb_PointerMoved; } var bottomRightThumb = (ImageCropperThumb)GetTemplateChild("BottomRightThumb"); if (bottomRightThumb != null) { bottomRightThumb.PointerEntered += NWSEThumb_PointerEntered; bottomRightThumb.PointerExited += Thumb_PointerExited; bottomRightThumb.PointerPressed += Thumb_PointerPressed; bottomRightThumb.PointerReleased += Thumb_PointerReleased; bottomRightThumb.PointerMoved += BottomRightThumb_PointerMoved; } if (m_imageWaiting) { m_imageWaiting = false; SetSource(m_imageSource, m_imagePreview, m_imageSize.Width, m_imageSize.Height); } else { UpdateCropRectangle(CropRectangle, false); } }
protected override void OnApplyTemplate() { m_layoutRoot = (Grid)GetTemplateChild("LayoutRoot"); m_imageViewer = (Image)GetTemplateChild("ImageViewer"); m_imageThumb = (FrameworkElement)GetTemplateChild("ImageThumb"); //m_imageThumb.ManipulationMode = ManipulationModes.Rotate | ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY; m_imageThumb.ManipulationDelta += ImageThumb_ManipulationDelta; m_outerClip = (Geometry)GetTemplateChild("OuterClip"); m_innerClip = (Geometry)GetTemplateChild("InnerClip"); m_thumbsContainer = (Grid)GetTemplateChild("ThumbsContainer"); m_imageThumbTransform = (CompositeTransform)GetTemplateChild("ImageThumbTransform"); var leftThumb = (ImageCropperThumb)GetTemplateChild("LeftThumb"); if (leftThumb != null) { leftThumb.PointerEntered += WEThumb_PointerEntered; leftThumb.PointerExited += Thumb_PointerExited; leftThumb.PointerPressed += Thumb_PointerPressed; leftThumb.PointerReleased += Thumb_PointerReleased; leftThumb.PointerMoved += LeftThumb_PointerMoved; } var topThumb = (ImageCropperThumb)GetTemplateChild("TopThumb"); if (topThumb != null) { topThumb.PointerEntered += NSThumb_PointerEntered; topThumb.PointerExited += Thumb_PointerExited; topThumb.PointerPressed += Thumb_PointerPressed; topThumb.PointerReleased += Thumb_PointerReleased; topThumb.PointerMoved += TopThumb_PointerMoved; } var rightThumb = (ImageCropperThumb)GetTemplateChild("RightThumb"); if (rightThumb != null) { rightThumb.PointerEntered += WEThumb_PointerEntered; rightThumb.PointerExited += Thumb_PointerExited; rightThumb.PointerPressed += Thumb_PointerPressed; rightThumb.PointerReleased += Thumb_PointerReleased; rightThumb.PointerMoved += RightThumb_PointerMoved; } var bottomThumb = (ImageCropperThumb)GetTemplateChild("BottomThumb"); if (bottomThumb != null) { bottomThumb.PointerEntered += NSThumb_PointerEntered; bottomThumb.PointerExited += Thumb_PointerExited; bottomThumb.PointerPressed += Thumb_PointerPressed; bottomThumb.PointerReleased += Thumb_PointerReleased; bottomThumb.PointerMoved += BottomThumb_PointerMoved; } var topLeftThumb = (ImageCropperThumb)GetTemplateChild("TopLeftThumb"); if (topLeftThumb != null) { topLeftThumb.PointerEntered += NWSEThumb_PointerEntered; topLeftThumb.PointerExited += Thumb_PointerExited; topLeftThumb.PointerPressed += Thumb_PointerPressed; topLeftThumb.PointerReleased += Thumb_PointerReleased; topLeftThumb.PointerMoved += TopLeftThumb_PointerMoved; } var topRightThumb = (ImageCropperThumb)GetTemplateChild("TopRightThumb"); if (topLeftThumb != null) { topRightThumb.PointerEntered += NESWThumb_PointerEntered; topRightThumb.PointerExited += Thumb_PointerExited; topRightThumb.PointerPressed += Thumb_PointerPressed; topRightThumb.PointerReleased += Thumb_PointerReleased; topRightThumb.PointerMoved += TopRightThumb_PointerMoved; } var bottomLeftThumb = (ImageCropperThumb)GetTemplateChild("BottomLeftThumb"); if (bottomLeftThumb != null) { bottomLeftThumb.PointerEntered += NESWThumb_PointerEntered; bottomLeftThumb.PointerExited += Thumb_PointerExited; bottomLeftThumb.PointerPressed += Thumb_PointerPressed; bottomLeftThumb.PointerReleased += Thumb_PointerReleased; bottomLeftThumb.PointerMoved += BottomLeftThumb_PointerMoved; } var bottomRightThumb = (ImageCropperThumb)GetTemplateChild("BottomRightThumb"); if (bottomRightThumb != null) { bottomRightThumb.PointerEntered += NWSEThumb_PointerEntered; bottomRightThumb.PointerExited += Thumb_PointerExited; bottomRightThumb.PointerPressed += Thumb_PointerPressed; bottomRightThumb.PointerReleased += Thumb_PointerReleased; bottomRightThumb.PointerMoved += BottomRightThumb_PointerMoved; } UpdateCropRectangle(CropRectangle, false); }
private void attBtn_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { _newBtnTransform = btnAttach.GetCompositeTransform(); }
private void Control_SizeChanged(object sender, SizeChangedEventArgs e) { Radius = Math.Min(e.NewSize.Height, e.NewSize.Width) / 2.0; double diameter = Radius * 2; LayoutRoot.Width = diameter; LayoutRoot.Height = diameter; InnerRadius = Radius - 100; _holeDiameter = GetEllipseDiameter(Radius); _pegDiameter = _holeDiameter + 2; // // drives the layout of all the peg holes OutsideHole_TranslateX = CalculateOutsideHole_TranslateX(); InsideHole_TranslateX = CalculateInsideHole_TranslateX(); WinningHole_TranslateX = CalculateWinningHole_TranslateX(); for (int i = 0; i < 122; i++) { Ellipse ellipse = _playerHoles[i]; ellipse.Width = _holeDiameter; ellipse.Height = _holeDiameter; CompositeTransform ct = ellipse.RenderTransform as CompositeTransform; ct.CenterX = -OutsideHole_TranslateX; ct.TranslateX = OutsideHole_TranslateX; ellipse = _computerHoles[i]; ellipse.Width = _holeDiameter; ellipse.Height = _holeDiameter; ct = ellipse.RenderTransform as CompositeTransform; ct.CenterX = -InsideHole_TranslateX; ct.TranslateX = InsideHole_TranslateX; } CompositeTransform _winningTransform = ((Ellipse)_winningHole).RenderTransform as CompositeTransform; _winningTransform.CenterX = -WinningHole_TranslateX; _winningTransform.TranslateX = WinningHole_TranslateX; // // there is a XAML bug where I can't animate and databind the same object foreach (RoundRectDivider divider in _dividers) { divider.Radius = Radius; } UpdatePegTransform(_playerPegScore1, true); UpdatePegTransform(_playerPegScore2, true); UpdatePegTransform(_computerPegScore1, false); UpdatePegTransform(_computerPegScore2, false); // // support for getting the user score _ringGetPlayerScore.Radius = Radius; _ringGetPlayerScore.InnerRadius = Radius - 100; ((CompositeTransform)_vbUp.RenderTransform).CenterX = Radius - 50; ((CompositeTransform)_vbUp.RenderTransform).TranslateX = -(Radius - 50); ((CompositeTransform)_vbDown.RenderTransform).CenterX = Radius - 50; ((CompositeTransform)_vbDown.RenderTransform).TranslateX = -(Radius - 50); ((CompositeTransform)_vbOk.RenderTransform).CenterX = Radius - 33; ((CompositeTransform)_vbOk.RenderTransform).TranslateX = -(Radius - 33); ((CompositeTransform)_vbScore.RenderTransform).CenterX = Radius - 80; ((CompositeTransform)_vbScore.RenderTransform).TranslateX = -(Radius - 80); _rectPendulum1.Height = Radius - 100; _rectPendulum2.Height = Radius - 100; ((CompositeTransform)_rectPendulum1.RenderTransform).TranslateY = (Radius - 100) / 2.0; ((CompositeTransform)_rectPendulum2.RenderTransform).TranslateY = (Radius - 100) / 2.0; _ctEllipseRivet1.TranslateY = Radius - 100; _ctEllipseRivet1.CenterY = 100 - Radius; _ctEllipseRivet2.TranslateY = Radius - 100; _ctEllipseRivet2.CenterY = 100 - Radius; _ctPendulumCrossbar.TranslateY = (Radius - 100) * Math.Cos(20 * Math.PI / 180);; _rectPendulumCrossbar.Width = 2 * (Radius - 100) * Math.Sin(20 * Math.PI / 180); }
public ShopeeNewItemPageViewModel() { this.isWarningTbxPriceShown = Visibility.Collapsed; this.isWarningTbxStockShown = Visibility.Collapsed; this.ListImages.Add(new NewItemImages()); this.ListVariations.Add(new ItemVariations { index = 1, }); var Var = new Variations(this.ListVariations[0]); Var.OptionAdded += (m, e) => { var sender = m as Variations; this.__UpdatePriceTable(sender); }; this.ListVariations[0].variations.Add(Var); this.isMultiVariationPricingShown = Visibility.Collapsed; this.isAVariationPricingShown = Visibility.Visible; if (StaticResources.ListCategories.Count() == 0) { if (StaticResources.SelectedShopLogin != null) { Utility.getCategories(StaticResources.SelectedShopLogin, new AsyncCallback(_getCategoriesCallback)); } } else { this.ListCategories = StaticResources.ListCategories; } BrLogoImageLoaded = new DelegateCommand <Border>((s) => { this._brLogoImage = s; }); MovableManipulationStarted = new DelegateCommand <CompositeTransform>((s) => { this._brLogoImage.Opacity = 0.4; this._brTransform = s; }); BrTransformLoaded = new DelegateCommand <CompositeTransform>((s) => { this._brTransform = s; }); MovableManipulationDelta = new DelegateCommand <ManipulationDeltaRoutedEventArgs>((s) => { var calibrateSpace = (int)(7 * Math.Abs(this._brTransform.ScaleX - 1) * 10); int boundX = 0; int boundY = 0; if (this._brTransform.ScaleX < 1) { boundX = 100 + calibrateSpace; boundY = 105 + calibrateSpace; } else { boundX = 100 - calibrateSpace; boundY = 105 - calibrateSpace; } this._brTransform.TranslateX += s.Delta.Translation.X; this._brTransform.TranslateY += s.Delta.Translation.Y; if (this._brTransform.TranslateX < -100) { this._brTransform.TranslateX = -100; } if (this._brTransform.TranslateX > boundX) { this._brTransform.TranslateX = boundX; } if (this._brTransform.TranslateY < -105) { this._brTransform.TranslateY = -105; } if (this._brTransform.TranslateY > boundY) { this._brTransform.TranslateY = boundY; } }); MovableManipulationCompleted = new DelegateCommand(() => { this._brLogoImage.Opacity = 1; }); DragImageOverHandler = new DelegateCommand <DragEventArgs>((s) => { s.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy; }); DropImageHandler = new DelegateCommand <DragEventArgs>(async(s) => { if (s.DataView.Contains(StandardDataFormats.StorageItems)) { var items = await s.DataView.GetStorageItemsAsync(); if (items.Count > 0) { var storageFile = items[0] as StorageFile; var bitmapImage = new BitmapImage(); bitmapImage.SetSource(await storageFile.OpenAsync(FileAccessMode.Read)); // Set the image on the main page to the dropped image LogoImage.Source = bitmapImage; } } }); ScaleLogoImageHandle = new DelegateCommand <PointerRoutedEventArgs>((s) => { double dblDelta_Scroll = s.GetCurrentPoint(this._brLogoImage).Properties.MouseWheelDelta; dblDelta_Scroll = (dblDelta_Scroll > 0) ? 1.1 : 0.9; if (this._brTransform != null) { this._brTransform.ScaleX = this._brTransform.ScaleX * dblDelta_Scroll; this._brTransform.ScaleY = this._brTransform.ScaleY * dblDelta_Scroll; if (this._brTransform.ScaleY > 1.5) { this._brTransform.ScaleX = 1.5; this._brTransform.ScaleY = 1.5; } if (this._brTransform.ScaleX < 0.7) { this._brTransform.ScaleX = 0.7; this._brTransform.ScaleY = 0.7; } } }); BtImageProcessingTapped = new DelegateCommand(() => { this.TgGrImgProcessing = "Visible"; }); BtCancelGrImgProcessingTapped = new DelegateCommand(() => { this.TgGrImgProcessing = "Collapsed"; }); BtDeleteFrameImageTapped = new DelegateCommand(() => { this.FrameImage = new NewItemImages(); }); BtAddNewFrameImageTapped = new DelegateCommand(async() => { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); if (file != null) { using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(fileStream); this.FrameImage.Source = bitmapImage; this.FrameImage.sourceStorageFile = file; this.FrameImage.Token = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); this.FrameImage.isAddImageShown = Visibility.Collapsed; this.FrameImage.isCanDeleteShown = Visibility.Visible; } } }); BtDeleteLogoImageTapped = new DelegateCommand(() => { this.LogoImage = new NewItemImages(); }); BtAddLogoImageTapped = new DelegateCommand(async() => { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); if (file != null) { using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(fileStream); this.LogoImage.Source = bitmapImage; this.LogoImage.sourceStorageFile = file; this.LogoImage.Token = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); this.LogoImage.isAddImageShown = Visibility.Collapsed; this.LogoImage.isCanDeleteShown = Visibility.Visible; } } }); BtUploadItemTapped = new DelegateCommand(async() => { if (string.IsNullOrEmpty(this.TbItemName)) { await new MessageDialog("Product name could not be a null or empty value").ShowAsync(); return; } if (string.IsNullOrEmpty(this.TbItemDescription)) { await new MessageDialog("Product description could not be a null or empty value").ShowAsync(); return; } if (this.SelectedMainCategory == null || this.SelectedSubCategory == null || this.SelectedSubSubCategory == null) { await new MessageDialog("Product category could not be a null value").ShowAsync(); return; } if (this.ListImages.Where(p => !string.IsNullOrEmpty(p.Token)).ToList().Count == 0) { await new MessageDialog("Please upload atleast one images").ShowAsync(); return; } if (string.IsNullOrEmpty(this.TbItemPrice) || string.IsNullOrEmpty(this.TbItemStock)) { await new MessageDialog("Product pricing could not be a null value").ShowAsync(); return; } else { if (this._checkTextBoxValidate(this.TbItemPrice) == false || this._checkTextBoxValidate(this.TbItemStock) == false) { await new MessageDialog("Product pricing must be a number").ShowAsync(); this.TbItemPrice = string.Empty; this.TbItemStock = string.Empty; return; } } if (this.ListFullAttribute.Where(p => !string.IsNullOrEmpty(p.data.multi_lang[0].Choose)).ToList().Count != this.ListFullAttribute.Count()) { await new MessageDialog("Please select all proper attributes for your product").ShowAsync(); return; } if (StaticResources.LogisticsChannel.Count() == 0) { await new MessageDialog(StaticResources.choosingLanguage.GlobalWarningConfig).ShowAsync(); StaticResources.NavigationFrame.Navigate(typeof(ShopeeConfigPage), null, new DrillInNavigationTransitionInfo()); return; } var item = await this._createNewItemInstance(); if (this.ListImages.Count > 0) { await Utility.UploadItemfromLocal_V3(StaticResources.SelectedShopLogin, null, false, this.ListImages.Where(p => !string.IsNullOrEmpty(p.Token)).ToList(), item, false); } }); BtAddNewOptionTapped = new DelegateCommand <ItemVariations>((s) => { if (!string.IsNullOrEmpty(s.variations[s.variations.Count() - 1].Option)) { var newVar = new Variations(s); newVar.index = s.variations.Count() + 1; newVar.OptionAdded += (m, e) => { var sender = m as Variations; this.__UpdatePriceTable(sender); }; s.variations.Add(newVar); } }); BtAddNewVariationTapped = new DelegateCommand(() => { if (this.ListVariations.Count < 2) { this.ListVariations.Add(new ItemVariations { index = 2, }); var Var1 = new Variations(this.ListVariations[1]); Var1.index = 1; Var1.OptionAdded += (m, e) => { var sender = m as Variations; this.__UpdatePriceTable(sender); }; this.ListVariations[1].variations.Add(Var1); this.isAVariationPricingShown = Visibility.Collapsed; this.isMultiVariationPricingShown = Visibility.Visible; } }); BtDeleteVariationTapped = new DelegateCommand <ItemVariations>((s) => { if (this.ListVariations.Count() > 1) { this.ListVariations.Remove(s); this.ListVariations[0].index = 1; this.isMultiVariationPricingShown = Visibility.Collapsed; this.isAVariationPricingShown = Visibility.Visible; } }); BtDeleteImageTapped = new DelegateCommand <NewItemImages>((s) => { this.ListImages.Remove(s); if (this.ListImages[this.ListImages.Count() - 1].Source != null) { this.ListImages.Add(new NewItemImages()); } }); BtDeleteOptionTapped = new DelegateCommand <Variations>((s) => { var par = s.Parent; if (par.variations.Count() > 1) { par.variations.Remove(s); } }); BtApplyForAllVariationsTapped = new DelegateCommand(async() => { if (!string.IsNullOrEmpty(this.TbItemPrice) && !string.IsNullOrEmpty(this.TbItemStock)) { if (this._isNumberic == true) { foreach (var Va in this.ListVariations[0].variations) { foreach (var subVa in Va.subVariations) { subVa.Price = this.TbItemPrice; subVa.Stock = this.TbItemStock; } } } else { await new MessageDialog("Product price/stock must be a number").ShowAsync(); } } else { await new MessageDialog("Product price/stock could not be null").ShowAsync(); } }); BtAddNewImageTapped = new DelegateCommand <NewItemImages>(async(s) => { if (this.ListImages.Where(p => p.Source != null).ToList().Count() >= 8) { await new MessageDialog("Maximum: 8 photos").ShowAsync(); return; } var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); var files = await picker.PickMultipleFilesAsync(); if (files.Count() > 0) { this.ListImages.Remove(s); foreach (var file in files) { if (this.ListImages.Where(p => p.Source != null).ToList().Count() < 8) { using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(fileStream); this.ListImages.Add(new NewItemImages() { Source = bitmapImage, sourceStorageFile = file, Token = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file), isAddImageShown = Visibility.Collapsed, isCanDeleteShown = Visibility.Visible, }); } } } if (this.ListImages.Count() < 8) { this.ListImages.Add(new NewItemImages()); } } }); }
public static void ClearAnimationProperties(FrameworkElement element) { var planeProjection = element.Projection as PlaneProjection; if (planeProjection == null) element.Projection = planeProjection = new PlaneProjection(); var transform = element.RenderTransform as CompositeTransform; if (transform == null) element.RenderTransform = transform = new CompositeTransform { CenterX = 0.5, CenterY = 0.5 }; element.RenderTransformOrigin = new Point(0.5, 0.5); element.Opacity = 1; transform.Rotation = 0; transform.TranslateX = 0; transform.TranslateY = 0; transform.ScaleX = 1; transform.ScaleY = 1; planeProjection.RotationX = 0; planeProjection.RotationY = 0; planeProjection.RotationZ = 0; planeProjection.GlobalOffsetX = 0; planeProjection.GlobalOffsetY = 0; planeProjection.GlobalOffsetZ = 0; planeProjection.CenterOfRotationX = 0; planeProjection.CenterOfRotationY = 0; planeProjection.CenterOfRotationZ = 0; }
private void grdNewQButton_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { _newQBtnTransform = grdNewQButton.GetCompositeTransform(); }
public void Render(Canvas funky, Canvas parent, Canvas window, CompositeTransform textRotation, Action<Action> dispatcher, RoomInfo location) { dispatcher(() => { CompositeTransform c = (CompositeTransform)funky.RenderTransform; c.CenterX = buildingBounds.CenterX; c.CenterY = buildingBounds.CenterY; funky.Width = buildingBounds.Width; funky.Height = buildingBounds.Height; c.TranslateX = -buildingBounds.CenterX + window.ActualWidth / 2; c.TranslateY = -buildingBounds.CenterY + window.ActualHeight / 2; }); foreach (var description in elements.Where(p => p.Parent == ParentType.Labels || p.Parent == ParentType.Rooms)) { this.checkRunActions(50, () => RenderElement(parent, textRotation, description), dispatcher); } // Highlight the correct room this.checkRunActions(1, () => { var roomElement = parent.Children.OfType<Path>().FirstOrDefault(p => ToInt(p.Tag as string) == location.Room); if (roomElement != null) { roomElement.Fill = new SolidColorBrush(Colors.Magenta); } }, dispatcher); foreach (var description in elements.Where(p => p.Parent == ParentType.Background)) { // Fewer because these paths are more complex this.checkRunActions(5, () => RenderElement(parent, textRotation, description), dispatcher); } this.checkRunActions(0, () => { }, dispatcher); }
/// <summary> /// Returns new CompositeTransform by easing startValue to endValue using a time percentage 0 -> 1. /// </summary> public static CompositeTransform EaseValue(CompositeTransform startValue, CompositeTransform endValue, double percent) { return new CompositeTransform { CenterX = (startValue.CenterX == endValue.CenterX) ? endValue.CenterX : EaseValue(startValue.CenterX, endValue.CenterX, percent), CenterY = (startValue.CenterY == endValue.CenterY) ? endValue.CenterY : EaseValue(startValue.CenterY, endValue.CenterY, percent), Rotation = (startValue.Rotation == endValue.Rotation) ? endValue.Rotation : EaseValue(startValue.Rotation, endValue.Rotation, percent), ScaleX = (startValue.ScaleX == endValue.ScaleX) ? endValue.ScaleX : EaseValue(startValue.ScaleX, endValue.ScaleX, percent), ScaleY = (startValue.ScaleY == endValue.ScaleY) ? endValue.ScaleY : EaseValue(startValue.ScaleY, endValue.ScaleY, percent), SkewX = (startValue.SkewX == endValue.SkewX) ? endValue.SkewX : EaseValue(startValue.SkewX, endValue.SkewX, percent), SkewY = (startValue.SkewY == endValue.SkewY) ? endValue.SkewY : EaseValue(startValue.SkewY, endValue.SkewY, percent), TranslateX = (startValue.TranslateX == endValue.TranslateX) ? endValue.TranslateX : EaseValue(startValue.TranslateX, endValue.TranslateX, percent), TranslateY = (startValue.TranslateY == endValue.TranslateY) ? endValue.TranslateY : EaseValue(startValue.TranslateY, endValue.TranslateY, percent), }; }
private void ImagesGrid_OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) { e.Handled = true; if (_panAndZoomBehavior.CurrentScaleX > 1.0) { return; } if (_slideAnimating) { return; } if (_verticalDrag == null) { _verticalDrag = Math.Abs(e.DeltaManipulation.Translation.Y) > Math.Abs(e.DeltaManipulation.Translation.X); } if (_verticalDrag == false) { var transform = ImagesGrid.RenderTransform as CompositeTransform; if (transform == null) { return; } if (e.CumulativeManipulation.Translation.X < 0.0 && ViewModel.CanSlideLeft) { transform.TranslateX += e.DeltaManipulation.Translation.X; } else if (e.CumulativeManipulation.Translation.X > 0.0 && ViewModel.CanSlideRight) { transform.TranslateX += e.DeltaManipulation.Translation.X; } var percent = transform.TranslateX / 480.0; #if !NO_RIBBON Ribbon.Move(percent); #endif transform.TranslateX = PanAndZoomBehavior.Clamp(transform.TranslateX, -480.0 - 12.0, 480.0 + 12.0); _panAndZoomBehavior.IsEnabled = transform.TranslateX == 0.0; } else { var transform = ImagesGrid.RenderTransform as CompositeTransform; if (transform == null) { return; } var translate = new CompositeTransform { TranslateX = 0, TranslateY = e.CumulativeManipulation.Translation.Y }; var rootFrameHeight = ((PhoneApplicationFrame)Application.Current.RootVisual).ActualHeight; var deltaY = Math.Abs(translate.TranslateY + translate.ScaleY * transform.TranslateY + (translate.ScaleY - 1) * (transform.CenterY - translate.CenterY)); var opacity = (rootFrameHeight - deltaY) / rootFrameHeight; var backgroundBrush = (SolidColorBrush)BackgroundBorder.Background; var backgroundColor = backgroundBrush.Color; backgroundColor.A = (byte)(opacity * byte.MaxValue); BackgroundBorder.Opacity = opacity; ImagesGrid.RenderTransform = translate; _panAndZoomBehavior.IsEnabled = translate.TranslateY == 0.0; } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // TimeUnit : the seconds between two number(long line) int secondsPerTimeUnit = 15; int minimumScaleUnitLength = 100; int timeUnitLength = 300; TimeSpan ts = new TimeSpan(0, 0, secondsPerTimeUnit); TimeSpan interval = new TimeSpan(0, 0, secondsPerTimeUnit); int width = (int)TimeLineScaleCanvas.ActualWidth; int height = (int)TimeLineScaleCanvas.ActualHeight; int y1_short = height / 2; int y1_long = height / 4; double y2 = height; int linePerTimeUnit = timeUnitLength / minimumScaleUnitLength; int totalLineCount = width / minimumScaleUnitLength; for (int i = 1; i < totalLineCount; i++) { int x = minimumScaleUnitLength * i; int y1; if (i % linePerTimeUnit == 0) { y1 = y1_long; CompositeTransform ct = new CompositeTransform { TranslateX = x + 10, TranslateY = 5 }; TextBlock tb = new TextBlock { Text = ts.ToString("mm\\:ss"), RenderTransform = ct, Foreground = new SolidColorBrush(Colors.White) }; TimeLineScaleCanvas.Children.Add(tb); ts = ts.Add(interval); } else { y1 = y1_short; } Line line = new Line { X1 = x, Y1 = y1, X2 = x, Y2 = y2, Stroke = new SolidColorBrush(Colors.White) }; TimeLineScaleCanvas.Children.Add(line); } }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); m_layoutRoot = (Grid)GetTemplateChild("LayoutRoot"); m_imageViewer = (Image)GetTemplateChild("ImageViewer"); m_imagePresenter = (FrameworkElement)GetTemplateChild("ImagePresenter"); m_thumbsContainer = (Grid)GetTemplateChild("ThumbsContainer"); m_clip = (Path)GetTemplateChild("Clip"); if (m_clip != null) { SetMask(_mask); } m_imageViewer.SizeChanged += ImageViewer_SizeChanged; m_imagePresenter.RenderTransformOrigin = new Point(0.5, 0.5); m_imagePresenter.RenderTransform = m_imagePresenterTransform = new CompositeTransform(); var leftThumb = (CustomImageCropperThumb)GetTemplateChild("LeftThumb"); if (leftThumb != null) { leftThumb.PointerEntered += WEThumb_PointerEntered; leftThumb.PointerExited += Thumb_PointerExited; leftThumb.PointerPressed += Thumb_PointerPressed; leftThumb.PointerReleased += Thumb_PointerReleased; leftThumb.PointerMoved += LeftThumb_PointerMoved; } var topThumb = (CustomImageCropperThumb)GetTemplateChild("TopThumb"); if (topThumb != null) { topThumb.PointerEntered += NSThumb_PointerEntered; topThumb.PointerExited += Thumb_PointerExited; topThumb.PointerPressed += Thumb_PointerPressed; topThumb.PointerReleased += Thumb_PointerReleased; topThumb.PointerMoved += TopThumb_PointerMoved; } var rightThumb = (CustomImageCropperThumb)GetTemplateChild("RightThumb"); if (rightThumb != null) { rightThumb.PointerEntered += WEThumb_PointerEntered; rightThumb.PointerExited += Thumb_PointerExited; rightThumb.PointerPressed += Thumb_PointerPressed; rightThumb.PointerReleased += Thumb_PointerReleased; rightThumb.PointerMoved += RightThumb_PointerMoved; } var bottomThumb = (CustomImageCropperThumb)GetTemplateChild("BottomThumb"); if (bottomThumb != null) { bottomThumb.PointerEntered += NSThumb_PointerEntered; bottomThumb.PointerExited += Thumb_PointerExited; bottomThumb.PointerPressed += Thumb_PointerPressed; bottomThumb.PointerReleased += Thumb_PointerReleased; bottomThumb.PointerMoved += BottomThumb_PointerMoved; } var topLeftThumb = (CustomImageCropperThumb)GetTemplateChild("TopLeftThumb"); if (topLeftThumb != null) { topLeftThumb.PointerEntered += NWSEThumb_PointerEntered; topLeftThumb.PointerExited += Thumb_PointerExited; topLeftThumb.PointerPressed += Thumb_PointerPressed; topLeftThumb.PointerReleased += Thumb_PointerReleased; topLeftThumb.PointerMoved += TopLeftThumb_PointerMoved; } var topRightThumb = (CustomImageCropperThumb)GetTemplateChild("TopRightThumb"); if (topLeftThumb != null) { topRightThumb.PointerEntered += NESWThumb_PointerEntered; topRightThumb.PointerExited += Thumb_PointerExited; topRightThumb.PointerPressed += Thumb_PointerPressed; topRightThumb.PointerReleased += Thumb_PointerReleased; topRightThumb.PointerMoved += TopRightThumb_PointerMoved; } var bottomLeftThumb = (CustomImageCropperThumb)GetTemplateChild("BottomLeftThumb"); if (bottomLeftThumb != null) { bottomLeftThumb.PointerEntered += NESWThumb_PointerEntered; bottomLeftThumb.PointerExited += Thumb_PointerExited; bottomLeftThumb.PointerPressed += Thumb_PointerPressed; bottomLeftThumb.PointerReleased += Thumb_PointerReleased; bottomLeftThumb.PointerMoved += BottomLeftThumb_PointerMoved; } var bottomRightThumb = (CustomImageCropperThumb)GetTemplateChild("BottomRightThumb"); if (bottomRightThumb != null) { bottomRightThumb.PointerEntered += NWSEThumb_PointerEntered; bottomRightThumb.PointerExited += Thumb_PointerExited; bottomRightThumb.PointerPressed += Thumb_PointerPressed; bottomRightThumb.PointerReleased += Thumb_PointerReleased; bottomRightThumb.PointerMoved += BottomRightThumb_PointerMoved; } var middleThumb = (Rectangle)GetTemplateChild("MiddleThumb"); if (middleThumb != null) { middleThumb.PointerPressed += Thumb_PointerPressed; middleThumb.PointerReleased += Thumb_PointerReleased; middleThumb.PointerMoved += MiddleThumb_PointerMoved; } }
/// <summary> /// Runs the cascades animation. /// </summary> /// <exception cref="System.InvalidOperationException"></exception> public void Cascade() { if (!_isLoaded || _layoutGrid == null) { return; } if (Rows < 1) { Rows = 1; } if (Columns < 1) { Columns = 1; } _layoutGrid.Children.Clear(); _layoutGrid.RowDefinitions.Clear(); _layoutGrid.ColumnDefinitions.Clear(); for (int row = 0; row < Rows; row++) { _layoutGrid.RowDefinitions.Add(new RowDefinition()); } for (int column = 0; column < Columns; column++) { _layoutGrid.ColumnDefinitions.Add(new ColumnDefinition()); } var sb = new Storyboard(); var totalDurationInSeconds = RowDelay.TotalSeconds * (Rows - 1) + ColumnDelay.TotalSeconds * (Columns - 1) + TileDuration.TotalSeconds; CascadeDirection direction = this.CascadeDirection; if (direction == CascadeDirection.Random) { direction = (CascadeDirection)Random.Next((int)CascadeDirection.Random); } int startColumn; int exclusiveEndColumn; int columnIncrement; int startRow; int exclusiveEndRow; int rowIncrement; switch (direction) { case CascadeDirection.Shuffle: case CascadeDirection.TopLeft: startColumn = 0; exclusiveEndColumn = Columns; columnIncrement = 1; startRow = 0; exclusiveEndRow = Rows; rowIncrement = 1; break; case CascadeDirection.TopRight: startColumn = Columns - 1; exclusiveEndColumn = -1; columnIncrement = -1; startRow = 0; exclusiveEndRow = Rows; rowIncrement = 1; break; case CascadeDirection.BottomRight: startColumn = Columns - 1; exclusiveEndColumn = -1; columnIncrement = -1; startRow = Rows - 1; exclusiveEndRow = -1; rowIncrement = -1; break; case CascadeDirection.BottomLeft: startColumn = 0; exclusiveEndColumn = Columns; columnIncrement = 1; startRow = Rows - 1; exclusiveEndRow = -1; rowIncrement = -1; break; default: throw new InvalidOperationException(); } List <Tuple <int, int> > rectCoords = new List <Tuple <int, int> >(Rows * Columns); List <Rectangle> rects = new List <Rectangle>(Rows * Columns); List <PlaneProjection> projs = new List <PlaneProjection>(Rows * Columns); for (int row = startRow; row != exclusiveEndRow; row = row + rowIncrement) { for (int column = startColumn; column != exclusiveEndColumn; column = column + columnIncrement) { var rect = new Rectangle(); rects.Add(rect); Grid.SetRow(rect, row); Grid.SetColumn(rect, column); rectCoords.Add(new Tuple <int, int>(column, row)); var brush = new ImageBrush(); brush.ImageSource = this.ImageSource; rect.Fill = brush; var transform = new CompositeTransform(); transform.TranslateX = -column; transform.ScaleX = Columns; transform.TranslateY = -row; transform.ScaleY = Rows; brush.RelativeTransform = transform; var projection = new PlaneProjection(); projection.CenterOfRotationY = 0; rect.Projection = projection; projs.Add(projection); _layoutGrid.Children.Add(rect); } } var indices = new List <int>(Rows * Columns); for (int i = 0; i < Rows * Columns; i++) { indices.Add(i); } if (direction == CascadeDirection.Shuffle) { indices = indices.Shuffle(); } for (int ii = 0; ii < indices.Count; ii++) { var i = indices[ii]; var projection = projs[i]; var rect = rects[i]; var column = rectCoords[ii].Item1; var row = rectCoords[ii].Item2; //Debug.WriteLine("i: {0}, p: {1}, rect: {2}, c: {3}, r: {4}", i, projection.GetHashCode(), rect.GetHashCode(), column, row); var rotationAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(rotationAnimation, projection); Storyboard.SetTargetProperty(rotationAnimation, "RotationX"); var endKeyTime = this.CascadeSequence == CascadeSequence.EndTogether ? TimeSpan.FromSeconds(totalDurationInSeconds) : TimeSpan.FromSeconds( (double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds + TileDuration.TotalSeconds); rotationAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 90 }); rotationAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 90 }); rotationAnimation.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 0 }); sb.Children.Add(rotationAnimation); var opacityAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(opacityAnimation, rect); Storyboard.SetTargetProperty(opacityAnimation, "Opacity"); opacityAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 0 }); opacityAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 0 }); opacityAnimation.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 1 }); sb.Children.Add(opacityAnimation); } sb.Begin(); }
public void Cascade() { RH = RW = double.NaN; if (!_isLoaded || _layoutGrid == null) { return; } if (Rows < 1) { Rows = 1; } if (Columns < 1) { Columns = 1; } _layoutGrid.Children.Clear(); _layoutGrid.RowDefinitions.Clear(); _layoutGrid.ColumnDefinitions.Clear(); for (int row = 0; row < Rows; row++) { _layoutGrid.RowDefinitions.Add(new RowDefinition()); } for (int column = 0; column < Columns; column++) { _layoutGrid.ColumnDefinitions.Add(new ColumnDefinition()); } var sb = new Storyboard(); var totalDurationInSeconds = RowDelay.TotalSeconds * (Rows - 1) + ColumnDelay.TotalSeconds * (Columns - 1) + TileDuration.TotalSeconds; CascadeDirection direction = this.CascadeDirection; if (direction == CascadeDirection.Random) { direction = (CascadeDirection)Random.Next((int)CascadeDirection.Random); } int startColumn; int exclusiveEndColumn; int columnIncrement; int startRow; int exclusiveEndRow; int rowIncrement; switch (direction) { case CascadeDirection.Shuffle: case CascadeDirection.TopLeft: startColumn = 0; exclusiveEndColumn = Columns; columnIncrement = 1; startRow = 0; exclusiveEndRow = Rows; rowIncrement = 1; break; case CascadeDirection.TopRight: startColumn = Columns - 1; exclusiveEndColumn = -1; columnIncrement = -1; startRow = 0; exclusiveEndRow = Rows; rowIncrement = 1; break; case CascadeDirection.BottomRight: startColumn = Columns - 1; exclusiveEndColumn = -1; columnIncrement = -1; startRow = Rows - 1; exclusiveEndRow = -1; rowIncrement = -1; break; case CascadeDirection.BottomLeft: startColumn = 0; exclusiveEndColumn = Columns; columnIncrement = 1; startRow = Rows - 1; exclusiveEndRow = -1; rowIncrement = -1; break; default: throw new InvalidOperationException(); } List <Tuple <int, int> > rectCoords = new List <Tuple <int, int> >(Rows * Columns); List <Rectangle> rects = new List <Rectangle>(Rows * Columns); //List<PlaneProjection> projs = new List<PlaneProjection>(Rows * Columns); //List<CompositeTransform> ct = new List<CompositeTransform>(Rows * Columns); //**********************开始的位置 /* * List<double> translateXInfo = new List<double>(); * List<double> translateYInfo = new List<double>(); */ for (int row = startRow; row != exclusiveEndRow; row = row + rowIncrement) { for (int column = startColumn; column != exclusiveEndColumn; column = column + columnIncrement) { var rect = new Rectangle(); rects.Add(rect); Grid.SetRow(rect, row); Grid.SetColumn(rect, column); rectCoords.Add(new Tuple <int, int>(column, row)); var brush = new ImageBrush(); brush.ImageSource = this.ImageSource; brush.Stretch = this.Stretch; rect.Fill = brush; //设置图片的笔刷位置 var transform = new CompositeTransform(); transform.TranslateX = -column; transform.ScaleX = Columns; transform.TranslateY = -row; transform.ScaleY = Rows; brush.RelativeTransform = transform; //设置填充图片笔刷矩形的透视投影 var projection = new PlaneProjection(); projection.CenterOfRotationY = 0; //projection.CenterOfRotationX = projection.CenterOfRotationZ = 0; //projection.GlobalOffsetX = column; //projection.GlobalOffsetY = row; rect.Projection = projection; //projs.Add(projection); //设置填充图片笔刷矩形的呈现位置 var rectTransform = new CompositeTransform(); //rectTransform.CenterX = rectTransform.CenterY = 0.5; rectTransform.TranslateX = column; rectTransform.TranslateY = row; rectTransform.Rotation = 0; rect.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5); rect.RenderTransform = rectTransform; //ct.Add(rectTransform); //if (!double.IsNaN(RH) && !double.IsNaN(RW)) //{ // rect.Margin = new Thickness(column * 52, row * 50, 0, 0); //} _layoutGrid.Children.Add(rect); } } //GetRHAndRW(); if (double.IsNaN(RH) || double.IsNaN(RW)) { rects[0].SizeChanged -= sizeChanged; rects[0].SizeChanged += sizeChanged = (ss, ee) => { this.RH = ee.NewSize.Height; this.RW = ee.NewSize.Width; var indices = new List <int>(Rows * Columns); for (int i = 0; i < Rows * Columns; i++) { indices.Add(i); var transform = rects[i].RenderTransform as CompositeTransform; transform.TranslateX = transform.TranslateX * RW; transform.TranslateY = transform.TranslateY * RH; //var transform = rects[i].Projection as PlaneProjection; //transform.GlobalOffsetX = transform.GlobalOffsetX * RW; //transform.GlobalOffsetY = transform.GlobalOffsetY * RH; /* * if (i < Rows * Columns / 2) * { * transform.TranslateX = -RW; * transform.TranslateY = -RH; * } * else * { * transform.TranslateX = RW; * transform.TranslateY = RH; * } * * translateXInfo.Add(transform.TranslateX); * translateYInfo.Add(transform.TranslateY); * System.Diagnostics.Debug.WriteLine("TX = " + transform.TranslateX + " TY = " + transform.TranslateY + "\n"); */ } if (direction == CascadeDirection.Shuffle) { indices = indices.Shuffle(); } for (int ii = 0; ii < indices.Count; ii++) { var i = indices[ii]; //var projection = projs[i]; var projection = rects[i].Projection; var rect = rects[i]; var column = rectCoords[ii].Item1; var row = rectCoords[ii].Item2; //*******************拿到当前的transform var transfrom = rect.RenderTransform as CompositeTransform; //Debug.WriteLine("i: {0}, p: {1}, rect: {2}, c: {3}, r: {4}", i, projection.GetHashCode(), rect.GetHashCode(), column, row); var rotationAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(rotationAnimation, projection); Storyboard.SetTargetProperty(rotationAnimation, "RotationX"); var endKeyTime = this.CascadeSequence == CascadeSequence.EndTogether ? TimeSpan.FromSeconds(totalDurationInSeconds) : TimeSpan.FromSeconds( (double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds + TileDuration.TotalSeconds); rotationAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 90 }); rotationAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 90 }); rotationAnimation.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 0 }); sb.Children.Add(rotationAnimation); //****************************y,z的效果可以研究下如何加比较好 var rotationAnimationY = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(rotationAnimationY, projection); Storyboard.SetTargetProperty(rotationAnimationY, "RotationY"); rotationAnimationY.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 180 }); rotationAnimationY.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 90 }); rotationAnimationY.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 0 }); sb.Children.Add(rotationAnimationY); var rotationAnimationZ = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(rotationAnimationZ, projection); Storyboard.SetTargetProperty(rotationAnimationZ, "RotationZ"); rotationAnimationZ.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 180 }); rotationAnimationZ.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 90 }); rotationAnimationZ.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 0 }); sb.Children.Add(rotationAnimationZ); //**************************** var opacityAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(opacityAnimation, rect); Storyboard.SetTargetProperty(opacityAnimation, "Opacity"); opacityAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 0 }); opacityAnimation.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 0 }); opacityAnimation.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 1 }); sb.Children.Add(opacityAnimation); //******************** 效果差不错出来了,主要是起始点的设置,还有,这里的动画要不要弄成关键祯? var translateXanimation = new DoubleAnimation(); /*translateXanimation.From = translateXInfo[i];*/ translateXanimation.From = transfrom.TranslateX; translateXanimation.To = 0; translateXanimation.Duration = endKeyTime; //translateXanimation.EasingFunction = CascadeInEasingFunction; //BackEase(缓动函数) BounceEase(弹跳效果) CircleEase(加速和/或减速) CubicEase( f(t) = t3 创建加速和/或减速) //ElasticEase(弹簧来回振动直到停止) ExponentialEase(指数公式创建加速和/或减速) PowerEase(f(t) = tp 创建加速和/或减速) //QuadraticEase(f(t) = t2 创建加速和/或减速) QuarticEase(f(t) = t4 创建加速和/或减速) QuinticEase(f(t) = t5 创建加速和/或减速) //SineEase(正弦方程式(见下面的备注)创建加速和/或减速) Storyboard.SetTarget(translateXanimation, transfrom); Storyboard.SetTargetProperty(translateXanimation, "TranslateX"); sb.Children.Add(translateXanimation); var translateYanimation = new DoubleAnimation(); /*translateYanimation.From = translateYInfo[i];*/ translateYanimation.From = transfrom.TranslateY; translateYanimation.To = 0; translateYanimation.Duration = endKeyTime; //translateYanimation.EasingFunction = CascadeInEasingFunction; Storyboard.SetTarget(translateYanimation, transfrom); Storyboard.SetTargetProperty(translateYanimation, "TranslateY"); sb.Children.Add(translateYanimation); //**************************** var globalOffsetY = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(globalOffsetY, projection); Storyboard.SetTargetProperty(globalOffsetY, "GlobalOffsetY"); globalOffsetY.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 180 }); globalOffsetY.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 90 }); globalOffsetY.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 0 }); //sb.Children.Add(globalOffsetY); var globalOffsetX = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(globalOffsetX, projection); Storyboard.SetTargetProperty(globalOffsetX, "GlobalOffsetX"); globalOffsetX.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 180 }); globalOffsetX.KeyFrames.Add( new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds), Value = 90 }); globalOffsetX.KeyFrames.Add( new EasingDoubleKeyFrame { KeyTime = endKeyTime, EasingFunction = CascadeInEasingFunction, Value = 0 }); //sb.Children.Add(globalOffsetX); } sb.Begin(); }; } }
public override void Begin(Action completionAction) { Storyboard = new Storyboard(); double liCounter = 0; var listBoxItems = ListBox.GetVisualDescendants().OfType <ListBoxItem>().Where(lbi => IsOnCurrentPage(lbi) && lbi.IsEnabled).ToList(); if (HoldSelectedItem && Direction == Directions.Out && ListBox.SelectedItem != null) { //move selected container to end var selectedContainer = ListBox.ItemContainerGenerator.ContainerFromItem(ListBox.SelectedItem); listBoxItems.Remove(selectedContainer); listBoxItems.Add(selectedContainer); } foreach (ListBoxItem li in listBoxItems) { GeneralTransform gt = li.TransformToVisual(RootElement); Point globalCoords = gt.Transform(new Point(0, 0)); double heightAdjustment = li.Content is FrameworkElement ? ((li.Content as FrameworkElement).ActualHeight / 2) : (li.ActualHeight / 2); //double yCoord = globalCoords.Y + ((((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(li)).Content)).ActualHeight) / 2); double yCoord = globalCoords.Y + heightAdjustment; double offsetAmount = (RootElement.ActualHeight / 2) - yCoord; PlaneProjection pp = new PlaneProjection(); pp.GlobalOffsetY = offsetAmount * -1; pp.CenterOfRotationX = 0; li.Projection = pp; CompositeTransform ct = new CompositeTransform(); ct.TranslateY = offsetAmount; li.RenderTransform = ct; var beginTime = TimeSpan.FromMilliseconds((FeatherDelay * liCounter) + InitialDelay); if (Direction == Directions.In) { li.Opacity = 0; DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame edkf1 = new EasingDoubleKeyFrame(); edkf1.KeyTime = beginTime; edkf1.Value = Angle; daukf.KeyFrames.Add(edkf1); EasingDoubleKeyFrame edkf2 = new EasingDoubleKeyFrame(); edkf2.KeyTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime); edkf2.Value = 0; ExponentialEase ee = new ExponentialEase(); ee.EasingMode = EasingMode.EaseOut; ee.Exponent = 6; edkf2.EasingFunction = ee; daukf.KeyFrames.Add(edkf2); Storyboard.SetTarget(daukf, li); Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")); Storyboard.Children.Add(daukf); DoubleAnimation da = new DoubleAnimation(); da.Duration = TimeSpan.FromMilliseconds(0); da.BeginTime = beginTime; da.To = 1; Storyboard.SetTarget(da, li); Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)")); Storyboard.Children.Add(da); } else { li.Opacity = 1; DoubleAnimation da = new DoubleAnimation(); da.BeginTime = beginTime; da.Duration = TimeSpan.FromMilliseconds(Duration); da.To = Angle; ExponentialEase ee = new ExponentialEase(); ee.EasingMode = EasingMode.EaseIn; ee.Exponent = 6; da.EasingFunction = ee; Storyboard.SetTarget(da, li); Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")); Storyboard.Children.Add(da); da = new DoubleAnimation(); da.Duration = TimeSpan.FromMilliseconds(10); da.To = 0; da.BeginTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime); Storyboard.SetTarget(da, li); Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)")); Storyboard.Children.Add(da); } liCounter++; } base.Begin(completionAction); }
private void OnTemplateChanged() { Vector2f position = this.Position; float angle = this.Angle; if(m_RootCircle != null) { m_RootCircle.PositionChanged -= this.HandleRootPositionChanged; m_RootCircle.AngleChanged -= this.HandleRootAngleChanged; } if(this.Template != null) { ShapeCircle templateRootCircle = this.Template.RootCircle; CompositeTransform compositeTransform = new CompositeTransform(); if(this.EditTemplateMode) { compositeTransform.InducedTransforms.Add(templateRootCircle.Transform); } else { compositeTransform.InducedTransforms.Add(templateRootCircle.Transform); compositeTransform.InducedTransforms.Add(new Transform()); } m_RootCircle = new ShapeCircle(this, compositeTransform, this.SceneView); m_Color = this.Template.Color; foreach(ShapeCircle templateChildCircle in templateRootCircle.Children) { CreateCircleFromTemplate(templateChildCircle, m_RootCircle); } m_SelectionManip = this.Template.GetSelectionManip(this); m_Manips = this.Template.GetManips(this); if(m_Manips == null) { m_Manips = new List<SpatialManip>(); } this.UserPropertiesFilepath = this.Template.PropertiesFilepath; } else { m_RootCircle = new ShapeCircle(this, new Transform(), this.SceneView); m_Color = Color.Black; m_Manips = new List<SpatialManip>(); } if(!this.EditTemplateMode) { this.Position = position; this.Angle = angle; } m_RootCircle.PositionChanged += this.HandleRootPositionChanged; m_RootCircle.AngleChanged += this.HandleRootAngleChanged; InvalidateView(); }
public static void SetCenterForCompositeTransform(UIElement target, CompositeTransform transform) { transform.CenterX = GetCenterX(target); transform.CenterY = GetCenterY(target); }
/// <summary> /// Attach方法就是当该Behavior被关联到某一元素时要执行的代码 /// </summary> /// <param name="ObjectInstance">元素对象的引用</param> public void Attach(DependencyObject ObjectInstance) { /// 获取关联的对象 AssociatedObject = ObjectInstance; if (ObjectInstance == null) { return; } var element = AssociatedObject as FrameworkElement; if (element == null) { return; } /// 添加CompositeTransform缩放支持 var CT = new CompositeTransform( ); element.RenderTransform = CT; CenterFrom = element.Width / 2; CenterTo = element.Width / 2; /// 设置动画关联对象 Storyboard.SetTarget(_scaleXAnim, element.RenderTransform); Storyboard.SetTargetProperty(_scaleXAnim, nameof(CompositeTransform.ScaleX)); Storyboard.SetTarget(_scaleYAnim, element.RenderTransform); Storyboard.SetTargetProperty(_scaleYAnim, nameof(CompositeTransform.ScaleY)); Storyboard.SetTarget(soliod_scaleXAnim, element.RenderTransform); Storyboard.SetTargetProperty(soliod_scaleXAnim, nameof(CompositeTransform.ScaleX)); Storyboard.SetTarget(soliod_scaleYAnim, element.RenderTransform); Storyboard.SetTargetProperty(soliod_scaleYAnim, nameof(CompositeTransform.ScaleY)); /// 设置控件动画中心 Storyboard.SetTarget(centerX, element.RenderTransform); Storyboard.SetTargetProperty(centerX, nameof(CompositeTransform.CenterX)); Storyboard.SetTarget(centerY, element.RenderTransform); Storyboard.SetTargetProperty(centerY, nameof(CompositeTransform.CenterY)); Storyboard.SetTarget(soliodcenterX, element.RenderTransform); Storyboard.SetTargetProperty(soliodcenterX, nameof(CompositeTransform.CenterX)); Storyboard.SetTarget(soliodcenterY, element.RenderTransform); Storyboard.SetTargetProperty(soliodcenterY, nameof(CompositeTransform.CenterY)); /// 将动画添加到故事版 storyboard.Children.Add(_scaleYAnim); storyboard.Children.Add(_scaleXAnim); storyboard.Children.Add(centerX); storyboard.Children.Add(centerY); InitSoliodStoryBoard( ); /// 关联事件 if (!AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Mobile")) { element.PointerEntered += Obj_PointerEntered; element.PointerExited += Obj_PointerExited; } if (element is Button) { (element as Button).Click += Obj_Click; } }
//init the control void initcontrols() { HorizontalAlignment = HorizontalAlignment.Left; VerticalAlignment = VerticalAlignment.Top; this.Width = _borderwidth; this.Height = _borderheight; this._transform = new CompositeTransform(); this.RenderTransform = this._transform; //init the border Color _bordercolor = new Border(); this._bordercolor.Width = _borderwidth; this._bordercolor.Height = _borderheight; _bordercolor.BorderThickness = new Thickness(10); _bordercolor.CornerRadius = new CornerRadius(4); _bordercolor.Background = new SolidColorBrush(ColorHelper.FromArgb(150, 112, 138, 144)); this.Children.Add(_bordercolor); this._itemgrid = new Grid(); this.Children.Add(_itemgrid); this._itemgrid.Height = _thumbheight; this._itemgrid.Width = _thumbwidth; this._thumbimage = new Image(); this._thumbimage.Height = _thumbheight; this._thumbimage.Width = _thumbwidth; this._thumbimage.Stretch = Stretch.Fill; this.Children.Add(_thumbimage); //for touch mainpualtions this.PointerPressed += StackItem_PointerPressed; this.PointerReleased += StackItem_PointerReleased; this.Tapped += StackItem_Tapped; //for text and description _textpanel = new StackPanel(); _textpanel.VerticalAlignment = VerticalAlignment.Center; _textpanel.HorizontalAlignment = HorizontalAlignment.Center; _textpanel.Orientation = Orientation.Vertical; _textpanel.Height = 160; _textpanel.Width = 140; _textpanel.Opacity = 0.0; _titletext = new TextBlock(); _titletext.Height = 40; _titletext.Width = 140; _titletext.FontSize = 16; _titletext.Text = "Nombre de Item"; _titletext.TextWrapping = TextWrapping.Wrap; _titletext.TextAlignment = TextAlignment.Center; _textpanel.Children.Add(_titletext); _descriptiontext = new TextBlock(); _descriptiontext.Height = 120; _descriptiontext.Width = 140; _descriptiontext.FontSize = 12; _descriptiontext.Text = "Descripcion del Item"; _descriptiontext.TextWrapping = TextWrapping.Wrap; _descriptiontext.TextAlignment = TextAlignment.Center; _textpanel.Children.Add(_descriptiontext); _texttransform = new CompositeTransform(); _textpanel.RenderTransform = _texttransform; // this.Children.Add(_textpanel); }
private static void AddEllipseToCanvas(InkAnalysisInkDrawing shape, Canvas drawingSurface) { Ellipse ellipse = new Ellipse(); ellipse.IsHitTestVisible = false; // Ellipses and circles are reported as four points // in clockwise orientation. // Points 0 and 2 are the extrema of one axis, // and points 1 and 3 are the extrema of the other axis. // See Ellipse.svg for a diagram. IReadOnlyList <Point> points = shape.Points; // Calculate the geometric center of the ellipse. var center = new Point((points[0].X + points[2].X) / 2.0, (points[0].Y + points[2].Y) / 2.0); // Calculate the length of one axis. ellipse.Width = Distance(points[0], points[2]); var compositeTransform = new CompositeTransform(); if (shape.DrawingKind == InkAnalysisDrawingKind.Circle) { ellipse.Height = ellipse.Width; } else { // Calculate the length of the other axis. ellipse.Height = Distance(points[1], points[3]); // Calculate the amount by which the ellipse has been rotated // by looking at the angle our "width" axis has been rotated. // Since the Y coordinate is inverted, this calculates the amount // by which the ellipse has been rotated clockwise. double rotationAngle = Math.Atan2(points[2].Y - points[0].Y, points[2].X - points[0].X); // Convert radians to degrees. compositeTransform.Rotation = rotationAngle * 180.0 / Math.PI; compositeTransform.CenterX = ellipse.Width / 2.0; compositeTransform.CenterY = ellipse.Height / 2.0; } compositeTransform.TranslateX = center.X - ellipse.Width / 2.0; compositeTransform.TranslateY = center.Y - ellipse.Height / 2.0; ellipse.RenderTransform = compositeTransform; var attributes = canvas.InkPresenter.CopyDefaultDrawingAttributes(); ellipse.Stroke = new SolidColorBrush(attributes.Color); ellipse.StrokeThickness = attributes.Size.Width; drawingSurface.Children.Add(ellipse); if (RecognitionOccured != null) { RecognitionOccured(null, new RecognitionEventArgs(ellipse) { Description = $"Ellipse centered at {center}" }); } }
/// <summary> /// Handle zoom by mouse wheel and touchpad /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) { // get keystates bool shift = (e.KeyModifiers & VirtualKeyModifiers.Shift) == VirtualKeyModifiers.Shift; bool ctrl = (e.KeyModifiers & VirtualKeyModifiers.Control) == VirtualKeyModifiers.Control; if (ctrl) { // handle rotation if (shift) { #region rotation /* * // store earlier manipulations * previousTransform.Matrix = transformGroup.Value; * System.Diagnostics.Debug.WriteLine($"Offset ({previousTransform.Matrix.OffsetX},{previousTransform.Matrix.OffsetY})"); * * // init * var delta = e.GetCurrentPoint(ManipulationElement).Properties.MouseWheelDelta; * * // init center * var center = previousTransform.TransformPoint(e.GetCurrentPoint(ManipulationElement).Position); * deltaTransform.CenterX = center.X; * deltaTransform.CenterY = center.Y; * * //var delta = PointerPoint.GetCurrentPoint(e.Pointer.PointerId).Properties.MouseWheelDelta; * //// With my mouse, delta is a multiple of 30. * //deltaTransform.CenterX = PointerPoint.GetCurrentPoint(e.Pointer.PointerId).Position.X; * //deltaTransform.CenterY = PointerPoint.GetCurrentPoint(e.Pointer.PointerId).Position.Y; * * // rotation * if (delta > 0) * { * deltaTransform.Rotation = -90.0; * System.Diagnostics.Debug.WriteLine($"delta > 0 -> {deltaTransform.Rotation}"); * } * else if (delta < 0) * { * deltaTransform.Rotation = 90.0; * System.Diagnostics.Debug.WriteLine($"dekta < 0 -> {deltaTransform.Rotation}"); * } */ #endregion } // handle scale else { // store existing transformation and to prepare new PointerPoint pointerPoint = e.GetCurrentPoint(this.ManipulationElement); Point center = StoreTransformationsAndGetCenter(pointerPoint.Position); // reset transformGroup.Children.RemoveAt(1); deltaTransform = new CompositeTransform(); transformGroup.Children.Add(deltaTransform); // get mouse wheel (touchpad) info double deltaScroll = pointerPoint.Properties.MouseWheelDelta * -1; deltaScroll = (deltaScroll > 0) ? 0.9 : 1.1; // handle zoom/scale deltaTransform.CenterX = center.X; deltaTransform.CenterY = center.Y; deltaTransform.ScaleX = deltaTransform.ScaleY = deltaScroll; ConstrainScale(); } } }
void Img_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e, CompositeTransform mytransform) { mytransform.TranslateX += e.Delta.Translation.X; mytransform.TranslateY += e.Delta.Translation.Y; }
void Imagenes3_Loaded(object sender, RoutedEventArgs e) { re = new Recursos(); re.reporducirSonido("/Sonidos/Voces/PintarPez.mp3"); dragTranslation = new CompositeTransform(); }
//更新视图 private void UpdateView() { if (ItemsSources != null) { int length = ItemsSources.Count; //初始化画布 Canvas.SetTop(ImageListSubCanvas, 0); ImageListSubCanvas.Children.Clear(); //循环向画布中添加图片 for (int i = 0; i < length; i++) { //初始化图片 TZPicItem TZPicItem = new TZPicItem { Width = 83, Height = 83 }; TZPicItem.PicImage.Source = ItemsSources[i]; TZPicItem.Tag = i; //设置图片位置 Canvas.SetTop(TZPicItem, i * TZPicItem.Height); //添加图片SelectionChanged事件 TZPicItem.SelectionChanged += (s, e) => { TZPicItem sender = s as TZPicItem; if (!sender.IsSelected) { return; } //更新当前选中图片索引 _selectedIndex = int.Parse(TZPicItem.Tag.ToString()); //让选中的图片移动到中间 // 计算要移动的位移 double offset = (double.Parse(TZPicItem.Tag.ToString()) + 0.5) * TZPicItem.ActualHeight - ImageListCanvas.ActualHeight / 2; offset = offset > 0 ? offset : 0; //动画移动 Storyboard moveStory = new Storyboard(); DoubleAnimation animation = new DoubleAnimation(); animation.To = -offset; animation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 300)); Storyboard.SetTarget(animation, ImageListSubCanvas); Storyboard.SetTargetProperty(animation, new PropertyPath("(Canvas.Top)")); moveStory.Children.Add(animation); moveStory.Begin(); //初始化变换 CompositeTransform trans = ShowImage.RenderTransform as CompositeTransform; trans.Rotation = _rotation = 0; //初始化图片大小 InitShowImageSize(); ShowImage.Source = TZPicItem.PicImage.Source; showImageStory.Begin(); }; //添加图片MouseLeftButtonUp事件 TZPicItem.MouseLeftButtonUp += (s, e) => { if (_selectedTZPicItem != null) { _selectedTZPicItem.IsSelected = false; } _selectedTZPicItem = TZPicItem; TZPicItem.IsSelected = true; TZPicItem.Cursor = Cursors.Hand; }; //把图片添加到画布中 ImageListSubCanvas.Children.Add(TZPicItem); //设置默认选中参数 if (length > 0) { _selectedIndex = 0; _selectedTZPicItem = (ImageListSubCanvas.Children[0] as TZPicItem); _selectedTZPicItem.IsSelected = true; } } } }
/* * 按下时的事件处理,两个步骤 * 1、首先判断当前按下去的位置在控件的那个区域(控件共分为9个区域,详见PressPointLocation定义) * 2、根据按下去的位置,对控件做不同的效果 */ protected override void OnPointerPressed(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { // 获得当前区域位置 PressPointLocation location = GetPointLocation(e.GetCurrentPoint(this).Position); // 开始对控件做效果处理 if (location == (PressPointLocation.Left | PressPointLocation.YCenter)) {// 左中 projection.RotationY = angle; projection.CenterOfRotationX = 1; } else if (location == (PressPointLocation.Left | PressPointLocation.Top)) {// 左上 projection.RotationX = -angle; projection.RotationY = angle; projection.CenterOfRotationX = 1; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.Top | PressPointLocation.XCenter)) {// 上中 projection.RotationX = -angle * 2; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.Right | PressPointLocation.Top)) {// 右上 projection.RotationY = projection.RotationX = -angle; projection.CenterOfRotationX = 0; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.Right | PressPointLocation.YCenter)) {// 右中 projection.RotationY = -angle; projection.CenterOfRotationX = 0; } else if (location == (PressPointLocation.Right | PressPointLocation.Bottom)) {// 右下 projection.RotationX = angle; projection.RotationY = -angle; projection.CenterOfRotationX = 0; projection.CenterOfRotationY = 0; } else if (location == (PressPointLocation.Bottom | PressPointLocation.XCenter)) {// 下中 projection.RotationX = angle * 2; projection.CenterOfRotationY = 0; } else if (location == (PressPointLocation.Left | PressPointLocation.Bottom)) {// 左下 projection.RotationY = projection.RotationX = angle; projection.CenterOfRotationX = 1; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.XCenter | PressPointLocation.YCenter)) {// 正中 CompositeTransform transform = RenderTransform as CompositeTransform; transform.CenterX = ActualWidth / 2; transform.CenterY = ActualHeight / 2; transform.ScaleX = 0.9; transform.ScaleY = 0.9; } }
public List <Task <object> > AnimateScore(PlayerType type, int scoreDelta) { List <Task <object> > taskList = new List <Task <object> >(); PegControl backPeg = null; List <Ellipse> holeList = null; int newScore = -1; if (type == PlayerType.Player) { holeList = _playerHoles; if (_playerPegScore1.Score > _playerPegScore2.Score) { backPeg = _playerPegScore2; newScore = _playerPegScore1.Score + scoreDelta; } else { backPeg = _playerPegScore1; newScore = _playerPegScore2.Score + scoreDelta; } } else { holeList = _computerHoles; if (_computerPegScore1.Score > _computerPegScore2.Score) { backPeg = _computerPegScore2; newScore = _computerPegScore1.Score + scoreDelta; } else { backPeg = _computerPegScore1; newScore = _computerPegScore2.Score + scoreDelta; } } int animateScore = newScore; if (newScore > 121) { animateScore = 121; } double ms = 50; if (MainPage.AnimationSpeeds != null) { ms = MainPage.AnimationSpeeds.Medium / 10; } Duration rotateDuration = TimeSpan.FromMilliseconds(ms * (animateScore - backPeg.Score)); Duration durationTo120 = TimeSpan.FromMilliseconds(ms * (120 - backPeg.Score)); TimeSpan durationZero = TimeSpan.FromMilliseconds(0); backPeg.Score = newScore; DoubleAnimation animateRotate = backPeg.MovePegStoryBoard.Children[0] as DoubleAnimation; DoubleAnimation animateTranslateX = backPeg.MovePegStoryBoard.Children[1] as DoubleAnimation; DoubleAnimation animateCenterX = backPeg.MovePegStoryBoard.Children[2] as DoubleAnimation; Ellipse ellipse = GetEllipseForScore(holeList, animateScore); CompositeTransform compositeTransform = ellipse.RenderTransform as CompositeTransform; animateRotate.To = compositeTransform.Rotation; animateTranslateX.To = compositeTransform.TranslateX; animateCenterX.To = compositeTransform.CenterX; animateCenterX.Duration = TimeSpan.FromMilliseconds(0); animateTranslateX.Duration = TimeSpan.FromMilliseconds(0); if (newScore <= 120) { animateRotate.Duration = rotateDuration; animateCenterX.BeginTime = durationZero; animateTranslateX.BeginTime = durationZero; animateCenterX.Duration = durationZero; animateTranslateX.Duration = durationZero; } else { animateCenterX.BeginTime = durationTo120.TimeSpan; animateTranslateX.BeginTime = durationTo120.TimeSpan; Duration durationToWin = TimeSpan.FromMilliseconds(ms); animateCenterX.Duration = durationToWin; animateTranslateX.Duration = durationToWin; } taskList.Add(backPeg.MovePegStoryBoard.ToTask()); return(taskList); }
/// <summary> /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class. /// </summary> protected override void OnApplyTemplate() { base.OnApplyTemplate(); _transitionTransform = GetTemplateChild(TransitionTransformPartName) as CompositeTransform; _layoutRoot = GetTemplateChild(LayoutRootPartName) as FrameworkElement; if (_layoutRoot == null) { return; } var visualStateGroups = VisualStateManager.GetVisualStateGroups(_layoutRoot); if (visualStateGroups == null) { return; } var floatingStatesGroup = visualStateGroups.FirstOrDefault(group => group.Name == FloatingStatesGroupName); if (floatingStatesGroup == null) { return; } var floatingVisibleState = floatingStatesGroup.States.FirstOrDefault( state => state.Name == FloatingVisibleStateName); if (floatingVisibleState != null && floatingVisibleState.Storyboard != null) { _floatingVisibleHorizontalTransition = floatingVisibleState.Storyboard.Children.FirstOrDefault( timeline => Storyboard.GetTargetName(timeline) == TransitionTransformPartName && Storyboard.GetTargetProperty(timeline) == "TranslateX") as DoubleAnimation; _floatingVisibleVerticalTransition = floatingVisibleState.Storyboard.Children.FirstOrDefault( timeline => Storyboard.GetTargetName(timeline) == TransitionTransformPartName && Storyboard.GetTargetProperty(timeline) == "TranslateY") as DoubleAnimation; } var floatingHiddenState = floatingStatesGroup.States.FirstOrDefault( state => state.Name == FloatingHiddenStateName); if (floatingHiddenState != null && floatingHiddenState.Storyboard != null) { _floatingHiddenHorizontalTransition = floatingHiddenState.Storyboard.Children.FirstOrDefault( timeline => Storyboard.GetTargetName(timeline) == TransitionTransformPartName && Storyboard.GetTargetProperty(timeline) == "TranslateX") as DoubleAnimation; _floatingHiddenVerticalTransition = floatingHiddenState.Storyboard.Children.FirstOrDefault( timeline => Storyboard.GetTargetName(timeline) == TransitionTransformPartName && Storyboard.GetTargetProperty(timeline) == "TranslateY") as DoubleAnimation; } //this.FloatingVisibleHorizontalTransition = GetTemplateChild(FloatingVisibleHorizontalTransitionPartName) as DoubleAnimation; //this.FloatingVisibleVerticalTransition = GetTemplateChild(FloatingVisibleVerticalTransitionPartName) as DoubleAnimation; //this.FloatingHiddenHorizontalTransition = GetTemplateChild(FloatingVisibleHorizontalTransitionPartName) as DoubleAnimation; //this.FloatingHiddenVerticalTransition = GetTemplateChild(FloatingVisibleVerticalTransitionPartName) as DoubleAnimation; if (IsOpen) { OnOpenedInternal(false); } else { OnClosedInternal(false); } }
public XamlAnimationBuilder([NotNull] UIElement target) : base(target) { TargetTransform = target.GetTransform <CompositeTransform>(false); target.RenderTransformOrigin = new Point(0.5, 0.5); }
public Figura(CompositeTransform dinamica, CompositeTransform estatica) { this.dinamica = dinamica; this.estatica = estatica; }
void OnManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { _panAreaTransform = PanArea.GetCompositeTransform(); _paneRootTransform = PaneRoot.GetCompositeTransform(); }
private async Task CalculatePositionsAsync() { await this.WaitForLayoutUpdateAsync(); if (Items.Count == 0) { return; } double width = this.Width; if (double.IsNaN(width)) { width = this.ActualWidth; } double height = this.Height; if (double.IsNaN(height)) { height = ActualHeight; } double itemWidth = GetFrameworkElementFromItem(0).ActualWidth; double itemHeight = GetFrameworkElementFromItem(0).ActualHeight; double distanceX = width / Items.Count; double distanceY = height / Items.Count; double startX = 0.0, startY = 0.0; switch (Orientation) { case DiagonalPanelOrientation.TopLeftToBottomRight: startX = 0.0; startY = 0.0; distanceX *= 1; distanceY *= 1; break; case DiagonalPanelOrientation.TopRightToBottomLeft: startX = width - itemWidth; startY = 0.0; distanceX *= -1; distanceY *= 1; break; case DiagonalPanelOrientation.BottomLeftToTopRight: startX = 0.0; startY = height - itemHeight; distanceX *= 1; distanceY *= -1; break; case DiagonalPanelOrientation.BottomRightToTopLeft: startX = width - itemWidth; startY = height - itemHeight; distanceX *= -1; distanceY *= -1; break; default: break; } for (int i = 0; i < this.Items.Count; i++) { FrameworkElement fe = GetFrameworkElementFromItem(i); fe.RenderTransformOrigin = new Point(0.5, 0.5); fe.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left; fe.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top; fe.RenderTransform = new CompositeTransform(); CompositeTransform ct = fe.RenderTransform as CompositeTransform; ct.TranslateX = i * distanceX + startX; ct.TranslateY = i * distanceY + startY; } }
protected CompositeTransform GetTransform(FrameworkElement element) { var transform = element.RenderTransform as CompositeTransform; if (transform == null) element.RenderTransform = transform = new CompositeTransform(); return transform; }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { recurso.reporducirSonido("/Sonidos/Voces/MezclarColorCeleste.mp3"); dragTranslation = new CompositeTransform(); }
private void CreateCircleFromTemplate(ShapeCircle templateCircle, ShapeCircle parent) { ITransform transform = templateCircle.Transform; if(!this.EditTemplateMode) { CompositeTransform compositeTransform = new CompositeTransform(); compositeTransform.InducedTransforms.Add(templateCircle.Transform); compositeTransform.InducedTransforms.Add(new Transform()); transform = compositeTransform; } ShapeCircle circle = null; if(parent != null) { circle = new ShapeCircle(parent, transform); } else { circle = new ShapeCircle(this, transform, this.SceneView); } foreach(ShapeCircle templateChildCircle in templateCircle.Children) { CreateCircleFromTemplate(templateChildCircle, circle); } }
/// <summary> /// Occurs when the value of the <see cref="Attitude"/> property has changed. /// </summary> /// <param name="e"> /// A <see cref="DependencyPropertyChangedEventArgs"/> containing event information. /// </param> protected override void OnAttitudeChanged(DependencyPropertyChangedEventArgs e) { base.OnAttitudeChanged(e); // Ensure that the viewport has been created EnsureViewport(); // Get the RotationMatrix from the MotionReading. // Rotate it 90 degrees around the X axis to put it in the XNA Framework coordinate system. Matrix xnaAttitude = Matrix.CreateRotationX(MathHelper.PiOver2) * Attitude; // Loop through our items for (int i = 0; i < Items.Count; i++) { // Get the WorldVIewItem that matches the index WorldViewItem wvItem = ItemContainerGenerator.ContainerFromIndex(i) as WorldViewItem; // If we couldn't get a WorldViewItem for the index, skip if (wvItem == null) { continue; } // Get the ARItem that the WorldViewItem represents ARItem arItem = (ARItem)wvItem.DataContext; // Create a World matrix for the ARItems WorldLocation Matrix world = Matrix.CreateWorld(arItem.WorldLocation, new Vector3(0, 0, 1), new Vector3(0, 1, 0)); // Use Viewport.Project to project the ARItems location in 3D space into screen coordinates Vector3 projected = viewport.Project(Vector3.Zero, projection, view, world * xnaAttitude); // If the point is outside of this range, it is behind the camera if (projected.Z > 1 || projected.Z < 0) { // Out of range, just hide wvItem.Visibility = Visibility.Collapsed; } else { // In range so show wvItem.Visibility = Visibility.Visible; /* * // Create a TranslateTransform to position the WorldViewItem * TranslateTransform tt = new TranslateTransform(); * * // Offset by half of the WorldViewItems size to center it on the point * tt.X = projected.X - (wvItem.ActualWidth / 2); * tt.Y = projected.Y - (wvItem.ActualHeight / 2); * * // Set the transform, which moves the item * wvItem.RenderTransform = tt; */ // Create a CompositeTransform to position and scale the WorldViewItem CompositeTransform ct = new CompositeTransform(); // Offset by half of the WorldViewItems size to center it on the point // TODO: Expose vertical limit property #if WIN_RT ct.TranslateX = projected.X - (wvItem.ActualWidth / 2) - (this.ActualWidth / 2); // Ricky; Keep the y value within the screen double y = projected.Y - (wvItem.ActualHeight / 2); double h2 = this.Height / 2; y = (y < -h2) ? -h2 : ((y > h2) ? h2 : y); ct.TranslateY = y; #endif #if WINDOWS_PHONE ct.TranslateX = projected.X - (wvItem.ActualWidth / 2); ct.TranslateY = projected.Y - (wvItem.ActualHeight / 2); #endif #if WP7 double scale = MathHelper.Lerp((float)MinItemScale, (float)MaxItemScale, ((float)FarClippingPlane - Math.Abs(arItem.WorldLocation.Z)) / (float)FarClippingPlane); #else double scale = MathHelper.Lerp(MinItemScale, MaxItemScale, (FarClippingPlane - Math.Abs(arItem.WorldLocation.Z)) / FarClippingPlane); #endif ct.ScaleX = scale; ct.ScaleY = scale; // Set the transform, which moves the item wvItem.RenderTransform = ct; // Set the items z-index so that the closest item is always rendered on top Canvas.SetZIndex(wvItem, (int)(scale * 255)); } } }
private static void RenderElement(Canvas parent, CompositeTransform textRotation, ElementDescription element) { switch (element.Type) { case ElementType.Circle: Ellipse e = new Ellipse() { Width = element.Width, Height = element.Height, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; parent.Children.Add(e); Canvas.SetLeft(e, element.CenterX); Canvas.SetTop(e, element.CenterY); break; case ElementType.Path: Path path = new Path() { Data = ProcessPathData(element.Path), Tag = element.Text, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; parent.Children.Add(path); break; case ElementType.Text: Grid g = new Grid() { Width = 200, Height = 200 }; parent.Children.Add(g); Canvas.SetLeft(g, element.CenterX - g.Width / 2); Canvas.SetTop(g, element.CenterY - g.Height / 2); TextBlock tb = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, RenderTransform = textRotation, Foreground = BrushForColor(element.Stroke), FontSize = element.FontSize, Text = element.Text, }; g.Children.Add(tb); break; default: throw new InvalidOperationException("Unexpected node: " + element.Type); } }
/// <summary> /// Initializes the transforms. /// </summary> private void InitTransforms() { this.transform = new CompositeTransform(); this.RenderTransformOrigin = new Point(0.5, 0.5); this.Thumb.RenderTransform = this.transform; }