Наследование: Shape, IRectangle
Пример #1
0
       // Image io=

        public main1()
        {
            this.InitializeComponent();
            this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
            canvas.PointerMoved += canvas_pointer_moved;
            canvas.PointerPressed += canvas_pointer_pressed;
            canvas.PointerExited += canvas_pointer_exited;
            canvas.PointerReleased += canvas_pointer_released;
            tool = "pencil";
            FillColor = Colors.Blue;
            BorderColor = Colors.Black;
            var colors = typeof(Colors).GetTypeInfo().DeclaredProperties;
            
            foreach (var item in colors)
            {
                //ImageBrush i= i
                Rectangle r = new Rectangle();
                //r.Fill=I
             
                //fill.Items.Add(item);
                
            }


            for (int i = 1; i < 20; i++)
            {
                ComboBoxItem Items = new ComboBoxItem();
                Items.Content = i;
                thick.Items.Add(Items);
            }
            thick.SelectedIndex = 0;

            

        }
Пример #2
0
        protected override void OnApplyTemplate()
        {
            // Find the left pane in the control template and store a reference
            LeftPanePresenter = GetTemplateChild("leftPanePresenter") as ContentPresenter;
            MainPaneRectangle = GetTemplateChild("mainPaneRectangle") as Rectangle;
            var mainToggleButton = GetTemplateChild("toggleButtonHamburgerMenu") as ToggleButton;
            var sideToggleButton = XamlHelper.GetChildrenOfType<ToggleButton>(LeftPanePresenter.Content as StackPanel).FirstOrDefault();

            if (MainPaneRectangle != null)
            {
                MainPaneRectangle.Tapped += (sender, e) => { IsLeftPaneOpen = false; };
            }

            // Ensure that the TranslateX on the RenderTransform of the left pane is set to the negative value of the left pa
            SetLeftPanePresenterX();

            // Set open/close for the sidebar
            if(mainToggleButton != null)
            {
                mainToggleButton.Click += OpenSidebar;
            }

            if (sideToggleButton != null)
            {
                sideToggleButton.Click += CloseSidebar;
            }

            base.OnApplyTemplate();
        }
Пример #3
0
        private void CreateGrid()
        {
            int rectSize = (int)theCanvas.Width / model.GridSize;

            for (int r = 0; r < model.GridSize; r++)
            {
                for (int c = 0; c < model.GridSize; c++)
                {
                    Rectangle rect = new Rectangle();

                    SolidColorBrush black = new SolidColorBrush(Windows.UI.Colors.Gray);

                    rect.Fill   = black;
                    rect.Width  = rectSize + 1;
                    rect.Height = rect.Width + 1;
                    rect.Stroke = black;

                    rect.Tag = new Point(r, c);

                    rect.Tapped += Rect_Tapped;

                    Canvas.SetTop(rect, r * rectSize);
                    Canvas.SetLeft(rect, c * rectSize);

                    theCanvas.Children.Add(rect);
                }
            }
        }
        private void CreateGrid()
        {
            // Remove all previously-existing rectangles
            paintCanvas.Children.Clear();

            grid = new bool[gridWidth, gridWidth];
            int rectSize = (int)paintCanvas.Width / gridWidth;

            SolidColorBrush black = new SolidColorBrush(Colors.Black);
            SolidColorBrush white = new SolidColorBrush(Colors.White);

            // Turn entire grid on and create rectangles to represent it
            for (int r = 0; r < gridWidth; r++)
                for (int c = 0; c < gridWidth; c++)
                {
                    grid[r, c] = true;

                    Rectangle rect = new Rectangle();
                    rect.Fill = white;
                    rect.Width = rectSize + 1;
                    rect.Height = rect.Width + 1;
                    rect.Stroke = black;

                    int x = c * rectSize;
                    int y = r * rectSize;

                    Canvas.SetTop(rect, y);
                    Canvas.SetLeft(rect, x);

                    // Add the new rectangle to the canvas' children
                    paintCanvas.Children.Add(rect);
                }
        }
Пример #5
0
        private void DrawGrid()
        {
            int             index = 0;
            SolidColorBrush black = new SolidColorBrush(Windows.UI.Colors.Gray);
            SolidColorBrush white = new SolidColorBrush(Windows.UI.Colors.White);

            for (int r = 0; r < model.GridSize; r++)
            {
                for (int c = 0; c < model.GridSize; c++)
                {
                    Rectangle rect = theCanvas.Children[index] as Rectangle;
                    index++;

                    if (model.GetGridValue(r, c))
                    {
                        rect.Fill   = white;
                        rect.Stroke = black;
                    }
                    else
                    {
                        rect.Fill   = black;
                        rect.Stroke = white;
                    }
                }
            }
        }
Пример #6
0
        public static UIElement StarControlFactory(double scale)
        {
            // Draw star shape
            Array starShapes = Enum.GetValues(typeof(StarShape));
            StarShape randomShape = (StarShape)starShapes.GetValue(_random.Next(0, starShapes.Length));

            UIElement starControl; //ISSUE: Is this type good?

            switch (randomShape)
            {
                case StarShape.Rectangle:
                    starControl = new Rectangle()
                    {Fill = new SolidColorBrush(RandomColor()) };

                    break;
                case StarShape.Ellipse:
                    starControl = new Ellipse()
                    { Fill = new SolidColorBrush(RandomColor()) };
                    break;
                case StarShape.Star:
                    starControl = new Star()
                    { Fill = new SolidColorBrush(RandomColor()) };
                    break;
                default:
                    starControl = new Star()
                    { Fill = new SolidColorBrush(RandomColor()) };
                    break;
            }

            return starControl;
        }
Пример #7
0
		private void RefreshCanvas()
		{
			_mainCanvas.Children.Clear();
			var mainImage = new Image() { Source = _viewModel.Image };
			mainImage.PointerPressed += MainImage_PointerPressed;
			_mainCanvas.Children.Add(mainImage);
			foreach (var frame in _viewModel.Frames)
			{
				var frameRectangle = new Rectangle()
				{
					Width = frame.Width,
					Height = frame.Height,
					Stroke = new SolidColorBrush()
					{
						Color = Colors.White,
					},
				};
				frameRectangle.SetValue(Canvas.LeftProperty, frame.X);
				frameRectangle.SetValue(Canvas.TopProperty, frame.Y);
				_mainCanvas.Children.Add(frameRectangle);
				if (frame.Image != null)
				{
					var frameImage = new Image()
					{
						Width = frame.Width,
						Height = frame.Height,
						Source = frame.Image,
					};
					frameImage.SetValue(Canvas.LeftProperty, frame.X);
					frameImage.SetValue(Canvas.TopProperty, frame.Y);
					_mainCanvas.Children.Add(frameImage);
				}
			}
		}
 private void AddHand(Rectangle hand)
 {
     if (!face.Children.Contains(hand))
     {
         face.Children.Add(hand);
     }
 }
