private async void enemyTurn() { string nextMove = enemy.nextMove(); try { gameBoard.setTile(nextMove, Board.TileStates.Enemy); }catch (TileOccupiedException e) { var notification = new Windows.UI.Popups.MessageDialog("Empate, tablero lleno"); await notification.ShowAsync(); gameBoard.clear(); clearBoard(); return; } Windows.UI.Xaml.Shapes.Rectangle nextTile = (Windows.UI.Xaml.Shapes.Rectangle) this.FindName(nextMove); nextTile.Fill = enemyColor; if (gameBoard.evaluateBoard() == Board.TileStates.Enemy) { var notification = new Windows.UI.Popups.MessageDialog("Has perdido!"); await notification.ShowAsync(); gameBoard.clear(); clearBoard(); } }
private async void LoadBoundingBoxesButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List; picker.FileTypeFilter.Add(".txt"); Windows.Storage.StorageFile storageFile = await picker.PickSingleFileAsync(); System.IO.Stream stream = await storageFile.OpenStreamForReadAsync(); using (System.IO.StreamReader streamReader = new System.IO.StreamReader(stream)) { while (!streamReader.EndOfStream) { string line = streamReader.ReadLine(); string[] values = line.Split(' '); Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle(); rectangle.Fill = this.GetColor(values[0]); rectangle.Opacity = 0.1; rectangle.Width = System.Convert.ToDouble(values[3]) * this.ImageToAnalyze.Width; rectangle.Height = System.Convert.ToDouble(values[4]) * this.ImageToAnalyze.Height; Windows.UI.Xaml.Controls.Canvas.SetLeft(rectangle, this.PositionOfLeftEdgeOfImageRelativeToLeftEdgeOfImageCanvas + (System.Convert.ToDouble(values[1]) * this.ImageToAnalyze.Width) - (rectangle.Width / 2)); Windows.UI.Xaml.Controls.Canvas.SetTop(rectangle, this.PositionOfTopEdgeOfImageRelativeToTopEdgeOfImageCanvas + (System.Convert.ToDouble(values[2]) * this.ImageToAnalyze.Height) - (rectangle.Height / 2)); this.ImageCanvas.Children.Add(rectangle); } } }
public void Dispose() { if (_mainCanvas != null) { if (_popMenuOverlayRenderer != null) { _popMenuOverlayRenderer.PointerPressed -= menuOverlayRenderer_PointerPressed; _popMenuOverlayRenderer.PointerMoved -= menuOverlayRenderer_PointerMoved; _popMenuOverlayRenderer.PointerReleased -= menuOverlayRenderer_PointerReleased; _popMenuOverlayRenderer.PointerExited -= menuOverlayRenderer_PointerReleased; _mainCanvas.Children.Remove(_popMenuOverlayRenderer); } if (_backgroundOverlay != null) { _backgroundOverlay.Tapped -= _backgroundOverlay_Tapped; _mainCanvas.Children.Remove(_backgroundOverlay); } if (_popupRenderer != null) { _mainCanvas.Children.Remove(_popupRenderer); } _mainCanvas.SizeChanged -= mainCanvas_SizeChanged; } _mainCanvas = null; _popMenuOverlayRenderer = null; _backgroundOverlay = null; _popupRenderer = null; }
protected override void OnApplyTemplate() { if (_bkgLayer == null) _bkgLayer = GetTemplateChild("bkgLayer") as EffectLayer.EffectLayer; if (_butRoot == null) { _butRoot = GetTemplateChild("butRoot") as Button; _butRoot.Click += _butRoot_Click; _butRoot.PointerEntered += _butRoot_PointerEntered; _butRoot.PointerExited += _butRoot_PointerExited; } if (_bkgLayer != null && _butRoot != null && _butRoot.ActualWidth != 0) _bkgLayer.InitLayer(_butRoot.ActualWidth, _butRoot.ActualHeight); if (_tbContent == null) _tbContent = GetTemplateChild("tbContent") as TextBlock; if (_xuiIco == null) _xuiIco = GetTemplateChild("xuiIco") as X.UI.Path.Path; if (_grdTooltip == null) _grdTooltip = GetTemplateChild("grdTooltip") as Grid; if (_grdTTContainer == null) _grdTTContainer = GetTemplateChild("grdTTContainer") as Grid; _rect = GetTemplateChild("rect") as Windows.UI.Xaml.Shapes.Rectangle; base.OnApplyTemplate(); }
private void MakeStarsBackground() { Random r = new Random(); int i = 0; int nb_stars = (int)(Window.Current.CoreWindow.Bounds.Width * Window.Current.CoreWindow.Bounds.Height * Options.NB_STARS_PER_AREA); Windows.UI.Xaml.Shapes.Rectangle temp; for (i = 0; i < nb_stars; i++) { temp = new Windows.UI.Xaml.Shapes.Rectangle() { Width = 2, Height = 2, Fill = new SolidColorBrush(Windows.UI.Colors.White), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness() { Left = r.Next() % Window.Current.CoreWindow.Bounds.Width, Top = r.Next() % Window.Current.CoreWindow.Bounds.Height } }; // Adding it to the display structure : stars.Children.Add(temp); } }
private void addHand(ref Windows.UI.Xaml.Shapes.Rectangle hand) { if (!face.Children.Contains(hand)) { face.Children.Add(hand); } }
//绘制颜色选择区rectColor private void DrawDoubleLinearGradient() { cvsDoubleLinear.Children.Clear(); int nRect = (int)Height; Windows.UI.Xaml.Shapes.Rectangle[] rectLinearGradient = new Windows.UI.Xaml.Shapes.Rectangle[nRect]; LinearGradientBrush[] linearBrush = new LinearGradientBrush[nRect]; for (int i = 0; i < nRect; ++i) { Windows.UI.Color clr1 = new Windows.UI.Color(), clr2 = new Windows.UI.Color(); clr1.A = clr2.A = 255; clr2.R = clr2.G = clr2.B = (Byte)((nRect - 1 - i) * 255 / (nRect - 1)); clr1.R = (Byte)((nRect - i - 1) * colorPure.R / (nRect - 1)); clr1.G = (Byte)((nRect - i - 1) * colorPure.G / (nRect - 1)); clr1.B = (Byte)((nRect - i - 1) * colorPure.B / (nRect - 1)); GradientStop gradientStop1 = new GradientStop(), gradientStop2 = new GradientStop(); gradientStop1.Offset = 0; gradientStop1.Offset = 1; gradientStop1.Color = clr1; gradientStop2.Color = clr2; linearBrush[i] = new LinearGradientBrush(); linearBrush[i].StartPoint = new Point(0, 0); linearBrush[i].EndPoint = new Point(1, 0); linearBrush[i].GradientStops.Add(gradientStop2); linearBrush[i].GradientStops.Add(gradientStop1); rectLinearGradient[i] = new Windows.UI.Xaml.Shapes.Rectangle(); rectLinearGradient[i].Width = 0.8 * Width; rectLinearGradient[i].Height = 1; rectLinearGradient[i].StrokeThickness = 0; rectLinearGradient[i].Fill = linearBrush[i]; cvsDoubleLinear.Children.Add(rectLinearGradient[i]); Canvas.SetTop(rectLinearGradient[i], i); } }
protected override void OnElementChanged(ElementChangedEventArgs <DropShadowView> e) { base.OnElementChanged(e); if (e?.OldElement != null) { ParentView.SizeChanged -= Element_SizeChanged; } if (e?.NewElement != null) { SetNativeControl(new DropShadowPanel() { Color = Colors.Black, ShadowOpacity = 0.34f, }); _rectangle = new Rectangle(); Control.Content = _rectangle; UpdateSurfaceColor(); UpdateCornerRadius(); UpdateElevation(); ParentView.SizeChanged += Element_SizeChanged; } }
public void InitializeComponent() { if (_contentLoaded) return; _contentLoaded = true; Application.LoadComponent(this, new System.Uri("ms-appx:///SplitPage.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application); pageRoot = (NoelBlogReader.Common.LayoutAwarePage)this.FindName("pageRoot"); itemsViewSource = (Windows.UI.Xaml.Data.CollectionViewSource)this.FindName("itemsViewSource"); primaryColumn = (Windows.UI.Xaml.Controls.ColumnDefinition)this.FindName("primaryColumn"); titlePanel = (Windows.UI.Xaml.Controls.Grid)this.FindName("titlePanel"); itemListScrollViewer = (Windows.UI.Xaml.Controls.ScrollViewer)this.FindName("itemListScrollViewer"); itemDetail = (Windows.UI.Xaml.Controls.ScrollViewer)this.FindName("itemDetail"); itemDetailGrid = (Windows.UI.Xaml.Controls.Grid)this.FindName("itemDetailGrid"); itemTitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("itemTitle"); contentViewBorder = (Windows.UI.Xaml.Controls.Border)this.FindName("contentViewBorder"); contentView = (Windows.UI.Xaml.Controls.WebView)this.FindName("contentView"); contentViewRect = (Windows.UI.Xaml.Shapes.Rectangle)this.FindName("contentViewRect"); itemListView = (Windows.UI.Xaml.Controls.ListView)this.FindName("itemListView"); backButton = (Windows.UI.Xaml.Controls.Button)this.FindName("backButton"); pageTitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("pageTitle"); FullScreenLandscape = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenLandscape"); Filled = (Windows.UI.Xaml.VisualState)this.FindName("Filled"); FullScreenPortrait = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait"); FullScreenPortrait_Detail = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait_Detail"); Snapped = (Windows.UI.Xaml.VisualState)this.FindName("Snapped"); Snapped_Detail = (Windows.UI.Xaml.VisualState)this.FindName("Snapped_Detail"); }
private void removeHand(ref Windows.UI.Xaml.Shapes.Rectangle hand) { if (hand != null && face.Children.Contains(hand)) { face.Children.Remove(hand); } }
internal override void InitializeShape() { Shape = new Windows.UI.Xaml.Shapes.Rectangle { Width = 100, Height = 100 }; }
public CanvasWidget(cave.GuiApplicationContext context) { widgetContext = context; widgetColor = cave.Color.black(); widgetOutlineColor = cave.Color.black(); rectangle = new Windows.UI.Xaml.Shapes.Rectangle(); this.Content = rectangle; }
private void Button_Click_3(object sender, RoutedEventArgs e) { var newRect = new Windows.UI.Xaml.Shapes.Rectangle(); canv1.Children.Add(newRect); newRect.Height = 40; newRect.Width = 40; }
void HideBackgroundOverlay() { if (_backgroundOverlay != null) { _mainCanvas.Children.Remove(_backgroundOverlay); _backgroundOverlay = null; } }
public FallbackGrid() { Latest = this; Windows.UI.Xaml.Shapes.Rectangle rect = new Windows.UI.Xaml.Shapes.Rectangle(); rect.MaxWidth = rect.MinWidth = RectangleWidth; rect.MaxHeight = rect.MinHeight = RectangleHeight; rect.Fill = new SolidColorBrush(RectangleColor); Children.Add(rect); }
private void DrawYoloBoundingBox(YoloBoundingBox box, Canvas overlayCanvas) { // process output boxes var x = (uint)Math.Max(box.X, 0); var y = (uint)Math.Max(box.Y, 0); var w = (uint)Math.Min(overlayCanvas.ActualWidth - x, box.Width); var h = (uint)Math.Min(overlayCanvas.ActualHeight - y, box.Height); // fit to current canvas and webcam size x = _canvasActualWidth * x / 416; y = _canvasActualHeight * y / 416; w = _canvasActualWidth * w / 416; h = _canvasActualHeight * h / 416; var rectStroke = _lineBrushYellow; if (box.Label == "person") { rectStroke = _lineBrushGreen; personCount++; } var r = new Windows.UI.Xaml.Shapes.Rectangle { Tag = box, Width = w, Height = h, Fill = _fillBrush, Stroke = rectStroke, StrokeThickness = _lineThickness, Margin = new Thickness(x, y, 0, 0) }; var tb = new TextBlock { Margin = new Thickness(x + 4, y + 4, 0, 0), Text = $"{box.Label} ({Math.Round(box.Confidence, 4)})", FontWeight = FontWeights.Bold, Width = 126, Height = 21, HorizontalTextAlignment = TextAlignment.Center }; var textBack = new Windows.UI.Xaml.Shapes.Rectangle { Width = 134, Height = 29, Fill = rectStroke, Margin = new Thickness(x, y, 0, 0) }; overlayCanvas.Children.Add(textBack); overlayCanvas.Children.Add(tb); overlayCanvas.Children.Add(r); }
/// <summary> /// Draws the specified rectangle. /// </summary> public void Draw(DualViewsDrawingModel.Shapes.Rectangle rectangle) { Windows.UI.Xaml.Shapes.Rectangle drawingPageCanvasRectangle = new Windows.UI.Xaml.Shapes.Rectangle(); drawingPageCanvasRectangle.Width = rectangle.Width; drawingPageCanvasRectangle.Height = rectangle.Height; drawingPageCanvasRectangle.Stroke = new SolidColorBrush(Colors.Black); _canvas.Children.Add(drawingPageCanvasRectangle); Canvas.SetLeft(drawingPageCanvasRectangle, rectangle.X); Canvas.SetTop(drawingPageCanvasRectangle, rectangle.Y); }
//draw a rectangle public void DrawRectangle(double x, double y, double width, double height) { Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle(); rectangle.Width = width; rectangle.Height = height; rectangle.Margin = new Windows.UI.Xaml.Thickness(x, y, width, height); rectangle.Fill = new SolidColorBrush(Colors.Yellow); rectangle.Stroke = new SolidColorBrush(Colors.Black); _canvas.Children.Add(rectangle); }
private async void Button_Click(object sender, RoutedEventArgs e) { Demo demo = new Demo(); Windows.UI.Xaml.Shapes.Rectangle modelhost = new Windows.UI.Xaml.Shapes.Rectangle(); modelhost.Width = modelhost.Height = 200; myStack.Children.Add(modelhost); demoList.Add(demo); await demo.CrossThread4(modelhost); }
private void SecondHand(int seconds) { RemoveHand(ref _secondsHand); if (ShowSeconds) { _secondsHand = Hand(_secondsWidth, _secondsHeight, 0, 0, 0); _secondsHand.RenderTransform = TransformGroup(seconds * 6, -_secondsWidth / 2, -_secondsHeight + 4.25); AddHand(ref _secondsHand); } }
private void MinuteHand(int minutes, int seconds) { RemoveHand(ref _minutesHand); if (ShowMinutes) { _minutesHand = Hand(_minutesWidth, _minutesHeight, 2, 2, 0.6); _minutesHand.RenderTransform = TransformGroup(6 * minutes + seconds / 10, -_minutesWidth / 2, -_minutesHeight + 4.25); AddHand(ref _minutesHand); } }
private void secondHand(int seconds) { removeHand(ref secondsHand);//ref?????? if (ShowSeconds) { secondsHand = hand(secondsWidth, secondsHeight, 0, 0, 0); secondsHand.RenderTransform = transformGroup(seconds * 6, -secondsWidth / 2, -secondsHeight + 4.25); addHand(ref secondsHand); } }
private Windows.UI.Xaml.Shapes.Rectangle GetRectangle(Windows.UI.Color colour, int column) { Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle() { Height = 10, Stretch = Stretch.UniformToFill, Fill = new SolidColorBrush(colour) }; rectangle.SetValue(Grid.ColumnProperty, column); return(rectangle); }
private Windows.UI.Xaml.Shapes.Rectangle hand(double width, double height, double radiusX, double radiusY, double thickness) { Windows.UI.Xaml.Shapes.Rectangle hand = new Windows.UI.Xaml.Shapes.Rectangle(); hand.Width = width; hand.Height = height; hand.Fill = Foreground; hand.StrokeThickness = thickness; hand.RadiusX = radiusX; hand.RadiusY = radiusY; return(hand); }
// Create ImageCanvas_PointerMoved to handle moving a mouse pointer across an opened image. private void ImageCanvas_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { Windows.Foundation.Point positionOfPointer = e.GetCurrentPoint(this.ImageCanvas).Position; double positionOfPointerRelativeToLeftEdgeOfImageCanvas = positionOfPointer.X; double positionOfPointerRelativeToTopEdgeOfImageCanvas = positionOfPointer.Y; // If the image has not been clicked to draw a bounding box, or if a bounding box has been drawn and clickState reset... if (this.ClickState == 0) { // Remove any horizontal and vertical lines through the mouse pointer. this.ImageCanvas.Children.Remove((Windows.UI.Xaml.UIElement) this.ImageCanvas.FindName("horizontalPointerLine")); this.ImageCanvas.Children.Remove((Windows.UI.Xaml.UIElement) this.ImageCanvas.FindName("verticalPointerLine")); // Draw a new horizontal pointer line. Windows.UI.Xaml.Shapes.Line horizontalPointerLine = new Windows.UI.Xaml.Shapes.Line(); horizontalPointerLine.Name = "horizontalPointerLine"; horizontalPointerLine.X1 = this.PositionOfLeftEdgeOfImageRelativeToLeftEdgeOfImageCanvas; horizontalPointerLine.X2 = this.PositionOfRightEdgeOfImageRelativeToLeftEdgeOfImageCanvas; horizontalPointerLine.Y1 = positionOfPointerRelativeToTopEdgeOfImageCanvas; horizontalPointerLine.Y2 = positionOfPointerRelativeToTopEdgeOfImageCanvas; horizontalPointerLine.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Black); horizontalPointerLine.StrokeThickness = 1; this.ImageCanvas.Children.Add(horizontalPointerLine); // Draw a new vertical pointer line. Windows.UI.Xaml.Shapes.Line verticalPointerLine = new Windows.UI.Xaml.Shapes.Line(); verticalPointerLine.Name = "verticalPointerLine"; verticalPointerLine.X1 = positionOfPointerRelativeToLeftEdgeOfImageCanvas; verticalPointerLine.X2 = positionOfPointerRelativeToLeftEdgeOfImageCanvas; verticalPointerLine.Y1 = this.PositionOfTopEdgeOfImageRelativeToTopEdgeOfImageCanvas; verticalPointerLine.Y2 = this.PositionOfBottomEdgeOfImageRelativeToTopEdgeOfImageCanvas; verticalPointerLine.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Black); verticalPointerLine.StrokeThickness = 1; this.ImageCanvas.Children.Add(verticalPointerLine); } // if // If the image has been clicked once, or if a bounding box has been drawn, clickState reset, and the image clicked again... if (this.ClickState == 1) { // Remove any rectangle from the imageCanvas. this.ImageCanvas.Children.Remove((Windows.UI.Xaml.UIElement) this.ImageCanvas.FindName("rectangle")); // Add a new rectangle named rectangle between the first click point and the present location of a mouse pointer. Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle(); rectangle.Name = "rectangle"; rectangle.Fill = this.GetColor(this.TextBoxForClassIndex.Text); rectangle.Opacity = 0.1; rectangle.Width = System.Math.Abs(positionOfPointerRelativeToLeftEdgeOfImageCanvas - this.PositionOfFirstClickRelativeToLeftEdgeOfImageCanvas); rectangle.Height = System.Math.Abs(positionOfPointerRelativeToTopEdgeOfImageCanvas - this.PositionOfFirstClickRelativeToTopEdgeOfImageCanvas); Windows.UI.Xaml.Controls.Canvas.SetLeft(rectangle, System.Math.Min(positionOfPointerRelativeToLeftEdgeOfImageCanvas, this.PositionOfFirstClickRelativeToLeftEdgeOfImageCanvas)); Windows.UI.Xaml.Controls.Canvas.SetTop(rectangle, System.Math.Min(positionOfPointerRelativeToTopEdgeOfImageCanvas, this.PositionOfFirstClickRelativeToTopEdgeOfImageCanvas)); this.ImageCanvas.Children.Add(rectangle); } // if } // private void ImageCanvas_PointerMoved
private void HourHand(int hours, int minutes, int seconds) { RemoveHand(ref _hoursHand); if (ShowHours) { _hoursHand = Hand(_hoursWidth, _hoursHeight, 3, 3, 0.6); _hoursHand.RenderTransform = TransformGroup(30 * hours + minutes / 2 + seconds / 120, -_hoursWidth / 2, -_hoursHeight + 4.25); AddHand(ref _hoursHand); } }
private void minuteHand(int minutes, int seconds) { removeHand(ref minutesHand); if (ShowMinutes) { minutesHand = hand(minutesWidth, minutesHeight, 2, 2, 0.6); minutesHand.RenderTransform = transformGroup(6 * minutes + seconds / 10, -minutesWidth / 2, -minutesHeight + 4.25); addHand(ref minutesHand); } }
private void hourHand(int hours, int minutes, int seconds) { removeHand(ref hoursHand); if (ShowHours) { hoursHand = hand(hoursWidth, hoursHeight, 3, 3, 0.6); hoursHand.RenderTransform = transformGroup(30 * hours + minutes / 2 + seconds / 120, -hoursWidth / 2, -hoursHeight + 4.25); addHand(ref hoursHand); } }
void SetupTopMarginBorder() { var cluster = (Cluster)_subgraph.GeometryObject; _topMarginRect = new Rectangle { Fill = new SolidColorBrush(Colors.Transparent), Width = Node.Width, Height = cluster.RectangularBoundary.TopMargin }; PositionTopMarginBorder(cluster); SetZIndexAndMouseInteractionsForTopMarginRect(); }
public override void FillRectangle(Brush brush, float x, float y, float width, float height) { var rect = new UIRectangle(); rect.Stroke = ToSolidColorBrush(((SolidBrush)brush).Color); rect.Fill = ToSolidColorBrush(((SolidBrush)brush).Color); rect.Width = width; rect.Height = height; Canvas.SetLeft(rect, x); Canvas.SetTop(rect, y); canvas.Children.Add(rect); }
public FallbackGrid() { _fallbackGrid = this; Windows.UI.Xaml.Shapes.Rectangle rect = new Windows.UI.Xaml.Shapes.Rectangle(); rect.MinWidth = 100; rect.MinHeight = 100; rect.MaxWidth = 100; rect.MaxHeight = 100; rect.Fill = new SolidColorBrush(Colors.Red); Children.Add(rect); }
private void InsertShade(int insertIndex, Shade shade) { shade.PropertyChanged -= ShadePropertyChanged; InternalLogger.Debug(LogTag, () => $"InsertShade( insertIndex: {insertIndex}, shade: {shade} )"); // https://docs.microsoft.com/en-US/windows/uwp/composition/using-the-visual-layer-with-xaml var ttv = _shadowSource.TransformToVisual(_shadowsCanvas); Windows.Foundation.Point offset = ttv.TransformPoint(new Windows.Foundation.Point(0, 0)); double width = _shadowSource.ActualWidth; double height = _shadowSource.ActualHeight; var shadowHost = new Rectangle() { Fill = Xamarin.Forms.Color.White.ToBrush(), Width = width, Height = height, RadiusX = _cornerRadius, RadiusY = _cornerRadius, }; Canvas.SetLeft(shadowHost, offset.X); Canvas.SetTop(shadowHost, offset.Y); _shadowsCanvas.Children.Insert(insertIndex, shadowHost); if (_compositor == null) { Visual hostVisual = ElementCompositionPreview.GetElementVisual(_shadowsCanvas); _compositor = hostVisual.Compositor; } var dropShadow = _compositor.CreateDropShadow(); dropShadow.BlurRadius = (float)shade.BlurRadius * 2; dropShadow.Opacity = (float)shade.Opacity; dropShadow.Color = shade.Color.ToWindowsColor(); dropShadow.Offset = new Vector3((float)shade.Offset.X - SafeMargin, (float)shade.Offset.Y - SafeMargin, 0); dropShadow.Mask = shadowHost.GetAlphaMask(); var shadowVisual = _compositor.CreateSpriteVisual(); shadowVisual.Size = new Vector2((float)width, (float)height); shadowVisual.Shadow = dropShadow; _shadowVisuals.Insert(insertIndex, shadowVisual); ElementCompositionPreview.SetElementChildVisual(shadowHost, shadowVisual); shade.PropertyChanged += ShadePropertyChanged; }
private void addButton_Click(object sender, RoutedEventArgs e) { var colorRect = new Windows.UI.Xaml.Shapes.Rectangle { Fill = new SolidColorBrush(c[rnd.Next(0, c.Length - 1)]), Transitions = new TransitionCollection() { new EntranceThemeTransition() } }; myGridView.Children.Add(colorRect); }
public void CreateRectangle(Color color) { Random random = new Random(); var left = random.Next(0, 300); var top = random.Next(0, 300); var rect = new Windows.UI.Xaml.Shapes.Rectangle(); rect.Height = 100; rect.Width = 100; rect.Margin = new Thickness(left, top, 0, 0); rect.Fill = new SolidColorBrush(color); LayoutGrid.Children.Add(rect); }
public void InitializeComponent() { if (_contentLoaded) return; _contentLoaded = true; Application.LoadComponent(this, new System.Uri("ms-appx:///BasicPage1.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application); pageRoot = (key_control_image_sample.Common.LayoutAwarePage)this.FindName("pageRoot"); canv1 = (Windows.UI.Xaml.Controls.Canvas)this.FindName("canv1"); rect = (Windows.UI.Xaml.Shapes.Rectangle)this.FindName("rect"); backButton = (Windows.UI.Xaml.Controls.Button)this.FindName("backButton"); pageTitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("pageTitle"); FullScreenLandscape = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenLandscape"); Filled = (Windows.UI.Xaml.VisualState)this.FindName("Filled"); FullScreenPortrait = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait"); Snapped = (Windows.UI.Xaml.VisualState)this.FindName("Snapped"); }
void OnTick(object sender, object e) { if (_On) { // clear children _Overlay.Children.Clear(); _On = false; } else { // draw a red rectangle double left = _Overlay.Width * _Rectangle.X, top = _Overlay.Height * _Rectangle.Y; double right = _Overlay.Width * _Rectangle.Width, bottom = _Overlay.Height * _Rectangle.Height; Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle(); rectangle.Margin = new Thickness(left, top, right, bottom); rectangle.Stroke = _Red; rectangle.StrokeThickness = 2; _Overlay.Children.Add(rectangle); // draw cross-hair - vertical Windows.UI.Xaml.Shapes.Rectangle vertical = new Windows.UI.Xaml.Shapes.Rectangle(); double centreX = _Overlay.Width / 2; vertical.Margin = new Thickness(centreX, top, centreX, bottom); vertical.Stroke = _Red; vertical.StrokeThickness = 2; _Overlay.Children.Add(vertical); // draw cross-hair - horizontal double centreY = _Overlay.Height / 2; Windows.UI.Xaml.Shapes.Rectangle horizontal = new Windows.UI.Xaml.Shapes.Rectangle(); horizontal.Margin = new Thickness(left, centreY, right, centreY); horizontal.Stroke = _Red; horizontal.StrokeThickness = 2; _Overlay.Children.Add(horizontal); _On = true; } }
private void init(Canvas canvas) { canvas.Children.Clear(); diameter = canvas.Width; double inner = diameter; Windows.UI.Xaml.Shapes.Ellipse face = new Windows.UI.Xaml.Shapes.Ellipse() { Height = diameter, Width = diameter, Fill = background }; canvas.Children.Add(face); Canvas markers = new Canvas() { Width = inner, Height = inner }; for (int i = 0; i < 51; i++) { Windows.UI.Xaml.Shapes.Rectangle marker = new Windows.UI.Xaml.Shapes.Rectangle() { Fill = foreground }; if ((i % 5) == 0) { marker.Width = 4; marker.Height = 16; marker.RenderTransform = transformGroup(i * 6, -(marker.Width / 2), -(marker.Height * 2 + 4.5 - face.StrokeThickness / 2 - inner / 2 - 16)); } else { marker.Width = 2; marker.Height = 8; marker.RenderTransform = transformGroup(i * 6, -(marker.Width / 2), -(marker.Height * 2 + 12.75 - face.StrokeThickness / 2 - inner / 2 - 16)); } markers.Children.Add(marker); } markers.RenderTransform = new RotateTransform() { Angle = 30, CenterX = diameter / 2, CenterY = diameter / 2 }; canvas.Children.Add(markers); needle = new Windows.UI.Xaml.Shapes.Rectangle() { Width = needleWidth, Height = (int)diameter / 2 - 30, Fill = foreground }; canvas.Children.Add(needle); Windows.UI.Xaml.Shapes.Ellipse middle = new Windows.UI.Xaml.Shapes.Ellipse() { Height = diameter / 10, Width = diameter / 10, Fill = foreground }; Canvas.SetLeft(middle, (diameter - middle.ActualWidth) / 2); Canvas.SetTop(middle, (diameter - middle.ActualHeight) / 2); canvas.Children.Add(middle); }
public void StrokeRect(float x, float y, float w, float h) { var rect = new Windows.UI.Xaml.Shapes.Rectangle(); rect.Width = w; rect.Height = h; rect.Stroke = _foregroundBrush; Windows.UI.Xaml.Controls.Canvas.SetTop(rect, y); Windows.UI.Xaml.Controls.Canvas.SetLeft(rect, x); _canvas.Children.Add(rect); }
internal static void Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Rectangle rectangle) { var rect = rectangle.GetBoundingRect(rootElement).ToSharpDX(); var fill = rectangle.Fill.ToSharpDX(renderTarget, rect); var stroke = rectangle.Stroke.ToSharpDX(renderTarget, rect); //var layer = new Layer(renderTarget); //var layerParameters = new LayerParameters(); //layerParameters.ContentBounds = rect; //renderTarget.PushLayer(ref layerParameters, layer); if (rectangle.RadiusX > 0 && rectangle.RadiusY > 0) { var roundedRect = new SharpDX.Direct2D1.RoundedRect(); roundedRect.Rect = rect; roundedRect.RadiusX = (float)rectangle.RadiusX; roundedRect.RadiusY = (float)rectangle.RadiusY; if (rectangle.StrokeThickness > 0 && stroke != null) { var halfThickness = (float)(rectangle.StrokeThickness * 0.5); roundedRect.Rect = rect.Eroded(halfThickness); if (fill != null) { renderTarget.FillRoundedRectangle(roundedRect, fill); } renderTarget.DrawRoundedRectangle( roundedRect, stroke, (float)rectangle.StrokeThickness, rectangle.GetStrokeStyle(compositionEngine.D2DFactory)); } else { renderTarget.FillRoundedRectangle(roundedRect, fill); } } else { if (rectangle.StrokeThickness > 0 && stroke != null) { var halfThickness = (float)(rectangle.StrokeThickness * 0.5); if (fill != null) { renderTarget.FillRectangle(rect.Eroded(halfThickness), fill); } var strokeRect = rect.Eroded(halfThickness); renderTarget.DrawRectangle( strokeRect, stroke, (float)rectangle.StrokeThickness, rectangle.GetStrokeStyle(compositionEngine.D2DFactory)); } else { renderTarget.FillRectangle(rect, fill); } } //renderTarget.PopLayer(); }
private void drawEmotionRectangle(Canvas RectangleCanvas, Rectangle FaceRectangle, float score, string emotion) { double ratio = 1; double leftMargin = 0; double topMargin = 0; if (captureWidth > 0) { var hratio = RectangleCanvas.ActualHeight / captureHeight; var wratio = RectangleCanvas.ActualWidth / captureWidth; if (hratio < wratio) { ratio = hratio; leftMargin = (RectangleCanvas.ActualWidth - (captureWidth * ratio)) / 2; } else { ratio = wratio; topMargin = (RectangleCanvas.ActualHeight - (captureHeight * ratio)) / 2; } } RectangleCanvas.Children.Clear(); var r = new Windows.UI.Xaml.Shapes.Rectangle(); RectangleCanvas.Children.Add(r); r.Stroke = new SolidColorBrush(Windows.UI.Colors.Yellow); r.StrokeThickness = 5; r.Width = FaceRectangle.Width * ratio; r.Height = FaceRectangle.Height * ratio; Canvas.SetLeft(r, (FaceRectangle.Left * ratio) + leftMargin); Canvas.SetTop(r, (FaceRectangle.Top * ratio) + topMargin); Border b = new Border(); b.Background= new SolidColorBrush(Windows.UI.Colors.Yellow); b.Width = r.Width; RectangleCanvas.Children.Add(b); b.Padding = new Thickness(2); var t = new TextBlock(); b.Child=t; t.Width = r.Width; t.FontSize = 16; t.Foreground = new SolidColorBrush(Windows.UI.Colors.Black); Canvas.SetLeft(b, (FaceRectangle.Left * ratio) + leftMargin); Canvas.SetTop(b, (FaceRectangle.Top * ratio) + topMargin + r.Height -1); t.Text = $"{emotion}\r\n{score:N1}%"; }
/// <summary> /// Draws a rectangle /// </summary> /// <param name="frame"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawRectangle(Rect frame, Pen pen = null, NGraphics.Brush brush = null) { var rectangleEl = new Windows.UI.Xaml.Shapes.Rectangle(); var offset = pen != null ? pen.Width : 0.0; rectangleEl.Width = frame.Width + offset; rectangleEl.Height = frame.Height + offset; if (brush != null) rectangleEl.Fill = GetBrush(brush); if (pen != null) { rectangleEl.Stroke = GetStroke(pen); rectangleEl.StrokeThickness = pen.Width; } rectangleEl.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(rectangleEl); Canvas.SetLeft(rectangleEl, frame.X - offset / 2.0); Canvas.SetTop(rectangleEl, frame.Y - offset / 2.0); }
private void oneTimeInit() { if (hasInitialized) return; //if(_bkgLayer == null) _bkgLayer = GetTemplateChild("bkgLayer") as EffectLayer.EffectLayer; if (_root == null) _root = GetTemplateChild("root") as Grid; if (_root != null) { if (_ccTitle == null) { _ccTitle = GetTemplateChild("ccTitle") as ContentControl; _ccTitle.Content = TitleContent; } if (_recSmallTitle == null) { _recSmallTitle = GetTemplateChild("recSmallTitle") as Windows.UI.Xaml.Shapes.Rectangle; Window.Current.SetTitleBar(_recSmallTitle); //_dtChrome = new DispatcherTimer(); //_dtChrome.Interval = new TimeSpan(0, 0, 0, 0, 15); //_dtChrome.Tick += (object sender, object e) => //{ // //NativeLib.GetCursorPos(ref _curPos); // //ChromeUpdate(_curPos); //}; //if (EnableResizeFix) _dtChrome.Start(); //else _dtChrome.Stop(); } if (_tbTitle == null) { _tbTitle = GetTemplateChild("tbTitle") as TextBlock; _tbTitle.DataContext = this; } //if (_bkgLayer != null && _tbTitle != null && _tbTitle.ActualWidth != 0) _bkgLayer.InitLayer(_root.ActualWidth, _root.ActualHeight, bkgOffsetX, bkgOffsetY); } if (_root != null) hasInitialized = true; }
IEnumerable<FrameworkElement> GetWebPages(WebView webView, Windows.Foundation.Size page) { // ask the content its width var widthString = webView.InvokeScript("eval", new[] { "document.body.scrollWidth.toString()" }); int contentWidth; if (!int.TryParse(widthString, out contentWidth)) throw new Exception(string.Format("failure/width:{0}", widthString)); webView.Width = contentWidth; // ask the content its height var heightString = webView.InvokeScript("eval", new[] { "document.body.scrollHeight.toString()" }); int contentHeight; if (!int.TryParse(heightString, out contentHeight)) throw new Exception(string.Format("failure/height:{0}", heightString)); webView.Height = contentHeight; // how many pages will there be? var scale = page.Width / contentWidth; var scaledHeight = (contentHeight * scale); var pageCount = (double)scaledHeight / page.Height; pageCount = pageCount + ((pageCount > (int)pageCount) ? 1 : 0); // create the pages var pages = new List<Windows.UI.Xaml.Shapes.Rectangle>(); for (int i = 0; i < (int)pageCount; i++) { var translateY = -page.Height * i; var _page = new Windows.UI.Xaml.Shapes.Rectangle { Height = page.Height, Width = page.Width, Margin = new Thickness(5), Tag = new TranslateTransform { Y = translateY }, }; _page.Loaded += (s, e) => { var rectangle = s as Windows.UI.Xaml.Shapes.Rectangle; var brush = GetWebViewBrush(webView); brush.Stretch = Stretch.UniformToFill; brush.AlignmentY = AlignmentY.Top; brush.Transform = rectangle.Tag as TranslateTransform; rectangle.Fill = brush; }; pages.Add(_page); } return pages; }
async private void MyMap_OnLoaded(object sender, RoutedEventArgs e) { Geolocator locator = new Geolocator(); locator.ReportInterval = 2000; locator.MovementThreshold = 1; locator.PositionChanged += (sender2, args) => { Geoposition pos = args.Position; string la = pos.Coordinate.Point.Position.Latitude.ToString(); string lo = pos.Coordinate.Point.Position.Longitude.ToString(); string ac = pos.Coordinate.Accuracy.ToString(); apiSetLocation(la, lo, ac); }; myMap = (MapControl)sender; myMap.Center = new Geopoint(new BasicGeoposition() { Altitude = 643, Latitude = 43.089863, Longitude = -77.669609 }); myMap.ZoomLevel = 14; IEnumerable<Location> locations = await SampleDataSource.GetLocationsAsync(); foreach (Location location in locations) { Double la = Convert.ToDouble(location.Latitude); Double lo = Convert.ToDouble(location.Longitude); Double al = 643; Geopoint pt = new Geopoint(new BasicGeoposition() { Latitude = la, Longitude = lo, Altitude = al }); Windows.UI.Xaml.Shapes.Rectangle fence2 = new Windows.UI.Xaml.Shapes.Rectangle(); fence2.Name = location.Email; fence2.Tapped += fence_Tapped; fence2.Width = 30; fence2.Height = 30; BitmapImage img2 = new BitmapImage(new Uri("ms-appx:///Assets/redpin.png")); fence2.Fill = new ImageBrush() { ImageSource = img2 }; myMap.Children.Add(fence2); MapControl.SetLocation(fence2, pt); MapControl.SetNormalizedAnchorPoint(fence2, new Point(1.0, 0.5)); } }
private void oneTimeInit() { if (hasInitialized) return; if (_bkgLayer == null) _bkgLayer = GetTemplateChild("bkgLayer") as EffectLayer.EffectLayer; if (_butRoot == null) _butRoot = GetTemplateChild("butRoot") as Button; if (_butRoot != null) { _butRoot.Click += _butRoot_Click; _butRoot.PointerEntered += _butRoot_PointerEntered; _butRoot.PointerExited += _butRoot_PointerExited; } if (_bkgLayer != null && _butRoot != null && _butRoot.ActualWidth != 0) _bkgLayer.InitLayer(_butRoot.ActualWidth, _butRoot.ActualHeight); if (_tbContent == null) _tbContent = GetTemplateChild("tbContent") as TextBlock; if (_xuiIco == null) _xuiIco = GetTemplateChild("xuiIco") as X.UI.Path.Path; if (_grdTooltip == null) _grdTooltip = GetTemplateChild("grdTooltip") as Grid; if (_grdTTContainer == null) _grdTTContainer = GetTemplateChild("grdTTContainer") as Grid; if (_rect == null) _rect = GetTemplateChild("rect") as Windows.UI.Xaml.Shapes.Rectangle; if (_bkgLayer != null) hasInitialized = true; }