public void Draw(UIElementCollection children) { if (!isAlive) return; DateTime cur = DateTime.Now; foreach (var segment in segments) { PlayerUtils.Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { var circle = new Ellipse(); circle.Width = seg.radius * 2; circle.Height = seg.radius * 2; circle.SetValue(Canvas.LeftProperty, seg.x1 - seg.radius); circle.SetValue(Canvas.TopProperty, seg.y1 - seg.radius); circle.Stroke = brJoints; circle.StrokeThickness = 1; circle.Fill = brBones; children.Add(circle); } } // Remove unused players after 1/2 second. if (DateTime.Now.Subtract(lastUpdated).TotalMilliseconds > 500) isAlive = false; }
public void Draw(UIElementCollection children) { foreach (SingleVortex sv in reds) children.Add(sv); foreach (SingleVortex sv in blues) children.Add(sv); }
private static void AddPasswordBox( UIElementCollection labelCollection, UIElementCollection inputCollection, UIElementCollection checkBoxCollection, string content, object dataContext, string key, int index) { var viewModel = (INotifyPropertyChanged)dataContext; labelCollection.Add(new Label() { Content = content }); var control = new PasswordBox() { DataContext = dataContext, TabIndex = index }; var parameters = (IDictionary<string, string>)((dynamic)dataContext).Dictionary; control.Password = parameters[key]; PropertyChangedEventHandler onSourceChanged = (sender, e) => { if (e.PropertyName != key) { return; } if (control.Password == parameters[key]) { return; } control.Password = parameters[key]; }; viewModel.PropertyChanged += onSourceChanged; control.PasswordChanged += (sender, e) => { if (parameters[key] != control.Password) { parameters[key] = control.Password; } }; control.Unloaded += (sender, e) => viewModel.PropertyChanged -= onSourceChanged; inputCollection.Add(new UserControl() { Content = control }); checkBoxCollection.Add(new FrameworkElement()); }
public static void Draw(UIElementCollection children) { foreach (var option in selections) { var rect = new Rectangle(); rect.Width = option.intersection.Width; rect.Height = option.intersection.Height; rect.SetValue(Canvas.LeftProperty, option.intersection.X); rect.SetValue(Canvas.TopProperty, option.intersection.Y); rect.Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)); rect.StrokeThickness = 1; rect.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0)); children.Add(rect); option.Advance(); children.Add(option.label); } }
public static void AddRange(this UIElementCollection uIElementCollection, ICollection <System.Windows.Shapes.Polygon> uIElements) { var hashtable = new Hashtable(); foreach (var item in uIElements) { uIElementCollection.Add(item); } }
public static void AddRange(this UIElementCollection children, List <Line> lines) { if (lines != null) { foreach (var line in lines) { children.Add(line); } } }
private static void AddTextBox( UIElementCollection labelCollection, UIElementCollection inputCollection, UIElementCollection checkBoxCollection, string labelText, object dataContext, string key, int tabIndex) { labelCollection.Add(new Label() { Content = labelText }); var control = new TextBox() { DataContext = dataContext, TabIndex = tabIndex }; control.SetBinding(TextBox.TextProperty, new Binding(key)); inputCollection.Add(new UserControl() { Content = control }); checkBoxCollection.Add(new FrameworkElement()); }
public async Task NextFrame() { // PrevInteractedElement = InteractedElement; const int elmtsToTriggerCleanup = 100; const int elmtsToCleanup = 50; var undrawnElements = ImElements.Values.Where(elmt => elmt.ImState == ImElement.State.NotDrawn) .Take(elmtsToTriggerCleanup).ToList(); if (undrawnElements.Count == elmtsToTriggerCleanup) { foreach (var elmt in undrawnElements.Take(elmtsToCleanup)) { elmt.Unsubber(elmt.WpfElement, elmt.Handler); ImElements.Remove(elmt.ID); } } InteractedElementId = null; WpfElement[] sortedWpfElements = ImElements.Values.Where(x => x.ImState == ImElement.State.Drawn) .OrderBy(c => c.SortKey).Select(c => c.WpfElement).ToArray(); var wpfElementsChanged = DisplayedElements.Count != sortedWpfElements.Length || !Enumerable.Zip( DisplayedElements.OfType <WpfElement>(), sortedWpfElements, (c1, c2) => c1 == c2).All(b => b); if (wpfElementsChanged) { DisplayedElements.Clear(); foreach (var item in sortedWpfElements) { DisplayedElements.Add(item); } } // Automatically go to next frame for each requested redraw if (RemainingRedraws <= 0) { RemainingRedraws = 0; await TCS.Task; TCS = new TaskCompletionSource <bool>(); } else { RemainingRedraws--; } foreach (var elmt in ImElements.Values) { elmt.ImState = ImElement.State.NotDrawn; elmt.SortKey = 999999; } }
public TransitionPresenter() { _children = new UIElementCollection(this, null); ContentPresenter currentContent = new ContentPresenter(); _currentHost = new AdornerDecorator(); _currentHost.Child = currentContent; _children.Add(_currentHost); ContentPresenter previousContent = new ContentPresenter(); _previousHost = new AdornerDecorator(); _previousHost.Child = previousContent; }
public static void Draw(UIElementCollection children) { if (bannerText == null) return; Label text = bannerText.GetLabel(); if (text == null) { bannerText = null; return; } children.Add(text); }
public override void Draw(UIElementCollection collection) { Triangle triangle; if (DrawedElement == null) triangle = new Triangle(); else triangle = (Triangle)DrawedElement; UpdateProperties(triangle); LocateShapeOnCanvas(triangle); if (DrawedElement == null) collection.Add(triangle); DrawedElement = triangle; }
public override void Draw(UIElementCollection collection) { Heart heart; if (DrawedElement == null) heart = new Heart(); else heart = (Heart)DrawedElement; UpdateProperties(heart); LocateShapeOnCanvas(heart); if (DrawedElement == null) collection.Add(heart); DrawedElement = heart; }
public override void Draw(UIElementCollection collection) { RectangularCallout callout; if (DrawedElement == null) callout = new RectangularCallout(); else callout = (RectangularCallout)DrawedElement; UpdateProperties(callout); LocateShapeOnCanvas(callout); if (DrawedElement == null) collection.Add(callout); DrawedElement = callout; }
public override void Draw(UIElementCollection collection) { Arrow arrow; if (DrawedElement == null) arrow = new Arrow(); else arrow = (Arrow)DrawedElement; UpdateProperties(arrow); LocateShapeOnCanvas(arrow); if (DrawedElement == null) collection.Add(arrow); DrawedElement = arrow; }
public override void Draw(UIElementCollection collection) { Line line; if (DrawedElement == null) line = new Line(); else line = (Line)DrawedElement; UpdateProperties(line); if (DrawedElement == null) collection.Add(line); DrawedElement = line; }
public override void Draw(UIElementCollection collection) { Star star; if (DrawedElement == null) star = new Star(); else star = (Star)DrawedElement; UpdateProperties(star); LocateShapeOnCanvas(star); if (DrawedElement == null) collection.Add(star); DrawedElement = star; }
public override void Draw(UIElementCollection collection) { Ellipse ellipse; if (DrawedElement == null) ellipse = new Ellipse(); else ellipse = (Ellipse)DrawedElement; UpdateProperties(ellipse); LocateShapeOnCanvas(ellipse); if (DrawedElement == null) collection.Add(ellipse); DrawedElement = ellipse; }
public static void Draw(UIElementCollection children) { for (int i = 0; i < FlyingTexts.Count; i++) { FlyingText flyout = FlyingTexts[i]; if (flyout.alpha <= 0) { FlyingTexts.Remove(flyout); i--; } } foreach (var flyout in FlyingTexts) { flyout.Advance(); children.Add(flyout.label); } }
public HexGrid(UIElementCollection ui, Action<List<Point>> onSelected) { _i = this; this.real_r = GlobalConst.DEFAULT_r; this.real_a = 2.0 / Math.Sqrt(3) * real_r; this.worldOrigin = new Point(0, 0); this.ui = ui; selectableHex = new HexRender(DisplayType.FUNC_Selectable); ui.Add(selectableHex); this.onSelected = onSelected; hexPen = new Pen { Brush = Brushes.BlueViolet, Thickness = 2, StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round }; }
internal static void MakeVideoCall(string primaryId, UIElementCollection uiElementCollection, int timeoutInSeconds, string secondaryId = null) { CommunicationView commView = new CommunicationView(primaryId, timeoutInSeconds); uiElementCollection.Add(commView); commView.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; commView.VerticalAlignment = System.Windows.VerticalAlignment.Center; commView.Width = 700; commView.Height = 400; commView.CommunicationEnded += (p1, p2) => { if (commView.TimedOut && string.IsNullOrEmpty(secondaryId)==false) { commView.InitializeUI(secondaryId); secondaryId = null; return; } else { commView.Visibility = Visibility.Collapsed; uiElementCollection.Remove(commView); } }; }
public NewHighScore(UIElementCollection _gridChildren) { LinearGradientBrush myGradBrus = new LinearGradientBrush(Colors.DarkGreen, Colors.LightGray, new Point(.5, 0), new Point(.5, 1)); highscoreCanvas = new Canvas(); highscoreCanvas.Name = "NewHighScoreCanvas"; highscoreCanvas.Width = 600; highscoreCanvas.Height = 225; highscoreCanvas.VerticalAlignment = VerticalAlignment.Top; btnBack = new System.Windows.Controls.Button(); btnBack.Name = "HighScoreBack"; btnBack.Margin = new Thickness(6, 178, 0, 0); btnBack.Width = 135; btnBack.Height = 41; btnBack.Content = "Back"; btnBack.FontSize = 16; btnBack.FontWeight = FontWeights.Bold; btnBack.Background = myGradBrus; btnBack.Click += new RoutedEventHandler(btnBack_Click); btnDone = new System.Windows.Controls.Button(); btnDone.Name = "HighScoreDone"; btnDone.Margin = new Thickness(459, 178, 0, 0); btnDone.Width = 135; btnDone.Height = 41; btnDone.Content = "Done"; btnDone.FontSize = 16; btnDone.FontWeight = FontWeights.Bold; btnDone.Background = myGradBrus; btnDone.Click += new RoutedEventHandler(btnDone_Click); txtBoxinitials = new TextBox(); txtBoxinitials.Name = "HighScoreInitials"; txtBoxinitials.Height = 30; txtBoxinitials.Width = 125; txtBoxinitials.FontSize = 16; txtBoxinitials.VerticalContentAlignment = VerticalAlignment.Center; txtBoxinitials.Margin = new Thickness(237, 145, 0, 0); txtBoxinitials.Background = new SolidColorBrush(Colors.LightGray); allLetters = new Menu(highscoreCanvas.Children, "AllLetters"); atoe = new Menu(highscoreCanvas.Children, "AtoE"); ftoj = new Menu(highscoreCanvas.Children, "FtoJ"); ktoo = new Menu(highscoreCanvas.Children, "KtoO"); ptot = new Menu(highscoreCanvas.Children, "PtoT"); utoz = new Menu(highscoreCanvas.Children, "UtoZ"); allLetters.addButton(new Button("A - E"), MenuButton.Left); allLetters.addButton(new Button("F - J"), MenuButton.LeftCenter); allLetters.addButton(new Button("K - O"), MenuButton.Center); allLetters.addButton(new Button("P - T"), MenuButton.RightCenter); allLetters.addButton(new Button("U - Z"), MenuButton.Right); atoe.addButton(new Button("A"), MenuButton.Left); atoe.addButton(new Button("B"), MenuButton.LeftCenter); atoe.addButton(new Button("C"), MenuButton.Center); atoe.addButton(new Button("D"), MenuButton.RightCenter); atoe.addButton(new Button("E"), MenuButton.Right); ftoj.addButton(new Button("F"), MenuButton.Left); ftoj.addButton(new Button("G"), MenuButton.LeftCenter); ftoj.addButton(new Button("H"), MenuButton.Center); ftoj.addButton(new Button("I"), MenuButton.RightCenter); ftoj.addButton(new Button("J"), MenuButton.Right); ktoo.addButton(new Button("K"), MenuButton.Left); ktoo.addButton(new Button("L"), MenuButton.LeftCenter); ktoo.addButton(new Button("M"), MenuButton.Center); ktoo.addButton(new Button("N"), MenuButton.RightCenter); ktoo.addButton(new Button("O"), MenuButton.Right); ptot.addButton(new Button("P"), MenuButton.Left); ptot.addButton(new Button("Q"), MenuButton.LeftCenter); ptot.addButton(new Button("R"), MenuButton.Center); ptot.addButton(new Button("S"), MenuButton.RightCenter); ptot.addButton(new Button("T"), MenuButton.Right); utoz.addButton(new Button("U"), MenuButton.Left); utoz.addButton(new Button("V"), MenuButton.LeftCenter); utoz.addButton(new Button("W"), MenuButton.Center); utoz.addButton(new Button("Y"), MenuButton.RightCenter); utoz.addButton(new Button("Z"), MenuButton.Right); highscoreCanvas.Visibility = Visibility.Hidden; draw(); //Hide(allLetters); UnHide(allLetters); Hide(atoe); Hide(ftoj); Hide(ktoo); Hide(ptot); Hide(utoz); _gridChildren.Add(highscoreCanvas); initials = ""; btnBack.IsEnabled = false; backtimer = 0; donetimer = 0; }
public void DrawFrame(UIElementCollection children, Grid grid, Point currPos) { frameCount++; if (gameMode == Game.GameMode.Playing) { if (poseTimer.WedgeAngle < 360) { poseTimer.WedgeAngle += POSE_TIMER_INCREMENT_PER_FRAME; } else//The timer is done check the pose { if (DoThis) { invalidPose(); } else { validPose(); } } if (scores.Count != 0) { int i = 0; foreach (var score in scores) { Label label = MakeSimpleLabel("Score: " + score.Value.ToString(), new Rect(0.02, 0.02, .5 * sceneRect.Width, .5 * sceneRect.Height), new SolidColorBrush(Color.FromArgb(200, 255, 255, 255))); label.FontSize = Math.Max(1, Math.Min(sceneRect.Width / 12, sceneRect.Height / 12)); children.Add(label); i++; } } children.Add(gamePauseButton); children.Add(poseTimer); children.Add(Water); } else if (this.gameMode == Game.GameMode.Paused) { mainMenu.unhideMenu(); if (kssLeaderBoard.isVisible()) { kssLeaderBoard.draw(grid.Children); } children.Add(Water); children.Add(poseTimer); } else if (this.gameMode == Game.GameMode.Off) { Reset(); if (kssLeaderBoard.isVisible()) { kssLeaderBoard.draw(grid.Children); } } else if (this.gameMode == Game.GameMode.Ending) { if (scores.Count > 0) { foreach (var score in scores) { if (kinectHighScores.isHighScore(score.Value)) { highscoreMenu.ActivateHighScoreMenu(); highscoreMenu.inputHighScore(kinectHighScores, score.Value, grid, currPos, ref gameMode); } else { gameMode = Game.GameMode.Off; } } } else { gameMode = Game.GameMode.Off; } } }
public void DrawCursor(Point currPos, UIElementCollection children) { RightHand.Height = 15; RightHand.Width = 15; RightHand.Stroke = Brushes.Black; RightHand.Fill = Brushes.White; Canvas.SetLeft(RightHand, currPos.X); Canvas.SetTop(RightHand, currPos.Y); children.Add(RightHand); }
public void DrawFrame(UIElementCollection children) { frameCount++; // Draw all shapes in the scene for (int i = 0; i < things.Count; i++) { Thing thing = things[i]; if (thing.brush == null) { thing.brush = new SolidColorBrush(thing.color); double factor = 0.4 + ((double)thing.color.R + thing.color.G + thing.color.B) / 1600; thing.brush2 = new SolidColorBrush(Color.FromRgb((byte)(255 - (255 - thing.color.R) * factor), (byte)(255 - (255 - thing.color.G) * factor), (byte)(255 - (255 - thing.color.B) * factor))); thing.brushPulse = new SolidColorBrush(Color.FromRgb(255, 255, 255)); } if (thing.state == ThingState.Bouncing) // Pulsate edges { double alpha = (Math.Cos(0.15 * (thing.flashCount++) * thing.hotness) * 0.5 + 0.5); children.Add(makeSimpleShape(PolyDefs[thing.shape].numSides, PolyDefs[thing.shape].skip, thing.size, thing.theta, thing.center, thing.brush, thing.brushPulse, thing.size * 0.1, alpha)); things[i] = thing; } else { if (thing.state == ThingState.Dissolving) thing.brush.Opacity = 1.0 - thing.dissolve * thing.dissolve; children.Add(makeSimpleShape(PolyDefs[thing.shape].numSides, PolyDefs[thing.shape].skip, thing.size, thing.theta, thing.center, thing.brush, (thing.state == ThingState.Dissolving) ? null : thing.brush2, 1, 1)); } } // Show scores if (scores.Count != 0) { int i = 0; foreach (var score in scores) { Label label = MakeSimpleLabel(score.Value.ToString(), new Rect((0.02 + i * 0.6) * sceneRect.Width, 0.01 * sceneRect.Height, 0.4 * sceneRect.Width, 0.3 * sceneRect.Height), new SolidColorBrush(Color.FromArgb(200, 255, 255, 255))); label.FontSize = Math.Max(1, Math.Min(sceneRect.Width / 12, sceneRect.Height / 12)); children.Add(label); i++; } } // Show game timer if (gameMode != GameMode.Off) { TimeSpan span = DateTime.Now.Subtract(gameStartTime); string text = span.Minutes.ToString() + ":" + span.Seconds.ToString("00"); Label timeText = MakeSimpleLabel(text, new Rect(0.1 * sceneRect.Width, 0.25 * sceneRect.Height, 0.89 * sceneRect.Width, 0.72 * sceneRect.Height), new SolidColorBrush(Color.FromArgb(160, 255, 255, 255))); timeText.FontSize = Math.Max(1, sceneRect.Height / 16); timeText.HorizontalContentAlignment = HorizontalAlignment.Right; timeText.VerticalContentAlignment = VerticalAlignment.Bottom; children.Add(timeText); } }
private static void RenderElement(UIElementCollection childCollection, Transform textRotation, ElementDescription element) { // Debug.WriteLine(element.ToString()); switch (element.Type) { case ElementType.Circle: Ellipse e = new Ellipse() { Width = element.Width.Value, Height = element.Height.Value, Fill = BrushForColor(element.Fill), Stroke = BrushForColor(element.Stroke), }; childCollection.Add(e); Canvas.SetLeft(e, element.CenterX.Value); Canvas.SetTop(e, element.CenterY.Value); break; case ElementType.Path: Path path = new Path() { Data = ProcessPathData(element.GetPath()), Tag = element.Text, Fill = BrushForColor("#80000000"), // element.Fill), Stroke = BrushForColor(element.Stroke), StrokeThickness = element.Scale.Value * (double)Path.StrokeThicknessProperty.GetMetadata(typeof(Path)).DefaultValue, }; childCollection.Add(path); //Canvas.SetLeft(path, element.CenterX.Value); //Canvas.SetTop(path, element.CenterY.Value); break; case ElementType.Text: Canvas canvas = new Canvas() { RenderTransform = textRotation, }; FrameworkElement tb = new Border() { // BorderThickness = new Thickness(1), // BorderBrush = new SolidColorBrush(Colors.Magenta), Child = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, // Foreground = BrushForColor(string.IsNullOrEmpty(element.Stroke) ? "white" : element.Stroke), Foreground = BrushForColor("white"), FontSize = element.FontSize * 0.85, Text = element.Text, } }; canvas.Children.Add(tb); tb.LayoutUpdated += (a, b) => { Canvas.SetLeft(tb, -tb.ActualWidth / 2); Canvas.SetTop(tb, -tb.ActualHeight / 2); }; childCollection.Add(canvas); Canvas.SetLeft(canvas, element.CenterX.Value); Canvas.SetTop(canvas, element.CenterY.Value); break; default: throw new InvalidOperationException("Unexpected node: " + element.Type); } }
public void Draw(UIElementCollection children) { if (!IsAlive) { return; } // Draw all bones first, then circles (head and hands). DateTime cur = DateTime.Now; foreach (var segment in _segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (!seg.IsCircle()) { var line = new Line { StrokeThickness = seg.Radius * 2, X1 = seg.X1, Y1 = seg.Y1, X2 = seg.X2, Y2 = seg.Y2, Stroke = _bonesBrush, StrokeEndLineCap = PenLineCap.Round, StrokeStartLineCap = PenLineCap.Round }; children.Add(line); } } foreach (var segment in _segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { var circle = new Ellipse { Width = seg.Radius * 2, Height = seg.Radius * 2 }; circle.SetValue(Canvas.LeftProperty, seg.X1 - seg.Radius); circle.SetValue(Canvas.TopProperty, seg.Y1 - seg.Radius); circle.Stroke = _jointsBrush; circle.StrokeThickness = 1; circle.Fill = _bonesBrush; children.Add(circle); } } // Remove unused players after 1/2 second. if (DateTime.Now.Subtract(LastUpdated).TotalMilliseconds > 500) { IsAlive = false; } }
public void DrawFrame(UIElementCollection children) { this.frameCount++; // Draw all shapes in the scene for (int i = 0; i < this.things.Count; i++) { Thing thing = this.things[i]; if (thing.Brush == null) { thing.Brush = new SolidColorBrush(thing.Color); double factor = 0.4 + (((double)thing.Color.R + thing.Color.G + thing.Color.B) / 1600); thing.Brush2 = new SolidColorBrush( System.Windows.Media.Color.FromRgb( (byte)(255 - ((255 - thing.Color.R) * factor)), (byte)(255 - ((255 - thing.Color.G) * factor)), (byte)(255 - ((255 - thing.Color.B) * factor)))); thing.BrushPulse = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 255)); } if (thing.State == ThingState.Bouncing) { // Pulsate edges double alpha = Math.Cos((0.15 * (thing.FlashCount++) * thing.Hotness) * 0.5) + 0.5; children.Add( this.MakeSimpleShape( this.polyDefs[thing.Shape].Sides, this.polyDefs[thing.Shape].Skip, thing.Size, thing.Theta, thing.Center, thing.Brush, thing.BrushPulse, thing.Size * 0.1, alpha)); this.things[i] = thing; } else { if (thing.State == ThingState.Dissolving) { thing.Brush.Opacity = 1.0 - (thing.Dissolve * thing.Dissolve); } children.Add( this.MakeSimpleShape( this.polyDefs[thing.Shape].Sides, this.polyDefs[thing.Shape].Skip, thing.Size, thing.Theta, thing.Center, thing.Brush, (thing.State == ThingState.Dissolving) ? null : thing.Brush2, 1, 1)); } } // Show scores if (this.scores.Count != 0) { int i = 0; foreach (var score in this.scores) { Label label = MakeSimpleLabel( score.Value.ToString(CultureInfo.InvariantCulture), new Rect( (0.02 + (i * 0.6)) * this.sceneRect.Width, 0.01 * this.sceneRect.Height, 0.4 * this.sceneRect.Width, 0.3 * this.sceneRect.Height), new SolidColorBrush(System.Windows.Media.Color.FromArgb(200, 255, 255, 255))); label.FontSize = Math.Max(1, Math.Min(this.sceneRect.Width / 12, this.sceneRect.Height / 12)); children.Add(label); i++; } } // Show game timer if (this.gameMode != GameMode.Off) { TimeSpan span = DateTime.Now.Subtract(this.gameStartTime); string text = span.Minutes.ToString(CultureInfo.InvariantCulture) + ":" + span.Seconds.ToString("00"); Label timeText = MakeSimpleLabel( text, new Rect( 0.1 * this.sceneRect.Width, 0.25 * this.sceneRect.Height, 0.89 * this.sceneRect.Width, 0.72 * this.sceneRect.Height), new SolidColorBrush(System.Windows.Media.Color.FromArgb(160, 255, 255, 255))); timeText.FontSize = Math.Max(1, this.sceneRect.Height / 16); timeText.HorizontalContentAlignment = HorizontalAlignment.Right; timeText.VerticalContentAlignment = VerticalAlignment.Bottom; children.Add(timeText); } }
public void Draw(UIElementCollection children) { if (!isAlive) return; Label l1 = new Label(); l1.Content = ""; l1.FontSize = 16; l1.Foreground = System.Windows.Media.Brushes.White; children.Add(l1); // Draw all bones first, then circles (head and hands). DateTime cur = DateTime.Now; foreach (var segment in segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (!seg.IsCircle()) { if (skin.bones.ContainsKey(segment.Key.GetBoneID()) /*&& segment.Key.GetBoneID() == Bone.BoneID.ForearmLeft*/) { Image bone = skin.bones[segment.Key.GetBoneID()]; TransformGroup trans = new TransformGroup(); double y = seg.y1 - seg.y2; double x = seg.x1 - seg.x2; double r = Math.Sqrt(y*y + x*x); bone.Stretch = Stretch.Uniform; if (segment.Key.GetBoneID() == Bone.BoneID.HandLeft || segment.Key.GetBoneID() == Bone.BoneID.HandRight) r = r * 2; if (r > 30) bone.Height = r; else bone.Height = 30; if (segment.Key.GetBoneID() == Bone.BoneID.Torso) bone.Height = bone.Height * 1.6; bone.SetValue(Canvas.LeftProperty, seg.x2 - (bone.ActualWidth / 2.0)); bone.SetValue(Canvas.TopProperty, seg.y2); RotateTransform rotate = new RotateTransform(); rotate.Angle = (Math.Atan2(y,x) * (180 / Math.PI)) - 90; l1.Content = Math.Atan2(x,y) + " --> "+ rotate.Angle.ToString(); rotate.CenterX = bone.ActualWidth / 2.0; rotate.CenterY = 0; trans.Children.Add(rotate); bone.RenderTransform = trans; if (!children.Contains(bone)) children.Add(bone); } if (MainWindow.ShowSkeleton) { var line = new Line(); line.StrokeThickness = seg.radius * 2; line.X1 = seg.x1; line.Y1 = seg.y1; line.X2 = seg.x2; line.Y2 = seg.y2; line.Stroke = brBones; line.StrokeEndLineCap = PenLineCap.Round; line.StrokeStartLineCap = PenLineCap.Round; var label = new Label(); label.Content = segment.Key.joint1; label.SetValue(Canvas.LeftProperty, seg.x1); label.SetValue(Canvas.TopProperty, seg.y1); children.Add(label); children.Add(line); } } } foreach (var segment in segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { if (skin.joints.ContainsKey(segment.Key.joint1) /*&& segment.Key.GetBoneID() == Bone.BoneID.Torso*/) { Image joint = skin.joints[segment.Key.joint1]; TransformGroup trans = new TransformGroup(); double y = seg.y1; double x = seg.x1; double hyp = seg.radius * 3.7; joint.Stretch = Stretch.Uniform; if (hyp > 30) joint.Height = hyp; else joint.Height = 30; joint.SetValue(Canvas.LeftProperty, seg.x1 - (joint.ActualWidth / 2.0)); joint.SetValue(Canvas.TopProperty, seg.y1 - (joint.ActualHeight / 2.0)); if (!children.Contains(joint)) children.Add(joint); } if (MainWindow.ShowSkeleton) { var circle = new Ellipse(); circle.Width = seg.radius * 2; circle.Height = seg.radius * 2; circle.SetValue(Canvas.LeftProperty, seg.x1 - seg.radius); circle.SetValue(Canvas.TopProperty, seg.y1 - seg.radius); circle.Stroke = brJoints; circle.StrokeThickness = 1; circle.Fill = brBones; var label = new Label(); label.Content = segment.Key.joint1; label.SetValue(Canvas.LeftProperty, seg.x1); label.SetValue(Canvas.TopProperty, seg.y1); children.Add(label); children.Add(circle); } } } // Remove unused players after 0.5 seconds. if (DateTime.Now.Subtract(lastUpdated).TotalMilliseconds > 500) isAlive = false; }
public void Draw(UIElementCollection children) { if (this.mIsAlive == false) { return; } DateTime currentTime = DateTime.Now; foreach (var segment in this.mSegments) { Segment estimatedSegment = segment.Value.GetEstimatedSegment(currentTime); if (estimatedSegment.IsCircle() == false) { // ボーンの描画 Line line = new Line() { StrokeThickness = estimatedSegment.mRadius * 2.0, X1 = estimatedSegment.mX1, Y1 = estimatedSegment.mY1, X2 = estimatedSegment.mX2, Y2 = estimatedSegment.mY2, Stroke = this.mBoneBrush, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round }; children.Add(line); } } foreach (var segment in this.mSegments) { Segment estimatedSegment = segment.Value.GetEstimatedSegment(currentTime); if (estimatedSegment.IsCircle() == true) { // 円の描画 Ellipse circle = new Ellipse() { Width = estimatedSegment.mRadius * 2.0, Height = estimatedSegment.mRadius * 2.0 }; circle.SetValue(Canvas.LeftProperty, estimatedSegment.mX1 - estimatedSegment.mRadius); circle.SetValue(Canvas.TopProperty, estimatedSegment.mY1 - estimatedSegment.mRadius); circle.StrokeThickness = 1.0; circle.Stroke = this.mJointBrush; circle.Fill = this.mBoneBrush; children.Add(circle); } } if (DateTime.Now.Subtract(this.mTimeLastUpdated).TotalMilliseconds > 1000.0) { // 1.0秒以上更新されない場合はプレイヤーを削除 this.mIsAlive = false; this.mPlayerState = PlayerState.Disappeared; } }
public void AddTo(UIElementCollection collection) { collection.Add(circle); }
public SmartTableControl() { ColumnList = new List<Column>(); RowList = new List<RowBase>(); ColumnHeaderDefaultBackgroundBrush = new SolidColorBrush(Color.FromRgb(230, 230, 230)); RowSelectionButtonDefaultBackgroudBrush = new SolidColorBrush(Color.FromRgb(230, 230, 230)); CellDefaultBackgroundBrush = Brushes.White; _columnHeaderHeight = 20; ColumnHeaderMargin = new Thickness(2, 2, 2, 2); CellMargin = new Thickness(2, 2, 2, 2); RowDefaultHeight = 20; _rowSelectionButtonWidth = 20; childs = new UIElementCollection(this, this); UseLayoutRounding = true; SnapsToDevicePixels = true; this.Margin = new Thickness(6, 120, 5, 5); this.Width = 250; this.Height = 100; this.HorizontalAlignment = HorizontalAlignment.Left; this.VerticalAlignment = VerticalAlignment.Top; hScroll = new ScrollBar(); childs.Add(hScroll); hScroll.Orientation = Orientation.Horizontal; hScroll.Margin = new Thickness(0, 0, 17, 0); hScroll.HorizontalAlignment = HorizontalAlignment.Stretch; hScroll.VerticalAlignment = VerticalAlignment.Bottom; hScroll.Minimum = 0; hScroll.Maximum = 0; hScroll.SmallChange = 1; hScroll.LargeChange = 5d; hScroll.ValueChanged += HScroll_ValueChanged; vScroll = new ScrollBar(); childs.Add(vScroll); vScroll.Margin = new Thickness(0, 0, 0, 17); vScroll.HorizontalAlignment = HorizontalAlignment.Right; vScroll.VerticalAlignment = VerticalAlignment.Stretch; vScroll.Minimum = 0; vScroll.Maximum = 0; vScroll.SmallChange = 1; vScroll.LargeChange = 5d; vScroll.ValueChanged += VScroll_ValueChanged; smallBlackPen = new Pen(Brushes.Black, 1); smallLtGrayPen = new Pen(Brushes.LightGray, 1); smallGrayPen = new Pen(Brushes.Gray, 1); LinearGradientBrush lb = new LinearGradientBrush(); lb.GradientStops.Add(new GradientStop(Color.FromRgb(230, 230, 230), 0)); lb.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 0), 0.8)); lb.MappingMode = BrushMappingMode.RelativeToBoundingBox; lb.SpreadMethod = GradientSpreadMethod.Pad; dkLLtGrayToGrayVBrush = new LinearGradientBrush(Color.FromRgb(230, 230, 230), Colors.Gray, 90); smallLLtGrayToGrayVPen = new Pen(dkLLtGrayToGrayVBrush, 1); dkLLtGrayToGrayHBrush = new LinearGradientBrush(Color.FromRgb(230, 230, 230), Colors.Gray, 0); smallLLtGrayToGrayHPen = new Pen(dkLLtGrayToGrayHBrush, 1); InvalidateMeasure(); }
public void Draw(UIElementCollection children) { if (!isAlive) return; // Draw all bones first, then circles (head and hands). DateTime cur = DateTime.Now; foreach (var segment in segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (!seg.IsCircle()) { var line = new Line(); line.StrokeThickness = seg.radius * 2; line.X1 = seg.x1; line.Y1 = seg.y1; line.X2 = seg.x2; line.Y2 = seg.y2; line.Stroke = brBones; line.StrokeEndLineCap = PenLineCap.Round; line.StrokeStartLineCap = PenLineCap.Round; children.Add(line); } } foreach (var segment in segments) { Segment seg = segment.Value.GetEstimatedSegment(cur); if (seg.IsCircle()) { var circle = new Ellipse(); circle.Width = seg.radius * 2; circle.Height = seg.radius * 2; circle.SetValue(Canvas.LeftProperty, seg.x1 - seg.radius); circle.SetValue(Canvas.TopProperty, seg.y1 - seg.radius); circle.Stroke = brJoints; circle.StrokeThickness = 1; circle.Fill = brBones; children.Add(circle); } } // Remove unused players after 1/2 second. if (DateTime.Now.Subtract(lastUpdated).TotalMilliseconds > 500) isAlive = false; }
public virtual void QuickBind(UIElementCollection target, UIElement candidate) { if (candidate != null) { target.Add(candidate); } }