Пример #9
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ProgressTrackRect = GetTemplateChild("ProgressTrackRect") as Rectangle;
            HorizontalTrackRect = GetTemplateChild("HorizontalTrackRect") as Rectangle;
        }
Пример #10
0
        public ColorList1Page() {
            this.InitializeComponent();

            IEnumerable<PropertyInfo> properties = typeof(Colors).GetTypeInfo().DeclaredProperties;

            foreach (PropertyInfo property in properties) {
                Color clr = (Color)property.GetValue(null);

                StackPanel vertStackPanel = new StackPanel { VerticalAlignment = VerticalAlignment.Center };
                TextBlock txtblkName = new TextBlock {
                    Text = property.Name,
                    FontSize = 24 };
                TextBlock txtblkRgb = new TextBlock {
                    Text = String.Format("{0:X2}-{1:X2}-{2:X2}-{3:X2}", clr.A, clr.R, clr.G, clr.B),
                    FontSize = 18
                };
                vertStackPanel.Children.Add(txtblkName);
                vertStackPanel.Children.Add(txtblkRgb);

                StackPanel horzStackPanel = new StackPanel { Orientation = Orientation.Horizontal };
                Rectangle rectangle = new Rectangle {
                    Width = 72,
                    Height = 72,
                    Fill = new SolidColorBrush(clr),
                    Margin = new Thickness(6)
                };
                horzStackPanel.Children.Add(rectangle);
                horzStackPanel.Children.Add(vertStackPanel);
                stackPanel.Children.Add(horzStackPanel);

            }

        }
Пример #11
0
        public TileRenderer(Canvas canvas, string displayText, Tile tile)
        {
            storyboard = new Storyboard();
            Tile = tile;
            this.canvas = canvas;
            Width = DefaultWidth;
            Height = DefaultHeight;
            rectangle = new Rectangle
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Stroke = new SolidColorBrush(Colors.Black),
                Fill = new SolidColorBrush(Colors.WhiteSmoke)
            };
            Children.Add(rectangle);

            text = new TextBlock
            {
                Text = displayText,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                TextAlignment = TextAlignment.Center,
                FontSize = 36,
                Foreground = new SolidColorBrush(Colors.Black),
                FontWeight = FontWeights.Bold,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, 26, 0, 26)

            };

            Children.Add(text);
            canvas.Children.Add(this);
            SetPosition();
            tile.PositionChanged += UpdatePosition;
        }
 /// override IGraphics 的 DrawRectangle,畫 rectangle
 public void DrawRectangle(Point startPoint, Point endPoint)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = GetRectangle(startPoint, endPoint);
     rectangle.Fill   = new SolidColorBrush(Colors.Yellow);
     rectangle.Stroke = new SolidColorBrush(Colors.Black);
     _canvas.Children.Add(rectangle);
 }
Пример #13
0
        private void Activate(Point2D item)
        {
            if (Map == null || Map.Layers == null)
            {
                return;
            }
            DrawLayer = new ElementsLayer();
            Map.Layers.Add(DrawLayer);
            rectangle = new Rectangle();
            rectangle.Stroke = this.Stroke;
            rectangle.StrokeThickness = this.StrokeThickness;
            rectangle.StrokeMiterLimit = this.StrokeMiterLimit;
            rectangle.StrokeDashOffset = this.StrokeDashOffset;
            rectangle.StrokeDashArray = this.StrokeDashArray;
            rectangle.StrokeDashCap = this.StrokeDashCap;
            rectangle.StrokeEndLineCap = this.StrokeEndLineCap;
            rectangle.StrokeLineJoin = this.StrokeLineJoin;
            rectangle.StrokeStartLineCap = this.StrokeStartLineCap;
            rectangle.Opacity = this.Opacity;
            rectangle.Fill = this.Fill;

            rectangle.SetValue(ElementsLayer.BBoxProperty , new Rectangle2D(item , item));
            DrawLayer.Children.Add(rectangle);

            isActivated = true;
            isDrawing = true;
        }
Пример #14
0
        private void HighlightDetectedFacesWithEmotions(Emotion[] faces)
        {
            // Remove any existing rectangles from previous events
            FacesCanvas.Children.Clear();

            // For each detected face
            for (int i = 0; i < faces?.Length; i++)
            {
                Emotion face = faces[i];
                // Face coordinate units are preview resolution pixels, which can be a different scale from our display resolution, so a conversion may be necessary
                Windows.UI.Xaml.Shapes.Rectangle faceBoundingBox = ConvertPreviewToUiRectangle(face.FaceRectangle);

                // Set bounding box stroke properties
                faceBoundingBox.StrokeThickness = 2;

                // Highlight the first face in the set
                faceBoundingBox.Stroke = (i == 0 ? new SolidColorBrush(Colors.Blue) : new SolidColorBrush(Colors.DeepSkyBlue));

                // Add grid to canvas containing all face UI objects
                FacesCanvas.Children.Add(faceBoundingBox);
                var left   = Canvas.GetLeft(faceBoundingBox);
                var bottom = Canvas.GetTop(faceBoundingBox) + faceBoundingBox.Height;
                var k      = 0;
                var scores = face.Scores;
                foreach (PropertyInfo pI in scores.GetType().GetProperties())
                {
                    var score = (float)pI.GetValue(scores);
                    FacesCanvas.Children.Add(CreateText($"{pI.Name}: {score.ToString("0.00")}", left, bottom + 20 * k, 20));
                    k++;
                }
            }

            // Update the face detection bounding box canvas orientation
            SetFacesCanvasRotation();
        }
		protected override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			Body = GetTemplateChild(BodyName) as Grid;

			_horizontalSlider = GetTemplateChild(HorizontalSliderName) as SuperSlider;
			_verticalSlider = GetTemplateChild(VerticalSliderName) as SuperSlider;

			_horizontalSelectedColor = GetTemplateChild(HorizontalSelectedColorName) as Rectangle;
			_verticalSelectedColor = GetTemplateChild(VerticalSelectedColorName) as Rectangle;

			if (_horizontalSlider != null)
				_horizontalSlider.ApplyTemplate();

			if (_verticalSlider != null)
				_verticalSlider.ApplyTemplate();

			if (Color.A == 0 && Color.R == 0 && Color.G == 0 && Color.B == 0)
				Color = Windows.UI.Color.FromArgb(255, 6, 255, 0); // this should be theme accent brush I think.
			else
				UpdateLayoutBasedOnColor();

			if (Thumb == null)
				Thumb = new ColorSliderThumb();

			IsEnabledVisualStateUpdate();
		}
