public Rectangle(double x, double y, double w, double h) { RectangleSurface rectangle = new RectangleSurface(x, y, w, h); _visual = new Visual(rectangle, Visual.Family.Rectangle, null); Born(); }
public VisualTree3DView(Visual visual) { DirectionalLight directionalLight1 = new DirectionalLight(Colors.White, new Vector3D(0, 0, 1)); DirectionalLight directionalLight2 = new DirectionalLight(Colors.White, new Vector3D(0, 0, -1)); double z = 0; Model3D model = this.ConvertVisualToModel3D(visual, ref z); Model3DGroup group = new Model3DGroup(); group.Children.Add(directionalLight1); group.Children.Add(directionalLight2); group.Children.Add(model); this.zScaleTransform = new ScaleTransform3D(); group.Transform = this.zScaleTransform; ModelVisual3D modelVisual = new ModelVisual3D(); modelVisual.Content = group; Rect3D bounds = model.Bounds; double fieldOfView = 45; Point3D lookAtPoint = new Point3D(bounds.X + bounds.SizeX / 2, bounds.Y + bounds.SizeY / 2, bounds.Z + bounds.SizeZ / 2); double cameraDistance = 0.5 * bounds.SizeX / Math.Tan(0.5 * fieldOfView * Math.PI / 180); Point3D position = lookAtPoint - new Vector3D(0, 0, cameraDistance); Camera camera = new PerspectiveCamera(position, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), fieldOfView); this.zScaleTransform.CenterZ = lookAtPoint.Z; this.Children.Add(modelVisual); this.Camera = camera; this.ClipToBounds = false; this.Width = 500; this.Height = 500; this.trackballBehavior = new TrackballBehavior(this, lookAtPoint); }
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Get backing visual from shadow container and interop compositor _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer); _compositor = _shadowContainer.Compositor; // Get CompositionImage, its sprite visual _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer); _imageVisual = _image.SpriteVisual; // Load mask asset onto surface using helpers in SamplesCommon _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White); // Create surface brush for mask CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush(); mask.Surface = _imageMaskSurface.Surface; // Get surface brush from composition image CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush; // Create mask brush for toggle mask functionality _maskBrush = _compositor.CreateMaskBrush(); _maskBrush.Mask = mask; _maskBrush.Source = source; // Initialize toggle mask _isMaskEnabled = false; }
private BitmapSource CreateBitmapFromVisuals(Visual target, FrameworkElement cursor) { Rect bounds = VisualTreeHelper.GetDescendantBounds(target); RenderTargetBitmap renderBitmap = new RenderTargetBitmap(800, 600, 96, 96, PixelFormats.Pbgra32); DrawingVisual dv = new DrawingVisual(); using (DrawingContext ctx = dv.RenderOpen()) { VisualBrush vb = new VisualBrush(target); VisualBrush vbCursor = new VisualBrush(cursor); // For linear gradient over ghost image. ////LinearGradientBrush opacityMask = new LinearGradientBrush(Color.FromArgb(255, 1, 1, 1), Color.FromArgb(0, 1, 1, 1), 30); ////ctx.PushOpacityMask(opacityMask); vb.Opacity = _opacity; Rect scaledBounds = new Rect(bounds.Location, new Size(bounds.Width * _scaleX, bounds.Height * _scaleY)); ctx.DrawRectangle(vbCursor, null, new Rect(0, 0, cursor.ActualWidth, cursor.ActualHeight)); ctx.DrawRectangle(vb, null, new Rect(new Point(cursor.ActualWidth, cursor.ActualHeight), scaledBounds.Size)); ////ctx.Pop(); } renderBitmap.Render(dv); return renderBitmap; }
public Circle(double x, double y, double r) { CircleSurface circle = new CircleSurface(x, y, r); _visual = new Visual(circle, Visual.Family.Circle, null); Born(); }
// called for each visible tile protected override void UpdateTile(Visual _tile, IntPoint ml) { MapControlTile2 tile = (MapControlTile2)_tile; BitmapSource bmp; if (m_map.Bounds.Contains(ml)) { byte b = m_map.MapArray[ml.Y, ml.X]; if (b < 100) bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Wall, Colors.Black, false); else bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Floor, Colors.Black, false); } else { bmp = null; } if (bmp != tile.Bitmap) { tile.Bitmap = bmp; tile.Update(); } }
public static IEnumerable<Visual> GetChildren(Visual parent, bool recurse = true) { if (parent != null) { int count = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < count; i++) { // Retrieve child visual at specified index value. var child = VisualTreeHelper.GetChild(parent, i) as Visual; if (child != null) { yield return child; if (recurse) { foreach (var grandChild in GetChildren(child, true)) { yield return grandChild; } } } } } }
public void DeleteVisual(Visual visual) { visuals.Remove(visual); base.RemoveVisualChild(visual); base.RemoveLogicalChild(visual); }
public static string Take(Visual visual, System.Windows.Size size, double dpi = 96) { UIElement uiElement = visual as UIElement; if (uiElement == null) return null; PresentationSource source = PresentationSource.FromVisual(visual); double dpiX = 96; double dpiY = 96; if (source != null) { dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11; dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22; } int width = (int)(size.Width * dpi / 96.0); int height = (int)(size.Height * dpi / 96.0); // Render var bmp = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Pbgra32); bmp.Render(visual); // Encode and save to PNG file var enc = new PngBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(bmp)); string path = Utils.ScreenshotPathName(); using (var stm = File.Create(path)) enc.Save(stm); return path; }
public void Parallax_Expression() { _compositor = new Compositor(); _root = ElementCompositionPreview.GetElementVisual(Container); _compositor = _root.Compositor; // Create the Blue Square var blueSquareVisual = _compositor.CreateSpriteVisual(); blueSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Blue); blueSquareVisual.Size = new System.Numerics.Vector2(100.0f, 100.0f); blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f); // Create the Green Square var greenSquareVisual = _compositor.CreateSpriteVisual(); greenSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Green); greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f); greenSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f); // Add the Blue and Green square visuals to the tree ContainerVisual mainContainer = _compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(Container, mainContainer); mainContainer.Children.InsertAtTop(blueSquareVisual); mainContainer.Children.InsertAtTop(greenSquareVisual); _foreground = greenSquareVisual; _background = blueSquareVisual; }
public void SetupVisuals() { // Intialize the Compositor _compositor = new Compositor(); _root = (ContainerVisual)ElementCompositionPreview.GetContainerVisual(Container); _compositor = _root.Compositor; // Create the Blue Square var blueSquareVisual = _compositor.CreateSolidColorVisual(); blueSquareVisual.Color = Colors.Blue; blueSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f); blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f); // Create the Green Square with 20% opacity var greenSquareVisual = _compositor.CreateSolidColorVisual(); greenSquareVisual.Color = Colors.Green; greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f); greenSquareVisual.Offset = new Vector3(150.00f, 100.00f, 0.00f); greenSquareVisual.Opacity = 0.20f; // Add the Visuals to the tree _root.Children.InsertAtTop(greenSquareVisual); _root.Children.InsertAtTop(blueSquareVisual); _source = greenSquareVisual; _target = blueSquareVisual; }
// Walks up the tree starting at the bottomMostVisual, until it finds the first item container for the ItemsControl // passed as a parameter. // In order to make sure it works with any control that derives from ItemsControl, this method makes no assumption // about the type of that container.(it will get a ListBoxItem if it's a ListBox, a ListViewItem if it's a ListView...) public static FrameworkElement GetItemContainer(ItemsControl itemsControl, Visual bottomMostVisual) { FrameworkElement itemContainer = null; if (itemsControl != null && bottomMostVisual != null && itemsControl.Items.Count >= 1) { var someContainer = itemsControl.ItemContainerGenerator.ContainerFromIndex(0); for (int i = 1; i < itemsControl.Items.Count; i++) { if (someContainer != null) { break; } someContainer = itemsControl.ItemContainerGenerator.ContainerFromIndex(i); } if (someContainer != null) { Type containerType = someContainer.GetType(); itemContainer = FindAncestor(containerType, bottomMostVisual); // Make sure that the container found belongs to the items control passed as a parameter. if (itemContainer != null && itemContainer.DataContext != null) { FrameworkElement itemContainerVerify = itemsControl.ItemContainerGenerator.ContainerFromItem(itemContainer.DataContext) as FrameworkElement; if (itemContainer != itemContainerVerify) { itemContainer = null; } } } } return itemContainer; }
public static Visual GetDescendantByType(Visual element, Type type) { if (element == null) { return null; } if (element.GetType() == type) { return element; } Visual descendantByType = null; if (element is FrameworkElement) { (element as FrameworkElement).ApplyTemplate(); } for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++) { Visual child = VisualTreeHelper.GetChild(element, i) as Visual; descendantByType = GetDescendantByType(child, type); if (descendantByType != null) { return descendantByType; } } return descendantByType; }
void Awake () { visual = transform.Find ("Visual").GetComponent <Visual> (); transitable.Add (CharacterState.Spawn, new List<CharacterState> { CharacterState.Idle }); transitable.Add (CharacterState.Idle, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Move, CharacterState.Stuck }); transitable.Add (CharacterState.Attack, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Idle, CharacterState.Stuck }); transitable.Add (CharacterState.Move, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Idle, CharacterState.Move, CharacterState.Stuck }); transitable.Add (CharacterState.Stuck, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Idle, CharacterState.Move }); transitable.Add (CharacterState.Dead, new List<CharacterState> { }); controllable = true; stateMachine.Add (CharacterState.Idle, () => { CheckBlock (); }); stateMachine.Add (CharacterState.Move, () => { transform.position += dir * moveSpeed * Time.deltaTime; CheckBlock (); }); stateEnd.Add (CharacterState.Move, () => { dir = Vector3.zero; }); stateStart.Add (CharacterState.Attack, () => { blurController.SetBlurs (true); weapon.enabled = true; trailController.gameObject.SetActive (true); }); stateMachine.Add (CharacterState.Attack, () => { float t = (Time.time - attackStartTime) / attackDuration; t = Mathf.Clamp01 (t); if (t >= 1f) { transform.position = attackEndPoint; RequestChangeState (CharacterState.Idle); return; } t *= 2f; var diff = attackEndPoint - attackStartPoint; if (t < 1) { transform.position = diff * 0.5f * t * t + attackStartPoint; } else { t--; transform.position = -diff * 0.5f * (t * (t - 2f) - 1f) + attackStartPoint; } CheckBlock (); }); stateEnd.Add (CharacterState.Attack, () => { blurController.SetBlurs (false); visual.StopAnimation (); dir = Vector3.zero; attackStartPoint = Vector3.zero; attackEndPoint = Vector3.zero; weapon.enabled = false; trailController.gameObject.SetActive (false); }); stateStart.Add (CharacterState.Dead, () => { controllable = false; }); }
private ContainerVisual CreatePageVisual(IBlankPage blankPage, Visual contentVisual) { var newPage = new ContainerVisual(); newPage.Children.Add(blankPage.PageVisual); newPage.Children.Add(TransformVisualToBox(contentVisual, blankPage.DataContentBox)); return newPage; }
/// <summary> /// Sets the CenterPoint of a visual to the center of a given FrameworkElement /// </summary> /// <param name="element">The source element</param> /// <param name="visual">The Visual object for the source FrameworkElement</param> private static async Task SetCenterPoint(this FrameworkElement element, Visual visual) { Func<bool> loadedTester = () => element.ActualWidth + element.ActualHeight < 0.1; if (loadedTester()) { // Wait for the loaded event and set the CenterPoint TaskCompletionSource<object> loadedTcs = new TaskCompletionSource<object>(); RoutedEventHandler handler = null; handler = (s, e) => { loadedTcs.SetResult(null); element.Loaded -= handler; }; element.Loaded += handler; await Task.WhenAny(loadedTcs.Task, Task.Delay(500)); element.Loaded -= handler; if (loadedTester()) { element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); visual.CenterPoint = new Vector3((float)element.DesiredSize.Width / 2, (float)element.DesiredSize.Height / 2, 0); return; } } visual.CenterPoint = new Vector3((float)element.ActualWidth / 2, (float)element.ActualHeight / 2, 0); }
//------------------------------------------------------------------------------- // // Public Methods // //------------------------------------------------------------------------------- #region Public Methods /// <summary> /// AttachVisual method /// </summary> /// <param name="visual">The stroke visual which needs to be attached</param> /// <param name="drawingAttributes">The DrawingAttributes of the stroke</param> public void AttachVisuals(Visual visual, DrawingAttributes drawingAttributes) { VerifyAccess(); EnsureRootVisual(); _renderer.AttachIncrementalRendering(visual, drawingAttributes); }
public Line(double x1, double y1, double x2, double y2) { LineSurface line = new LineSurface(x1, y1, x2, y2); _visual = new Visual(line, Visual.Family.Line, null); Born(); }
private static Point TransformFromDevice(this Point point, Visual visual) { var compositionTarget = PresentationSource.FromVisual(visual)?.CompositionTarget; if (compositionTarget == null) throw new InvalidOperationException("Invalid visual"); var matrix = compositionTarget.TransformFromDevice; return new Point(point.X * matrix.M11, point.Y * matrix.M22); }
internal static Rect ElementToRoot(Rect rectElement, Visual element, PresentationSource presentationSource) { GeneralTransform transformElementToRoot = element.TransformToAncestor(presentationSource.RootVisual); Rect rectRoot = transformElementToRoot.TransformBounds(rectElement); return rectRoot; }
public static Visual GetDescendantByType(Visual element, Type type) { if (element != null) { if (element.GetType() != type) { Visual foundElement = null; if (element is FrameworkElement) { (element as FrameworkElement).ApplyTemplate(); } for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++) { Visual visual = VisualTreeHelper.GetChild(element, i) as Visual; foundElement = GetDescendantByType(visual, type); if (foundElement != null) { break; } } return foundElement; } return element; } return null; }
public static Screen GetScreenFrom(Visual v) { var w = Window.GetWindow(v); if (w == null) return null; return GetScreenFrom(w); }
public bool IsPointInsideOverlay(Point pos, Visual root) { var bounds = GetOverlayBounds(root); return pos.X >= bounds.X && pos.X <= bounds.X + bounds.Width && pos.Y >= bounds.Y && pos.Y <= bounds.Y + bounds.Height; }
public BackDrop() { m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); Compositor = m_rootVisual.Compositor; m_blurVisual = Compositor.CreateSpriteVisual(); #if SDKVERSION_INSIDER m_noiseBrush = Compositor.CreateSurfaceBrush(); CompositionEffectBrush brush = BuildBlurBrush(); brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); m_blurBrush = brush; m_blurVisual.Brush = m_blurBrush; BlurAmount = 9; TintColor = Colors.Transparent; #else m_blurBrush = Compositor.CreateColorBrush(Colors.White); m_blurVisual.Brush = m_blurBrush; #endif ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual); this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
public static double TransformToDeviceY(Visual visual, double y) { var source = PresentationSource.FromVisual(visual); if (source?.CompositionTarget != null) return y * source.CompositionTarget.TransformToDevice.M22; return TransformToDeviceY(y); }
public static double TransformToDeviceX(Visual visual, double x) { var source = PresentationSource.FromVisual(visual); if (source?.CompositionTarget != null) return x * source.CompositionTarget.TransformToDevice.M11; return TransformToDeviceX(x); }
public BehaviorBase(GameObject owner) { _owner = owner; _selectedBehavior = _owner.GetComponent<SelectedBehavior>(); _visual = _owner.GetComponent<Visual>(); _behaviors = _owner.GetComponent<Behaviors>(); }
public int AddElement(Visual element) { if (element != null && !m_elements.Contains(element)) { return m_elements.Add(element); } return -1; }
public static void DisableOnionEffect(Visual visual) { // apply to surfaces only if (visual.family != Visual.Family.Line && visual.family != Visual.Family.Circle && visual.family != Visual.Family.Rectangle) return; visual.content.Opacity = 1.0; int count = visual.content.Children.Count; bool firstLine = true; for (int i = 0; i < count; i++) { if (visual.content.Children[i] is System.Windows.Shapes.Rectangle) { System.Windows.Shapes.Rectangle rect = visual.content.Children[i] as System.Windows.Shapes.Rectangle; rect.Fill = Brushes.Gray; } if (visual.content.Children[i] is System.Windows.Shapes.Ellipse) { System.Windows.Shapes.Ellipse circle = visual.content.Children[i] as System.Windows.Shapes.Ellipse; circle.Fill = Brushes.Gray; } if (visual.content.Children[i] is System.Windows.Shapes.Line) { System.Windows.Shapes.Line line = visual.content.Children[i] as System.Windows.Shapes.Line; if (firstLine) line.Stroke = Brushes.Gray; else { line.Visibility = Visibility.Collapsed; } firstLine = false; } } }
public void AddVisual(Visual visual) { visuals.Add(visual); base.AddVisualChild(visual); base.AddLogicalChild(visual); }
public static Point TransformToDeviceDpi(this Visual visual, Point pt) { Matrix m = PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice; return(new Point(pt.X / m.M11, pt.Y / m.M22)); }
public static Point PointToScreenDpi(this Visual visual, Point pt) { Point resultPt = visual.PointToScreen(pt); return(TransformToDeviceDpi(visual, resultPt)); }
private void Handle(Player player, TankPacket packet, World world) { bool send = true; packet.NetId = player.NetId; switch (packet.Type) { case 0x0: { send = OnMoving(player, packet); break; } case 0x3: { send = packet.Tile switch { 18 => OnPunching(packet, world), 32 => OnWrenching(player, packet, world), _ => OnPlacing(player, packet, world), }; if (packet.Tile != 32) { world.Save(); } break; } case 0x7: { OnTileActivated(player, world, packet); break; } case 0xa: { break; } case 0xb: { Visual.ApplyCollect(player, world, packet.Tile, packet.Pos); break; } case 0x12: { break; } default: send = false; break; } if (send) { foreach (var ply in world.Players) { ply.Send(packet); } } }
//<SnippetGraphicsMMRetrieveDrawings> public void RetrieveDrawing(Visual v) { DrawingGroup drawingGroup = VisualTreeHelper.GetDrawing(v); EnumDrawingGroup(drawingGroup); }
public void BitCompoundButtonShouldHaveCorrectDisabledClassBasedOnButtonStyle(Visual visual, BitButtonStyle buttonStyle, bool isEnabled) { var component = RenderComponent <BitCompoundButtonTest>(parameters => { parameters.Add(p => p.Visual, visual); parameters.Add(p => p.ButtonStyle, buttonStyle); parameters.Add(p => p.IsEnabled, isEnabled); }); var bitCompoundButton = component.Find(".bit-cmp-btn"); var visualClass = visual == Visual.Cupertino ? "cupertino" : visual == Visual.Material ? "material" : "fluent"; var buttonStyleStr = buttonStyle == BitButtonStyle.Primary ? "primary" : "standard"; Assert.IsTrue(bitCompoundButton.ClassList.Contains($"bit-cmp-btn-{buttonStyleStr}-disabled-{visualClass}")); }
/// <summary> /// Initializes a new instance of the <see cref="RenderControl"/> class. /// </summary> public RenderControl(Visual hostVisual = null) { this.hostVisual = hostVisual; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.UserPaint, true); UpdateStyles(); }
public static Size TransformFromDevice(this Size size, Visual visual) { Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; return(new Size(size.Width * matrix.M11, size.Height * matrix.M22)); }
public static bool CanTransform(this Visual visual) { return(PresentationSource.FromVisual(visual) != null); }
public static Size TransformFromDeviceDPI(this Visual visual, Size size) { Matrix m = PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice; return(new Size(size.Width * m.M11, size.Height * m.M22)); }
/// <summary> /// Initializes a new instance of the <see cref="VisualReferenceNode" /> class. /// </summary> /// <param name="paramName">Name of the parameter.</param> /// <param name="v">The v.</param> internal VisualReferenceNode(string paramName, Visual v = null) : base(paramName, v) { }
private static Drawing CreateDrawing(Visual visual, bool includeTransform) { DrawingGroup drawingGroup = new DrawingGroup(); System.Windows.Media.Geometry clip = VisualTreeHelper.GetClip(visual); if (clip != null) { drawingGroup.ClipGeometry = clip; } if (includeTransform) { Transform transform = VisualTreeHelper.GetTransform(visual); Vector offset = VisualTreeHelper.GetOffset(visual); Matrix matrix = transform == null ? Matrix.Identity : transform.Value; matrix.Translate(offset.X, offset.Y); if (!matrix.IsIdentity) { drawingGroup.Transform = (Transform) new MatrixTransform(matrix); } } double opacity = VisualTreeHelper.GetOpacity(visual); if (opacity != 1.0) { drawingGroup.Opacity = opacity; } Brush opacityMask = VisualTreeHelper.GetOpacityMask(visual); if (opacityMask != null) { drawingGroup.OpacityMask = opacityMask; } BitmapEffect bitmapEffect = VisualTreeHelper.GetBitmapEffect(visual); if (bitmapEffect != null) { drawingGroup.BitmapEffect = bitmapEffect; } BitmapEffectInput bitmapEffectInput = VisualTreeHelper.GetBitmapEffectInput(visual); if (bitmapEffectInput != null && (!bitmapEffectInput.AreaToApplyEffect.IsEmpty || bitmapEffectInput.Input != BitmapEffectInput.ContextInputSource)) { drawingGroup.BitmapEffectInput = bitmapEffectInput; } Drawing drawing1; if (MakeDrawingBrushCommand.IsMediaElementInstance(visual)) { Rect bounds = VisualTreeHelper.GetDrawing(visual).Bounds; drawing1 = (Drawing) new VideoDrawing() { Rect = bounds }; } else { drawing1 = (Drawing)VisualTreeHelper.GetDrawing(visual); } if (drawing1 != null) { drawingGroup.Children.Add(drawing1); } for (int childIndex = 0; childIndex < VisualTreeHelper.GetChildrenCount((DependencyObject)visual); ++childIndex) { Visual visual1 = VisualTreeHelper.GetChild((DependencyObject)visual, childIndex) as Visual; if (visual1 != null) { Drawing drawing2 = MakeDrawingBrushCommand.CreateDrawing(visual1, true); if (drawing2 != null) { drawingGroup.Children.Add(drawing2); } } } if (drawingGroup.Children.Count == 0) { return((Drawing)null); } if (drawingGroup.Children.Count == 1 && drawingGroup.ClipGeometry == null && (drawingGroup.Transform == null || drawingGroup.Transform.Value.IsIdentity) && (drawingGroup.Opacity == 1.0 && drawingGroup.OpacityMask == null && drawingGroup.BitmapEffect == null)) { return(drawingGroup.Children[0]); } return((Drawing)drawingGroup); }
// Translate a mask into shapes for a shape visual. The mask is applied to the visual to be masked // using the VisualSurface. The VisualSurface can take the rendered contents of a visual tree and // use it as a brush. The final masked result is achieved by taking the visual to be masked, putting // it into a VisualSurface, then taking the mask and putting that in a VisualSurface and then combining // the result with a composite effect. public static Visual TranslateAndApplyMasksForLayer( LayerContext context, Visual visualToMask) { var result = visualToMask; var layer = context.Layer; if (layer.Masks.Count > 0) { if (layer.Masks.Count == 1) { // Common case for masks: exactly one mask. var masks = layer.Masks.Slice(0, 1); switch (masks[0].Mode) { // If there's only 1 mask, Difference and Intersect act the same as Add. case Mask.MaskMode.Add: case Mask.MaskMode.Difference: case Mask.MaskMode.Intersect: case Mask.MaskMode.None: // Composite using the mask. result = TranslateAndApplyMasks(context, masks, result, CanvasComposite.DestinationIn); break; case Mask.MaskMode.Subtract: // Composite using the mask. result = TranslateAndApplyMasks(context, masks, result, CanvasComposite.DestinationOut); break; default: context.Issues.MaskWithUnsupportedMode(masks[0].Mode.ToString()); break; } } else { // Uncommon case for masks: multiple masks. // Get the contiguous segments of masks that have the same mode, create a shape tree for each // segment, and composite the shape trees. // The goal here is to use the smallest possible number of composites. // 1) Get the masks that have the same mode and are next to each other in the list of masks. // 2) Translate the masks to a ShapeVisual. // 3) Composite each ShapeVisual with the previous ShapeVisual. foreach (var(index, count) in EnumerateMaskListSegments(layer.Masks.ToArray())) { // Every mask in the segment has the same mode or None. The first mask is never None. var masksWithSameMode = layer.Masks.Slice(index, count); switch (masksWithSameMode[0].Mode) { case Mask.MaskMode.Add: // Composite using the mask, and apply to what has been already masked. result = TranslateAndApplyMasks(context, masksWithSameMode, result, CanvasComposite.DestinationIn); break; case Mask.MaskMode.Subtract: // Composite using the mask, and apply to what has been already masked. result = TranslateAndApplyMasks(context, masksWithSameMode, result, CanvasComposite.DestinationOut); break; default: // Only Add, Subtract, and None modes are currently supported. context.Issues.MaskWithUnsupportedMode(masksWithSameMode[0].Mode.ToString()); break; } } } } return(result); }
/// <summary> /// Indicates if the provider is responsible for providing /// input for the specified visual. /// </summary> public bool ProvidesInputForRootVisual(Visual v) { return(false); }
/// <summary> /// Forces content to scroll until the coordinate space of a System.Windows.Media.Visual /// object is visible. /// </summary> /// <param name="visual">A System.Windows.Media.Visual that becomes visible.</param> /// <param name="rectangle">A bounding rectangle that identifies the coordinate space to make visible.</param> /// <returns>A <see cref="System.Windows.Rect"/> that is visible.</returns> public Rect MakeVisible(Visual visual, Rect rectangle) { return(rectangle); // TODO: implement this???????? }
public static void SetAdornedElement(Visual adorner, Visual adorned) { adorner.SetValue(AdornedElementProperty, adorned); }
private static bool TryScrollToCenterOfView(this ItemsControl itemsControl, object item) { // Find the container var container = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as UIElement; if (container == null) { return(false); } // Find the ScrollContentPresenter ScrollContentPresenter presenter = null; for (Visual vis = container; vis != null && vis != itemsControl; vis = VisualTreeHelper.GetParent(vis) as Visual) { if ((presenter = vis as ScrollContentPresenter) != null) { break; } } if (presenter == null) { return(false); } // Find the IScrollInfo var scrollInfo = !presenter.CanContentScroll ? presenter : presenter.Content as IScrollInfo ?? FirstVisualChild(presenter.Content as ItemsPresenter) as IScrollInfo ?? presenter; // Compute the center point of the container relative to the scrollInfo Size size = container.RenderSize; Point center = container.TransformToAncestor((Visual)scrollInfo).Transform(new Point(size.Width / 2, size.Height / 2)); center.Y += scrollInfo.VerticalOffset; center.X += scrollInfo.HorizontalOffset; // Adjust for logical scrolling if (scrollInfo is StackPanel || scrollInfo is VirtualizingStackPanel) { double logicalCenter = itemsControl.ItemContainerGenerator.IndexFromContainer(container) + 0.5; Orientation orientation = scrollInfo is StackPanel ? ((StackPanel)scrollInfo).Orientation : ((VirtualizingStackPanel)scrollInfo).Orientation; if (orientation == Orientation.Horizontal) { center.X = logicalCenter; } else { center.Y = logicalCenter; } } // Scroll the center of the container to the center of the viewport if (scrollInfo.CanVerticallyScroll) { scrollInfo.SetVerticalOffset(CenteringOffset(center.Y, scrollInfo.ViewportHeight, scrollInfo.ExtentHeight)); } if (scrollInfo.CanHorizontallyScroll) { scrollInfo.SetHorizontalOffset(CenteringOffset(center.X, scrollInfo.ViewportWidth, scrollInfo.ExtentWidth)); } return(true); }
public VisualItem(Visual visual, VisualTreeItem parent) : base(visual, parent) { this.visual = visual; }
public static Visual GetAdornedElement(Visual adorner) { return(adorner.GetValue(AdornedElementProperty)); }
public AlphaTweener(Visual image, float alpha, float time) : base(image, time) { Image = image; Start = image.Alpha(); Delta = alpha - Start; }
public int AddChild(Visual child) { return(children.Add(child)); }
public Rect MakeVisible(Visual visual, Rect rectangle) { return(new Rect()); }
private void PullToRefreshPage_Loaded(object sender, RoutedEventArgs e) { visualizerContentVisual = ElementCompositionPreview.GetElementVisual(rv2.Content); this.Loaded -= PullToRefreshPage_Loaded; }
public IntPtr GetHandle(Visual element) { var source = (HwndSource)PresentationSource.FromVisual(element); return(source.Handle); }
public void AddObject(Visual visual) { //_objectsToAdd.Enqueue(visual); ObjectsToRemove.Add(visual); }
public static Point TransformFromDevice(this Point point, Visual visual) { Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; return(matrix.Transform(point)); }
private void uc_Loaded(object sender, RoutedEventArgs e) { rootVisual = ElementCompositionPreview.GetElementVisual(maingrid); compositor = rootVisual.Compositor; }
/// <summary>Forces content to scroll until the coordinate space of a <see cref="T:System.Windows.Media.Visual" /> object is visible. </summary> /// <param name="visual">The <see cref="T:System.Windows.Media.Visual" /> that becomes visible.</param> /// <param name="rectangle">The bounding rectangle that identifies the coordinate space to make visible.</param> /// <returns>A <see cref="T:System.Windows.Rect" /> that represents the visible region.</returns> // Token: 0x06005442 RID: 21570 RVA: 0x00175420 File Offset: 0x00173620 public Rect MakeVisible(Visual visual, Rect rectangle) { return(this.MakeVisible(visual, rectangle, true)); }
// Token: 0x0600545F RID: 21599 RVA: 0x00175B34 File Offset: 0x00173D34 internal void HookupScrollingComponents() { ScrollViewer scrollViewer = base.TemplatedParent as ScrollViewer; if (scrollViewer != null) { IScrollInfo scrollInfo = null; if (this.CanContentScroll) { scrollInfo = (base.Content as IScrollInfo); if (scrollInfo == null) { Visual visual = base.Content as Visual; if (visual != null) { ItemsPresenter itemsPresenter = visual as ItemsPresenter; if (itemsPresenter == null) { FrameworkElement frameworkElement = scrollViewer.TemplatedParent as FrameworkElement; if (frameworkElement != null) { itemsPresenter = (frameworkElement.GetTemplateChild("ItemsPresenter") as ItemsPresenter); } } if (itemsPresenter != null) { itemsPresenter.ApplyTemplate(); int childrenCount = VisualTreeHelper.GetChildrenCount(itemsPresenter); if (childrenCount > 0) { scrollInfo = (VisualTreeHelper.GetChild(itemsPresenter, 0) as IScrollInfo); } } } } } if (scrollInfo == null) { scrollInfo = this; this.EnsureScrollData(); } if (scrollInfo != this._scrollInfo && this._scrollInfo != null) { if (this.IsScrollClient) { this._scrollData = null; } else { this._scrollInfo.ScrollOwner = null; } } if (scrollInfo != null) { this._scrollInfo = scrollInfo; scrollInfo.ScrollOwner = scrollViewer; scrollViewer.ScrollInfo = scrollInfo; return; } } else if (this._scrollInfo != null) { if (this._scrollInfo.ScrollOwner != null) { this._scrollInfo.ScrollOwner.ScrollInfo = null; } this._scrollInfo.ScrollOwner = null; this._scrollInfo = null; this._scrollData = null; } }
public static Rect TransformFromDevice(this Rect rect, Visual visual) { Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; return(Rect.Transform(rect, matrix)); }
public abstract void WriteAsync(Visual visual, PrintTicket printTicket, object userState);