Пример #16
0
 // 畫矩形
 public void DrawRectangle(double x1, double y1, double x2, double y2)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = LinkPointToRectangle(x1, y1, x2, y2);
     rectangle.Stroke = new SolidColorBrush(Colors.Black);
     rectangle.Fill   = new SolidColorBrush(Windows.UI.Colors.Aqua);
     _canvas.Children.Add(rectangle);
 }
Пример #17
0
        /// <summary>
        /// Builds the visual tree for the ColorPicker control when the template is applied. 
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            m_rootElement = GetTemplateChild("RootElement") as Panel;
            m_hueMonitor = GetTemplateChild("HueMonitor") as Rectangle;
            m_sampleSelector = GetTemplateChild("SampleSelector") as Canvas;
            m_hueSelector = GetTemplateChild("HueSelector") as Canvas;
            m_selectedColorView = GetTemplateChild("SelectedColorView") as Rectangle;
            m_colorSample = GetTemplateChild("ColorSample") as Rectangle;
            m_hexValue = GetTemplateChild("HexValue") as TextBlock;


            m_rootElement.RenderTransform = m_scale = new ScaleTransform();

            m_hueMonitor.PointerPressed += m_hueMonitor_PointerPressed;
            m_hueMonitor.PointerReleased += m_hueMonitor_PointerReleased;
            m_hueMonitor.PointerMoved += m_hueMonitor_PointerMoved;

            m_colorSample.PointerPressed += m_colorSample_PointerPressed;
            m_colorSample.PointerReleased += m_colorSample_PointerReleased;
            m_colorSample.PointerMoved += m_colorSample_PointerMoved;

            m_sampleX = m_colorSample.Width;
            m_sampleY = 0;
            m_huePos = 0;

            UpdateVisuals();
        }
Пример #18
0
        public override Rectangle Render()
        {
            Rectangle rectangle = new Rectangle();

            //rectangle.ManipulationMode = ManipulationModes.All;
            //rectangle.ManipulationDelta += rectangle_ManipulationDelta;
            //rectangle.Tapped += rectangle_Tapped;

            ParentCanvas.ManipulationMode = ManipulationModes.All;
            ParentCanvas.ManipulationDelta += rectangle_ManipulationDelta;
            ParentCanvas.Tapped += rectangle_Tapped;

            rectangle.StrokeThickness = 3;
            rectangle.Height = Utility.SPRITE_HEIGHT;
            rectangle.Width = Utility.SPRITE_WIDTH;
            _participant = rectangle;

            ImageBrush ib = new ImageBrush();
            ib.ImageSource = new BitmapImage(new Uri("ms-appx:/Assets/ship 90x60.png", UriKind.RelativeOrAbsolute));
            _participant.Fill = ib;
            _participant.SetValue(Canvas.LeftProperty, _position.X);
            _participant.SetValue(Canvas.TopProperty, _position.Y);

            return _participant;
        }
Пример #19
0
 protected override void OnApplyTemplate()
 {
     if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
         return;
     Indicator = GetTemplateChild(nameof(Indicator)) as Rectangle;
     if (Indicator == null)
         throw new NullReferenceException(nameof(Indicator));
 }
Пример #20
0
 public InfoView()
     :base( "InfoView", "BookInfoSection" )
 {
     Rectangle Rect = new Rectangle();
     Rect.Height = Height;
     Rect.Width = Width;
     Rect.Fill = new SolidColorBrush( Properties.APPEARENCE_THEME_MINOR_BACKGROUND_COLOR );
     Children.Add( Rect );
 }
Пример #21
0
 public static Rectangle CreateBorder()
 {
     var rectangle = new Rectangle();
     rectangle.Stroke = new SolidColorBrush(Color.FromArgb(100, 174, 169, 169));
     rectangle.StrokeThickness = 2;
     rectangle.Height = 2 * Utility.MARGIN + Utility.WORLD_HEIGHT * Utility.SPRITE_WIDTH;
     rectangle.Width = 2 * Utility.MARGIN + Utility.WORLD_WIDTH * Utility.SPRITE_WIDTH;
     return rectangle;
 }
Пример #22
0
 public MainPage()
 {
     this.InitializeComponent();
     _gameBoard = new GameBoard(5, 5, PlayArea);
     _gameBoard.UpdateTiles();
     _selectionSquare = BuildSelectionSquare();
     PlayArea.Children.Add(_selectionSquare);
     _clickedPoint = EmptyPoint;
 }
Пример #23
0
 public PaletteRect(Rectangle rOuter, Rectangle rInner, int i, ColorPicker p)
 {
     OuterRect = rOuter;
     InnerRect = rInner;
     _color = ((SolidColorBrush)OuterRect.Fill).Color;
     index = i;
     Picker = p;
     InnerRect.PointerPressed += InnerRect_Selected;
 }
Пример #24
0
 public GamePiece()
 {
     Rectangle rectangle = new Rectangle();
     rectangle.Width = 50;
     rectangle.Height = 50;
     rectangle.Fill = _colorBrushOn;
     _rectangle = rectangle;
     _on = true;
 }
Пример #25
0
        public async Task GetWebPages(double printHeight)
        {
            //h:998.485714
            double heightSplit = 998.485714;
            var    _PageCount  = printHeight / heightSplit;

            _PageCount = _PageCount + ((_PageCount > (int)_PageCount) ? 1 : 0);
            StorageFile printImg = await ApplicationData.Current.LocalFolder.GetFileAsync("Print.png");

            // create the pages
            var _Pages = new List <FrameworkElement>();

            for (int i = 0; i < (int)_PageCount; i++)
            {
                StackPanel pagePanel = new StackPanel()
                {
                    Orientation = Orientation.Vertical
                };
                TextBlock header = new TextBlock
                {
                    Text                = "Ritchie's Uniform Civil Procedure NSW / Civil Procedure Act 2005 / [ss 64–73] DIVISION 3 OTHER POWERS OF COURT",
                    FontSize            = 10,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Margin              = new Thickness(18)
                };

                TextBlock footer = new TextBlock
                {
                    Text                = string.Format("Currency date: 20 Apr 2015 © 2015 LexisNexis Printed page {0}", i + 1),
                    FontSize            = 10,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Bottom,
                    Margin              = new Thickness(18)
                };
                ImageBrush imgBrush = new ImageBrush();
                imgBrush.ImageSource = await GetCroppedBitmapAsync(printImg, new Point(0, i *heightSplit), new Size(704, heightSplit), 1);

                var _Page = new Windows.UI.Xaml.Shapes.Rectangle
                {
                    Height              = heightSplit,
                    Width               = 704,
                    Fill                = imgBrush,
                    Stretch             = Stretch.Fill,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center
                };
                pagePanel.Children.Add(header);
                pagePanel.Children.Add(_Page);
                pagePanel.Children.Add(footer);
                Viewbox layout = new Viewbox();
                layout.Child = pagePanel;
                _Pages.Add(layout);
            }
            Pages = _Pages;
        }
Пример #26
0
 internal static FrameworkElement RectangleControlFactory(Model.Rectangle rectangle)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangleControl = new Windows.UI.Xaml.Shapes.Rectangle();
     rectangleControl.Stroke = new SolidColorBrush(Colors.Black);
     rectangleControl.Fill   = new SolidColorBrush(Colors.Transparent);
     rectangleControl.Width  = rectangle.Area.Width;
     rectangleControl.Height = rectangle.Area.Height;
     SetCanvasLocation(rectangleControl, rectangle.Start.X, rectangle.Start.Y, 100);
     return(rectangleControl);
 }
Пример #27
0
 // Draw Rectangle
 public void DrawRectangle(double x1, double y1, 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(x1, y1, x1 + width, y1 + height);
     rectangle.Fill   = new SolidColorBrush(Colors.Yellow);
     rectangle.Stroke = new SolidColorBrush(Colors.Black);
     _canvas.Children.Add(rectangle);
 }
Пример #28
0
 //
 public void DrawRectangle(Boundary rectangleBoundary)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
     rectangle.Width  = rectangleBoundary.Width;
     rectangle.Height = rectangleBoundary.Height;
     Canvas.SetLeft(rectangle, rectangleBoundary.X);
     Canvas.SetTop(rectangle, rectangleBoundary.Y);
     rectangle.Stroke = new SolidColorBrush(Colors.BurlyWood);
     _canvas.Children.Add(rectangle);
 }
Пример #29
0
        public CodeAnimator(CodeDelegate del)
            : base(new Rectangle())
        {
            _delegate = del;
            _elem = new Rectangle();

            _duration = new Duration(GetTimeSpan(1, OrSo.Tick));

            _reverse = false;
        }
Пример #30
0
 //draw a rectangle using windows store graphics
 protected override void DoDrawRectangle(Point topLeftPoint, Point bottomRightPoint)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
     rectangle.Fill = new SolidColorBrush(Colors.Green);
     rectangle.Width = bottomRightPoint.X - topLeftPoint.X;
     rectangle.Height = bottomRightPoint.Y - topLeftPoint.Y;
     Canvas.SetLeft(rectangle, topLeftPoint.X);
     Canvas.SetTop(rectangle, topLeftPoint.Y);
     _canvas.Children.Add(rectangle);
 }
Пример #31
0
 private Rectangle BuildSelectionSquare()
 {
     Rectangle rectangle = new Rectangle();
     rectangle.Opacity = 0.5;
     rectangle.Width = 50;
     rectangle.Height = 50;
     rectangle.Stroke = new SolidColorBrush(Colors.Wheat);
     rectangle.StrokeThickness = 2;
     rectangle.Visibility = Visibility.Collapsed;
     return rectangle;
 }
        // 劃出標示線
        private void DrawMarkLines(DrawingModel.Point startPoint, DrawingModel.Point endPoint)
        {
            DoubleCollection dashCollection = new DoubleCollection();

            dashCollection.Add(Constant.TWO);
            dashCollection.Add(Constant.TWO);
            Windows.UI.Xaml.Shapes.Rectangle rectangle = GetRectangle(startPoint, endPoint);
            rectangle.StrokeDashArray = dashCollection;
            rectangle.Stroke          = new SolidColorBrush(Colors.Red);
            _canvas.Children.Add(rectangle);
        }
Пример #33
0
 //draw a border using windows store graphics
 protected override void DoBorderRectangle(Point topLeftPoint, Point bottomRightPoint)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
     rectangle.Width = bottomRightPoint.X - topLeftPoint.X;
     rectangle.Height = bottomRightPoint.Y - topLeftPoint.Y;
     rectangle.StrokeThickness = 2;
     rectangle.Stroke = new SolidColorBrush(Colors.Black);
     Canvas.SetLeft(rectangle, topLeftPoint.X);
     Canvas.SetTop(rectangle, topLeftPoint.Y);
     _canvas.Children.Add(rectangle);
 }
        protected override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			_rect1 = GetTemplateChild( "Rect1" ) as Rectangle;
			_rect2 = GetTemplateChild( "Rect2" ) as Rectangle;
			_rect3 = GetTemplateChild( "Rect3" ) as Rectangle;
            _rect5 = GetTemplateChild( "Rect4" ) as Rectangle;

			SetRectangles( (int) Value );
		}
Пример #35
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var line = new Rectangle
     {
         MinWidth = double.MaxValue,
         MinHeight = 1,
         Fill = new SolidColorBrush(Colors.Gray),
         Margin = new Thickness(0, 5, 0, 5)
     };
     parent.Add(line);
 }
Пример #36
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            PivotItem pi = new PivotItem();

            Rectangle r = new Rectangle();
            r.Fill = new SolidColorBrush(Colors.Turquoise);
            r.Margin = new Thickness(0, 0, 0, 0);

            pi.Content = r;
            BleepBloop.Items.Add(pi);
        }
        public void MonitorControl(Panel panel)
        {
            Monitor = new Rectangle {Fill = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0))};
			Monitor.SetValue(Grid.RowSpanProperty, int.MaxValue - 1);
			Monitor.SetValue(Grid.ColumnSpanProperty, int.MaxValue - 1);

	        Monitor.ManipulationMode = ManipulationModes.All;
			Monitor.ManipulationStarted += MonitorManipulationStarted;
			Monitor.ManipulationDelta += MonitorManipulationDelta;

            panel.Children.Add(Monitor);
        }
Пример #38
0
        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Method initializes and sets background appearance
        /// </summary>
        private void InitializeBackground()
        {
            background        = new UIX.Shapes.Rectangle();
            background.Margin = new UIX.Thickness(0);

            backgroundBorder = new Border();
            Color borderColor = Colors.White;

            backgroundBorder.BorderBrush     = new UIX.Media.SolidColorBrush(borderColor);
            backgroundBorder.BorderThickness = new UIX.Thickness(2);
            backgroundBorder.Child           = background;
        }
        public static async Task FlyoutOpenAsync(Rectangle webViewRect, WebView webView)
        {
            var b = new WebViewBrush();
            b.SourceName = webView.Name;
            b.Redraw();

            webViewRect.Fill = b;

            await Task.Delay(100);

            webView.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }
Пример #40
0
        public override object GetCoreInstance()
        {
            var rectangle = new Rectangle
            {
                Fill = new SolidColorBrush(Colors.Red),
                Opacity = 0.5,
                Width = CanvasItem.Width,
                Height = CanvasItem.Height,
            };

            return rectangle;
        }      
Пример #41
0
 private void temp()
 {
     MainGrid.Children.Clear();
     MainGrid.ColumnDefinitions.Clear();
     MainGrid.RowDefinitions.Clear();
     MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(CellWidth) });
     MainGrid.RowDefinitions.Add(new RowDefinition());
     TextBlock block = null;
     for (int x = 0; x < Columns.Count + 1; x++)
     {
         for (int y = 0; y < Rows.Count + 1; y++)
         {
             Rectangle rect = new Rectangle() { Fill = ((y) / 2 == (double)(y) / 2.0) ? new SolidColorBrush(Color.FromArgb(255, 56, 56, 56)) : new SolidColorBrush(Color.FromArgb(255, 64, 64, 64)), Margin = new Thickness(0,0,1,0) };
             Grid.SetColumn(rect, x);
             Grid.SetRow(rect, y);
             MainGrid.Children.Add(rect);
             if (x == 0)
             {
                 if (y > 0)
                 {
                     string rowTitle = Rows[y - 1];
                     MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(CellHeight) });
                     bool sizeFound = false;
                     double candidateWidth = MainGrid.ColumnDefinitions[0].Width.Value;
                     double candidateHeight;
                     while (!sizeFound)
                     {
                         block = new TextBlock() { Text = rowTitle, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWholeWords, FontSize = 8, Margin = new Thickness(CellMargin) };
                         block.Measure(new Size(candidateWidth - CellMargin * 2, CellHeight * 2));
                         candidateHeight = block.ActualHeight;
                         block.Width = CellWidth;
                         if (candidateHeight <= CellHeight - CellMargin * 2)
                             sizeFound = true;
                         else
                             candidateWidth += 5;
                     }
                     block = new TextBlock() { Text = rowTitle, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWholeWords, FontSize = 8, Margin = new Thickness(CellMargin) };
                     MainGrid.ColumnDefinitions[0].Width = new GridLength(candidateWidth);
                     Grid.SetRow(block, y);
                     MainGrid.Children.Add(block);
                 }
             }
         }
         if (x > 0)
         {
             string columnTitle = Columns[x - 1];
             MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(CellWidth) });
             block = new TextBlock() { Text = columnTitle, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWholeWords, FontSize = 8, Margin = new Thickness(CellMargin) };
             Grid.SetColumn(block, x);
             MainGrid.Children.Add(block);
         }
     }
 }
        // 取得 rectangle
        private Windows.UI.Xaml.Shapes.Rectangle GetRectangle(Point startPoint, Point endPoint)
        {
            Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
            float  left   = (float)startPoint.GetSmallLeft(endPoint);
            float  top    = (float)startPoint.GetSmallTop(endPoint);
            double width  = startPoint.GetLeftDifference(endPoint);
            double height = startPoint.GetTopDifference(endPoint);

            rectangle.Margin = new Windows.UI.Xaml.Thickness(left, top, 0, 0);
            rectangle.Width  = width;
            rectangle.Height = height;
            return(rectangle);
        }
Пример #43
0
 // 畫矩形框
 public void DrawRectangleFrame(double x1, double y1, double x2, double y2)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = LinkPointToRectangle(x1, y1, x2, y2);
     rectangle.Stroke          = new SolidColorBrush(Colors.Red);
     rectangle.StrokeThickness = (int)3m;
     rectangle.StrokeDashArray = new DoubleCollection();
     rectangle.StrokeDashArray.Add(1);
     rectangle.StrokeDashArray.Add((int)2m);
     _canvas.Children.Add(rectangle);
     DrawAnglePoint(x1, y1);
     DrawAnglePoint(x2, y1);
     DrawAnglePoint(x1, y2);
     DrawAnglePoint(x2, y2);
 }
Пример #44
0
        private void SetupVisualizationQRCode(WriteableBitmap displaySource, IList <DetectedQRCode> foundFaces)
        {
            ImageBrush brush = new ImageBrush();

            brush.ImageSource = displaySource;
            brush.Stretch     = Stretch.Fill;
            this.FaceTrackingVisualizationCanvas.Background = brush;

            if (foundFaces != null)
            {
                double widthScale  = displaySource.PixelWidth / this.FaceTrackingVisualizationCanvas.ActualWidth;
                double heightScale = displaySource.PixelHeight / this.FaceTrackingVisualizationCanvas.ActualHeight;

                foreach (DetectedQRCode face in foundFaces)
                {
                    // Create a rectangle element for displaying the face box but since we're using a Canvas
                    // we must scale the rectangles according to the image's actual size.
                    // The original FaceBox values are saved in the Rectangle's Tag field so we can update the
                    // boxes when the Canvas is resized.
                    Windows.UI.Xaml.Shapes.Rectangle box = new Windows.UI.Xaml.Shapes.Rectangle();
                    box.Tag             = face.QRCodeBox;
                    box.Width           = (uint)(face.QRCodeBox.Width / widthScale);
                    box.Height          = (uint)(face.QRCodeBox.Height / heightScale);
                    box.Fill            = this.fillBrush;
                    box.Stroke          = this.lineBrush;
                    box.StrokeThickness = this.lineThickness;
                    box.Margin          = new Thickness((uint)(face.QRCodeBox.X / widthScale), (uint)(face.QRCodeBox.Y / heightScale), 0, 0);

                    this.FaceTrackingVisualizationCanvas.Children.Add(box);
                }
            }

            string message;

            if (foundFaces == null || foundFaces.Count == 0)
            {
                message = "Didn't find any QR Code(s) in the image";
            }
            else if (foundFaces.Count == 1)
            {
                message = "Found a QR Code in the image with Data " + foundFaces[0].QRCodeResult.Text;
            }
            else
            {
                message = "Found " + foundFaces.Count + " QR Codes in the image";
            }

            //this.rootPage.NotifyUser(message, NotifyType.StatusMessage);
        }
Пример #45
0
        //draw selected rectangle
        public void DrawSelectedRectangle(double x1, double y1, double x2, double y2)
        {
            double width;
            double height;

            height = Math.Abs(y1 - y2);
            width  = Math.Abs(x1 - x2);
            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(x1, y1, x2, y2);
            rectangle.Fill   = new SolidColorBrush(Colors.Yellow);
            rectangle.Stroke = new SolidColorBrush(Colors.Red);
            _canvas.Children.Add(rectangle);
        }
Пример #46
0
        // Draw Ellipse
        public void DrawDashRectangle(double x1, double y1, double width, double height)
        {
            const int DASH = 10;

            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(x1, y1, x1 + width, y1 + height);
            rectangle.Stroke          = new SolidColorBrush(Colors.Red);
            rectangle.StrokeDashArray = new DoubleCollection()
            {
                DASH
            };
            _canvas.Children.Add(rectangle);
        }
Пример #47
0
        /// <summary>
        /// GazeMoved handler translates the ellipse on the canvas to reflect gaze point.
        /// </summary>
        /// <param name="sender">Source of the gaze moved event</param>
        /// <param name="e">Event args for the gaze moved event</param>
        private void GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args)
        {
            // Update the position of the ellipse corresponding to gaze point.
            if (args.CurrentPoint.EyeGazePosition != null)
            {
                double gazePointX = args.CurrentPoint.EyeGazePosition.Value.X;
                double gazePointY = args.CurrentPoint.EyeGazePosition.Value.Y;

                double ellipseLeft =
                    gazePointX -
                    (eyeGazePositionEllipse.Width / 2.0f);
                double ellipseTop =
                    gazePointY -
                    (eyeGazePositionEllipse.Height / 2.0f) -
                    (int)Header.ActualHeight;

                // Translate transform for moving gaze ellipse.
                TranslateTransform translateEllipse = new TranslateTransform
                {
                    X = ellipseLeft,
                    Y = ellipseTop
                };

                eyeGazePositionEllipse.RenderTransform = translateEllipse;

                // The gaze point screen location.
                Windows.Foundation.Point gazePoint = new Windows.Foundation.Point(gazePointX, gazePointY);

                int    rectx    = ((int)gazePointX) / 100;
                int    recty    = (((int)gazePointY) / 25) - 4;
                string rectname = "rect" + rectx.ToString() + "_" + recty.ToString();
                try
                {
                    Windows.UI.Xaml.Shapes.Rectangle ele = hashtable[rectname];
                    // Basic hit test to determine if gaze point is on progress bar.
                    ele.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                }
                catch (Exception e)
                {
                    Console.WriteLine("IOException source: {0}, rectname {1}", e.Source, rectname);
                }



                // Mark the event handled.
                args.Handled = true;
            }
        }
Пример #48
0
        protected override void OnElementChanged(ElementChangedEventArgs <ShapeView> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            var converter = new ColorConverter();

            var color       = (SolidColorBrush)converter.Convert(Element.Color, null, null, null);
            var strockColor = (SolidColorBrush)converter.Convert(Element.StrokeColor, null, null, null);
            var margin      = new Thickness(Element.Padding.Left, Element.Padding.Top, Element.Padding.Right, Element.Padding.Bottom);

            switch (Element.ShapeType)
            {
            case ShapeType.Box:
                _rectangle = new Rectangle
                {
                    Fill            = color,
                    Stroke          = strockColor,
                    StrokeThickness = Element.StrokeWidth,
                    Margin          = margin,
                    RadiusX         = Element.CornerRadius,
                    RadiusY         = Element.CornerRadius,
                };
                SetNativeControl(_rectangle);
                break;

            case ShapeType.Circle:
                _ellipse = new Ellipse
                {
                    Fill            = color,
                    Stroke          = strockColor,
                    StrokeThickness = Element.StrokeWidth,
                    Margin          = margin
                };
                SetNativeControl(_ellipse);
                break;

            case ShapeType.CircleIndicator:
                // TODO WinPhone circle indicator
                break;
            }
        }
Пример #49
0
        public static void InitializeFrom(this Border nativeControl, RoundedBoxView formsControl)
        {
            if (nativeControl == null || formsControl == null)
            {
                return;
            }

            nativeControl.Height = formsControl.HeightRequest;
            nativeControl.Width  = formsControl.WidthRequest;
            nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
            nativeControl.UpdateBorderColor(formsControl.BorderColor);

            var rectangle = new Windows.UI.Xaml.Shapes.Rectangle();

            rectangle.InitializeFrom(formsControl);

            nativeControl.Child = rectangle;
        }
Пример #50
0
        private void Layout(ref Canvas canvas)
        {
            Ellipse rim = new Ellipse();

            canvas.Children.Clear();
            diameter = canvas.Width;
            double inner = diameter - 15;

            rim.Height          = diameter;
            rim.Width           = diameter;
            rim.Stroke          = RimBackground;
            rim.StrokeThickness = 20;
            canvas.Children.Add(rim);
            markers.Children.Clear();
            markers.Width  = inner;
            markers.Height = inner;
            for (int i = 0; i < 60; i++)
            {
                Windows.UI.Xaml.Shapes.Rectangle marker = new Windows.UI.Xaml.Shapes.Rectangle();
                marker.Fill = RimForeground;
                if ((i % 5) == 0)
                {
                    marker.Width           = 3;
                    marker.Height          = 8;
                    marker.RenderTransform = transformGroup(i * 6, -(marker.Width / 2),
                                                            -(marker.Height * 2 + 4.5 - rim.StrokeThickness / 2 - inner / 2 - 6));
                }
                else
                {
                    marker.Width           = 1;
                    marker.Height          = 4;
                    marker.RenderTransform = transformGroup(i * 6, -(marker.Width / 2),
                                                            -(marker.Height * 2 + 12.75 - rim.StrokeThickness / 2 - inner / 2 - 8));
                }
                markers.Children.Add(marker);
            }
            canvas.Children.Add(markers);
            face.Width  = diameter;
            face.Height = diameter;
            canvas.Children.Add(face);
            secondsHeight = (int)diameter / 2 - 20;
            minutesHeight = (int)diameter / 2 - 40;
            hoursHeight   = (int)diameter / 2 - 60;
        }
Пример #51
0
        private Windows.UI.Xaml.Shapes.Rectangle ConvertPreviewToUiRectangle(Microsoft.ProjectOxford.Common.Rectangle faceRectangle)
        {
            var result        = new Windows.UI.Xaml.Shapes.Rectangle();
            var previewStream = _previewProperties as VideoEncodingProperties;

            // If there is no available information about the preview, return an empty rectangle, as re-scaling to the screen coordinates will be impossible
            if (previewStream == null)
            {
                return(result);
            }

            // Similarly, if any of the dimensions is zero (which would only happen in an error case) return an empty rectangle
            if (previewStream.Width == 0 || previewStream.Height == 0)
            {
                return(result);
            }

            double streamWidth  = previewStream.Width;
            double streamHeight = previewStream.Height;

            // For portrait orientations, the width and height need to be swapped
            if (_displayOrientation == DisplayOrientations.Portrait || _displayOrientation == DisplayOrientations.PortraitFlipped)
            {
                streamHeight = previewStream.Width;
                streamWidth  = previewStream.Height;
            }

            // Get the rectangle that is occupied by the actual video feed
            var previewInUI = GetPreviewStreamRectInControl(previewStream, PreviewControl);

            // Scale the width and height from preview stream coordinates to window coordinates
            result.Width  = (faceRectangle.Width / streamWidth) * previewInUI.Width;
            result.Height = (faceRectangle.Height / streamHeight) * previewInUI.Height;

            // Scale the X and Y coordinates from preview stream coordinates to window coordinates
            var x = (faceRectangle.Left / streamWidth) * previewInUI.Width;
            var y = (faceRectangle.Top / streamHeight) * previewInUI.Height;

            Canvas.SetLeft(result, x);
            Canvas.SetTop(result, y);

            return(result);
        }
Пример #52
0
        Child GetChild(ChildType type)
        {
            while (nextChildIndex < children.Count && children[nextChildIndex].Type != type)
            {
                // TODO: This shape is out of order
                nextChildIndex++;
            }

            if (nextChildIndex >= children.Count)
            {
                FrameworkElement shape;
                switch (type)
                {
                case ChildType.Rectangle: shape = new Shapes.Rectangle(); break;

                case ChildType.Ellipse: shape = new Shapes.Ellipse(); break;

                case ChildType.Path: shape = new Shapes.Path(); break;

                case ChildType.Image: shape = new Image(); break;

                case ChildType.Text: shape = new TextBlock(); break;

                default: throw new NotSupportedException(type + " not supported");
                }
                var ch = new Child {
                    Type  = type,
                    Shape = shape,
                };
                children.Add(ch);
                nextChildIndex = children.Count;
                return(ch);
            }
            else
            {
                var ch = children[nextChildIndex];
                nextChildIndex++;
                return(ch);
            }
        }
Пример #53
0
 // 連矩形的點
 private Windows.UI.Xaml.Shapes.Rectangle LinkPointToRectangle(double x1, double y1, double x2, double y2)
 {
     Windows.UI.Xaml.Shapes.Rectangle rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
     rectangle.Width  = Math.Abs(x2 - x1);
     rectangle.Height = Math.Abs(y2 - y1);
     if (x2 > x1 && y2 > y1)
     {
         this.SetTopLeft(rectangle, y1, x1);
     }
     if (x2 < x1 && y2 > y1)
     {
         this.SetTopLeft(rectangle, y1, x2);
     }
     if (x2 > x1 && y2 < y1)
     {
         this.SetTopLeft(rectangle, y2, x1);
     }
     if (x2 < x1 && y2 < y1)
     {
         this.SetTopLeft(rectangle, y2, x2);
     }
     return(rectangle);
 }
Пример #54
0
        private async void Rect_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Rectangle rect   = sender as Rectangle;
            var       rowCol = (Point)rect.Tag;
            int       row    = (int)rowCol.X;
            int       col    = (int)rowCol.Y;

            model.Move(row, col);

            DrawGrid();

            if (model.IsGameOver())
            {
                MessageDialog msgDialog = new MessageDialog("Congratulations! You won.");
                msgDialog.Commands.Add(new UICommand("OK"));
                await msgDialog.ShowAsync();

                model.NewGame();
                DrawGrid();
            }

            e.Handled = true;
        }
Пример #55
0
        /// <summary>
        /// Iterates over all detected faces, creating and adding Rectangles to the FacesCanvas as face bounding boxes
        /// </summary>
        /// <param name="faces">The list of detected faces from the FaceDetected event of the effect</param>
        private void HighlightDetectedFaces(IReadOnlyList <DetectedFace> faces)
        {
            // Remove any existing rectangles from previous events
            FacesCanvas.Children.Clear();

            // For each detected face
            for (int i = 0; i < faces.Count; i++)
            {
                // Face coordinate units are preview resolution pixels, which can be a different scale from our display resolution, so a conversion may be necessary
                Windows.UI.Xaml.Shapes.Rectangle faceBoundingBox = ConvertPreviewToUiRectangle(faces[i].FaceBox);

                // Set bounding box stroke properties
                faceBoundingBox.StrokeThickness = 2;

                // Highlight the first face in the set
                faceBoundingBox.Stroke = (i == 0 ? new SolidColorBrush(Colors.Blue) : new SolidColorBrush(Colors.DeepSkyBlue));

                // Add grid to canvas containing all face UI objects
                FacesCanvas.Children.Add(faceBoundingBox);
            }

            // Update the face detection bounding box canvas orientation
            SetFacesCanvasRotation();
        }
Пример #56
0
        void IAstVisitor <ParsingContext> .Visit(TextNode node, ParsingContext context)
        {
            if (node.HasReferer)
            {
                {
                    var hyper = new Hyperlink();
                    Run run   = new Run()
                    {
                        Text = node.Text.Text
                    };
                    if (context.Colors.Count > 0)
                    {
                        run.Foreground = context.Colors.Peek();
                    }
                    hyper.Inlines.Add(run);
                    context.Stack.Peek().Inlines.Add(hyper);
                }

                if (node.Refer != null)
                {
                    var root = node.Refer;
                    var rtb  = new RichTextBlock();
                    rtb.Margin = new Thickness(8, 4, 8, 4);
                    var newContext = new ParsingContext(context.Level + 1);
                    if (context.Colors.Count > 0)
                    {
                        newContext.Colors.Push(context.Colors.Peek());
                    }
                    root.Accept(this, newContext);
                    newContext.Blocks.Trim();

                    foreach (var item in newContext.Blocks)
                    {
                        rtb.Blocks.Add(item);
                    }

                    var panel   = new InlineUIContainer();
                    var stretch = new StretchContentControl();
                    {
                        panel.Child = stretch;
                    }
                    var grid = new Grid();
                    {
                        grid.Style = (Style)Application.Current.Resources["RTBNestedGridStyle"];
                        grid.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = GridLength.Auto
                        });
                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        stretch.Content = grid;
                    }

                    {
                        var rect = new Rectangle();
                        rect.Style = (Style)Application.Current.Resources["RTBRectStyle"];
                        grid.Children.Add(rect);
                        Grid.SetColumn(rect, 0);
                    }

                    {
                        grid.Children.Add(rtb);
                        Grid.SetColumn(rtb, 1);
                    }



                    context.Stack.Peek().Inlines.Add(new LineBreak());
                    context.Stack.Peek().Inlines.Add(panel);
                }
                else
                {
                    context.Stack.Peek().Inlines.Add(new Run()
                    {
                        Text = " 引用解析失败", Foreground = new SolidColorBrush(Colors.Red)
                    });
                    context.Stack.Peek().Inlines.Add(new LineBreak());
                }
            }
            else
            {
                Run run = new Run()
                {
                    Text = node.Text.Text
                };
                if (context.Colors.Count > 0)
                {
                    run.Foreground = context.Colors.Peek();
                }
                context.Stack.Peek().Inlines.Add(run);
            }
        }
Пример #57
0
        public async Task <IEnumerable <FrameworkElement> > GetWebPages(WebView webView, Windows.Foundation.Size page)
        {
            // ask the content its width
            var widthString = await webView.InvokeScriptAsync("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 = await webView.InvokeScriptAsync("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?
            double scale        = page.Width / contentWidth;
            double scaledHeight = (contentHeight * scale);
            double 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 rectanglePage = new Windows.UI.Xaml.Shapes.Rectangle
                {
                    Height = page.Height,
                    Width  = page.Width,
                    Margin = new Thickness(5),
                    Tag    = new TranslateTransform {
                        Y = translateY
                    },
                };

                rectanglePage.Loaded += (async(s, e) =>
                {
                    var subRectangle = s as Windows.UI.Xaml.Shapes.Rectangle;
                    var subBrush = await GetWebViewBrush(webView);
                    subBrush.Stretch = Stretch.UniformToFill;
                    subBrush.AlignmentY = AlignmentY.Top;
                    subBrush.Transform = subRectangle.Tag as TranslateTransform;
                    subRectangle.Fill = subBrush;
                });

                pages.Add(rectanglePage);
            }

            return(pages);
        }
Пример #58
0
        private void DisplayFaces(Microsoft.ProjectOxford.Face.Contract.Face[] faces, bool init = true)
        {
            if (faces == null)
            {
                return;
            }
            MainCanvas.Children.Clear();
            var offset_h = 0.0; var offset_w = 0.0;
            var p  = 0.0;
            var d  = MainCanvas.ActualHeight / MainCanvas.ActualWidth;
            var d2 = size_image.Height / size_image.Width;

            if (d < d2)
            {
                offset_h = 0;
                offset_w = (MainCanvas.ActualWidth - MainCanvas.ActualHeight / d2) / 2;
                p        = MainCanvas.ActualHeight / size_image.Height;
            }
            else
            {
                offset_w = 0;
                offset_h = (MainCanvas.ActualHeight - MainCanvas.ActualWidth / d2) / 2;
                p        = MainCanvas.ActualWidth / size_image.Width;
            }

            if (faces != null)
            {
                int count = 1;
                //将face矩形显示到界面(如果有)
                foreach (var face in faces)
                {
                    Windows.UI.Xaml.Shapes.Rectangle rect = new Windows.UI.Xaml.Shapes.Rectangle();
                    rect.Width  = face.FaceRectangle.Width * p;
                    rect.Height = face.FaceRectangle.Height * p;
                    Canvas.SetLeft(rect, face.FaceRectangle.Left * p + offset_w);
                    Canvas.SetTop(rect, face.FaceRectangle.Top * p + offset_h);
                    rect.Stroke          = new SolidColorBrush(Colors.Orange);
                    rect.StrokeThickness = 3;

                    MainCanvas.Children.Add(rect);

                    TextBlock txt = new TextBlock();
                    txt.Foreground = new SolidColorBrush(Colors.Orange);
                    txt.Text       = "#" + count;
                    Canvas.SetLeft(txt, face.FaceRectangle.Left * p + offset_w);
                    Canvas.SetTop(txt, face.FaceRectangle.Top * p + offset_h - 20);
                    MainCanvas.Children.Add(txt);
                    count++;
                }
            }
            if (!init)
            {
                return;
            }
            faceDatas.Clear();
            faceDatas.Add(new FaceData()
            {
                Age = "年龄", Gender = "性别", Glasses = "眼镜", Index = "序号", Smile = "笑容"
            });
            int index = 1;

            foreach (var face in faces)
            {
                faceDatas.Add(
                    new FaceData()
                {
                    Index   = "#" + index++,
                    Age     = Math.Round(face.FaceAttributes.Age, 2).ToString(),
                    Gender  = face.FaceAttributes.Gender,
                    Glasses = face.FaceAttributes.Glasses.ToString(),
                    Smile   = face.FaceAttributes.Smile.ToString()
                });
            }
        }
Пример #59
0
 // 設定左上角座標
 private void SetTopLeft(Windows.UI.Xaml.Shapes.Rectangle rectangle, double top, double left)
 {
     Canvas.SetTop(rectangle, top);
     Canvas.SetLeft(rectangle, left);
 }
Пример #60
0
        ShapeData ConstructAndAddShape(TypeId typeId)
        {
            UIElement element;

            if (typeId == TypeId.Line)
            {
                var line = new Line {
                    StrokeEndLineCap   = PenLineCap.Round,
                    StrokeStartLineCap = PenLineCap.Round,
                };
                element = line;
            }
            else if (typeId == TypeId.Polyline)
            {
                var line = new Polyline {
                    StrokeEndLineCap   = PenLineCap.Round,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeLineJoin     = PenLineJoin.Round,
                };
                element = line;
            }
            else if (typeId == TypeId.Text)
            {
                element = new TextBlock();
            }
            else if (typeId == TypeId.Oval)
            {
                element = new Ellipse();
            }
            else if (typeId == TypeId.Arc)
            {
                element = new Path {
                    StrokeEndLineCap = PenLineCap.Round, StrokeStartLineCap = PenLineCap.Round,
                };
            }
            else if (typeId == TypeId.RoundedRect)
            {
                element = new Rectangle();
            }
            else if (typeId == TypeId.Rect)
            {
                element = new Rectangle();
            }
            else if (typeId == TypeId.Image)
            {
                element = new NativeImage();
            }
            else if (typeId == TypeId.Polygon)
            {
                element = new NativePolygon();
            }
            else
            {
                throw new NotSupportedException("Don't know how to construct: " + typeId);
            }

            var sd = new ShapeData {
                Element = element,
                TypeId  = typeId,
            };

            _shapes.Add(sd);

            //
            // Insert it in the right place so it gets drawn in the right order
            //
            if (_lastAddElementIndex >= 0)
            {
                _lastAddElementIndex++;
                _canvas.Children.Insert(_lastAddElementIndex, element);
            }
            else
            {
                if (_lastShape != null)
                {
                    _lastAddElementIndex = _canvas.Children.IndexOf(_lastShape.Element) + 1;
                    _canvas.Children.Insert(_lastAddElementIndex, element);
                }
                else
                {
                    _lastAddElementIndex = _canvas.Children.Count;
                    _canvas.Children.Add(element);
                }
            }

            return(sd);
        }