/// <summary> /// Find the segment where the window is hung /// </summary> /// <param name="rect">Rectangle that represent the window</param> /// <returns>Return the finded segment</returns> private Line FindSegmentByWindow(Rectangle rect) { double x = InkCanvas.GetLeft(rect); double y = InkCanvas.GetTop(rect); double width = rect.Width; double height = rect.Height; Line wall = null; // Loop throught the segment and search the segment that contain the window foreach (UIElement element in _receiver.ViewModel._mainWindow.canvas.Children) { if (element is Line line) { if (x > line.X1 && x + width < line.X2 || x > line.X2 && x + width < line.X1 || y > line.Y1 && y + height < line.Y2 || y > line.Y2 && y + height < line.Y1) { wall = line; } } } return(wall); }
private bool BeginCrop(PathGeometry path) { TouchableImage image = this._selectedImage; if (image != null) { //이 이미지 위치정보 A+ 저장 double outerImage_x = InkCanvas.GetLeft(image); double outerImage_y = InkCanvas.GetTop(image); double outerImage_width = image.Width; double outerImage_height = image.Height; Rect outerImageRect = new Rect(0, 0, outerImage_width, outerImage_height); //입력받은 패스를 가지고 이미지의 좌표에 맞게 좌표수정 path.Transform = new TranslateTransform(-outerImage_x, -outerImage_y); //화면 영역에 맞게 combine 된 clipping path를 구함 RectangleGeometry imageRectGeo = new RectangleGeometry(outerImageRect); CombinedGeometry combinedGeoIntersect = new CombinedGeometry(GeometryCombineMode.Intersect, imageRectGeo, path); //이미지에 적용, 패스로 크로핑 image.Clip = combinedGeoIntersect; //새 이미지를 만든다. TouchableImage cloneImg = new TouchableImage(); //cloneImg.RenderTransform = image.RenderTransform.Clone(); cloneImg.Source = image.Source.Clone(); cloneImg.Width = image.ActualWidth; cloneImg.Height = image.ActualHeight; //이미지의 영역과 클리핑 데이터로 새로운 클리핑 영역을 만듦 CombinedGeometry combinedGeoXor = new CombinedGeometry(GeometryCombineMode.Xor, imageRectGeo, path); cloneImg.Clip = combinedGeoXor; //새로 만들어진 이미지를 넣고 배치한다. this._inkCanvas.Children.Add(cloneImg); //cloneImg.RenderTransform = new RotateTransform(); InkCanvas.SetLeft(cloneImg, outerImage_x); InkCanvas.SetTop(cloneImg, outerImage_y); //원본 이미지에 재적용 //클리핑된 이미지 B 완성 (선택한 영역만 남은 그림) //이 이미지 위치정보 B+ 저장 //원본 이미지의 인덱스 위치에 //이미지 A 를 A+ 위치에 배치 //이미지 B 를 B+ 위치에 배치 //원본 이미지 캔버스에서 제거 if (this.ImageCropped != null) { ImageCropped(this, null); } } return(true); }
internal void Scale(bool shouldAdd, int count) { for (int j = 0; j < count; j++) { double _ScaleFactor = shouldAdd ? 1.2 : .8; _Scale *= _ScaleFactor; //TODO: implement // _ScaleText.Text = _Scale.ToString(); foreach (InkCanvas _InkCanvas in _canvasList.Children) { foreach (Stroke _Stroke in _InkCanvas.Strokes) { for (int i = 0; i < _Stroke.StylusPoints.Count; i++) { StylusPoint _StylusPoint = _Stroke.StylusPoints[i]; _Stroke.StylusPoints[i] = new StylusPoint(_StylusPoint.X * _ScaleFactor, _StylusPoint.Y * _ScaleFactor); } } foreach (FrameworkElement _Image in _InkCanvas.Children) { InkCanvas.SetLeft(_Image, InkCanvas.GetLeft(_Image) * _ScaleFactor); InkCanvas.SetTop(_Image, InkCanvas.GetTop(_Image) * _ScaleFactor); _Image.Width = _Image.ActualWidth * _ScaleFactor; _Image.Height = _Image.ActualHeight * _ScaleFactor; } } } }
//void myimg_MouseDown() void myimg_MouseDown(object sender, MouseButtonEventArgs e) { //mouseClick = e.GetPosition(null); //Console.WriteLine("HELLO"); System.Windows.Controls.Image nearestImage = findNearestImage(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y); //Console.WriteLine("AHHHHHHHHH"); //((System.Windows.Controls.Image)sender).CaptureMouse(); //baseTop = InkCanvas.GetTop(((System.Windows.Controls.Image)sender)); //baseLeft = InkCanvas.GetLeft(((System.Windows.Controls.Image)sender)); Console.WriteLine(nearestImage.Name); baseTop = InkCanvas.GetTop(nearestImage); baseLeft = InkCanvas.GetLeft(nearestImage); deltaLeft = new double[selectedImages.Count()]; deltaTop = new double[selectedImages.Count()]; for (int i = 0; i < selectedImages.Count(); i++) { deltaLeft[i] = InkCanvas.GetLeft(selectedImages[i]); deltaTop[i] = InkCanvas.GetTop(selectedImages[i]); } }
private void AddCopy(InkCanvas inkCanvas) { var strokeCollection = new StrokeCollection(); foreach (var selectedStroke in _selectedStrokes) { var stroke = selectedStroke.Clone(); strokeCollection.Add(stroke); inkCanvas.Strokes.Add(stroke); } var uiElementCollection = new List <UIElement>(); foreach (UIElement selectedElement in _selectedElements) { var element = WPFHelper.Clone(selectedElement, inkCanvas); if (element == null) { continue; } uiElementCollection.Add(element); inkCanvas.Children.Add(element); InkCanvas.SetLeft(element, InkCanvas.GetLeft(selectedElement)); InkCanvas.SetTop(element, InkCanvas.GetTop(selectedElement)); } _repetitions.Add(new Tuple <ReadOnlyCollection <UIElement>, StrokeCollection>(new ReadOnlyCollection <UIElement>(uiElementCollection), strokeCollection)); }
/* METHOD: Parameters: x coordinate * y coordinate * * Returns: The nearest image from the specified coordiate */ private System.Windows.Controls.Image findNearestImage(double x, double y) { System.Windows.Controls.Image output = new System.Windows.Controls.Image(); double currentBest = -1; for (int i = 0; i < selectedImages.Count(); i++) { double left = InkCanvas.GetLeft(selectedImages[i]); double top = InkCanvas.GetTop(selectedImages[i]); double distance = Math.Sqrt(Math.Pow(left - x, 2) + Math.Pow(top - y, 2)); if (currentBest == -1) { currentBest = distance; output = selectedImages[i]; } else if (distance < currentBest) { currentBest = distance; output = selectedImages[i]; } } return(output); }
private void startDrag() { Console.WriteLine("Start Drag has been called"); WC_inkCanvas.EditingMode = InkCanvasEditingMode.None; System.Windows.Controls.Image nearestImage = findNearestImage(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y); //Console.WriteLine("AHHHHHHHHH"); //((System.Windows.Controls.Image)sender).CaptureMouse(); //baseTop = InkCanvas.GetTop(((System.Windows.Controls.Image)sender)); //baseLeft = InkCanvas.GetLeft(((System.Windows.Controls.Image)sender)); //Console.WriteLine(nearestImage.Name); baseTop = InkCanvas.GetTop(nearestImage); baseLeft = InkCanvas.GetLeft(nearestImage); deltaLeft = new double[selectedImages.Count()]; deltaTop = new double[selectedImages.Count()]; for (int i = 0; i < selectedImages.Count(); i++) { deltaLeft[i] = InkCanvas.GetLeft(selectedImages[i]); deltaTop[i] = InkCanvas.GetTop(selectedImages[i]); } imagesFollowMouse = true; }
void AttachedPropertiesSnippets() { //<Snippet27> InkCanvas.SetTop(button1, 100); //</Snippet27> //<Snippet28> InkCanvas.SetBottom(button1, 100); //</Snippet28> //<Snippet29> InkCanvas.SetLeft(button1, 100); //</Snippet29> //<Snippet30> InkCanvas.SetRight(button1, 100); //</Snippet30> //<Snippet31> double buttonLeft = InkCanvas.GetLeft(button1); //</Snippet31> //<Snippet32> double buttonRight = InkCanvas.GetRight(button1); //</Snippet32> //<Snippet33> double buttonTop = InkCanvas.GetTop(button1); //</Snippet33> //<Snippet34> double buttonBottom = InkCanvas.GetBottom(button1); //</Snippet34> }
// Token: 0x060077AE RID: 30638 RVA: 0x002225D4 File Offset: 0x002207D4 protected override Size MeasureOverride(Size constraint) { Size availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity); Size result = default(Size); foreach (object obj in base.InternalChildren) { UIElement uielement = (UIElement)obj; if (uielement != null) { uielement.Measure(availableSize); double num = InkCanvas.GetLeft(uielement); if (!DoubleUtil.IsNaN(num)) { result.Width = Math.Max(result.Width, num + uielement.DesiredSize.Width); } else { result.Width = Math.Max(result.Width, uielement.DesiredSize.Width); } double num2 = InkCanvas.GetTop(uielement); if (!DoubleUtil.IsNaN(num2)) { result.Height = Math.Max(result.Height, num2 + uielement.DesiredSize.Height); } else { result.Height = Math.Max(result.Height, uielement.DesiredSize.Height); } } } return(result); }
private void _drawerTextBox_LostFocus(object sender, RoutedEventArgs e) { String text = _drawerTextBox.Text; if (text.Length > 0) { var textBlock = new TextBlock(); //textBlock.TextWrapping = TextWrapping.NoWrap; textBlock.Text = text; MainInkCanvas.Children.Add(textBlock); textBlock.Visibility = Visibility.Visible; textBlock.Foreground = _drawerTextBox.Foreground; textBlock.FontSize = _drawerTextBox.FontSize; textBlock.TextWrapping = _drawerTextBox.TextWrapping; InkCanvas.SetLeft(textBlock, InkCanvas.GetLeft(_drawerTextBox)); InkCanvas.SetTop(textBlock, InkCanvas.GetTop(_drawerTextBox)); } MainInkCanvas.Children.Remove(_drawerTextBox); //throw new NotImplementedException(); }
void myimg_MouseMove(object sender, MouseEventArgs e) { // if (((System.Windows.Controls.Image)sender).IsMouseCaptured) //{ //System.Windows.Point mouseCurrent = e.GetPosition(null); //double Left = mouseCurrent.X; //double Top = mouseCurrent.Y; if ((deltaTop[0] != -1) && (deltaLeft[0] != -1)) { double CursorLeft = System.Windows.Forms.Cursor.Position.X; double CursorTop = System.Windows.Forms.Cursor.Position.Y; for (int i = 0; i < selectedImages.Count(); i++) { selectedImages[i].SetValue(InkCanvas.LeftProperty, (CursorLeft - (baseLeft - deltaLeft[i]))); selectedImages[i].SetValue(InkCanvas.TopProperty, (CursorTop - (baseTop - deltaTop[i]))); double SOFUKCINGCOLD = InkCanvas.GetLeft(selectedImages[i]); double IHATETHISPROJ = InkCanvas.GetTop(selectedImages[i]); selectedTextBlocks[i].SetValue(InkCanvas.LeftProperty, SOFUKCINGCOLD - 20); selectedTextBlocks[i].SetValue(InkCanvas.TopProperty, IHATETHISPROJ + 40 + 10); } } // } }
private void TabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (tabDeleted) { return; } //追加ボタン用タブを選択させない if (TabControl1.SelectedIndex <= 0) { TabControl1.SelectedIndex = lastSelectedTab; return; } else { MemoryStream ms = new MemoryStream(); TegakiCanvas.Strokes.Save(ms, true); NoteData nd = new NoteData() { tegaki = ms.ToArray(), borderMargin = lineMargine }; foreach (TextBlock TB in TegakiCanvas.Children.OfType <TextBlock>()) { nd.TBFontSizes.Add(TB.FontSize); nd.TBLineHeights.Add(TB.LineHeight); nd.TBtexts.Add(TB.Text); nd.TBXs.Add(InkCanvas.GetLeft(TB)); nd.TBYs.Add(InkCanvas.GetTop(TB)); } Pages[(((TabControl1.Items[lastSelectedTab] as TabItem).Header as DockPanel).Children[1] as TextBlock).Text] = nd; lastSelectedTab = TabControl1.SelectedIndex; nd = Pages[(((TabControl1.Items[lastSelectedTab] as TabItem).Header as DockPanel).Children[1] as TextBlock).Text]; TegakiCanvas.Strokes.Clear(); TegakiCanvas.Children.Clear(); OCRCanvas.Strokes.Clear(); OCRCanvas.Children.Clear(); if (nd.tegaki == null) { return; } TegakiCanvas.Strokes = new StrokeCollection(new MemoryStream(nd.tegaki)); lineMargine = nd.borderMargin; for (int i = 0; i < nd.TBFontSizes.Count; i++) { TextBlock tb = new TextBlock() { Text = nd.TBtexts[i], FontSize = nd.TBFontSizes[i], LineHeight = nd.TBLineHeights[i] }; TegakiCanvas.Children.Add(tb); InkCanvas.SetLeft(tb, nd.TBXs[i]); InkCanvas.SetTop(tb, nd.TBYs[i]); } } }
/// <summary> /// Canvas computes a position for each of its children taking into account their margin and /// attached Canvas properties: Top, Left. /// /// Canvas will also arrange each of its children. /// This code is same as the Canvas'. /// </summary> /// <param name="arrangeSize">Size that Canvas will assume to position children.</param> protected override Size ArrangeOverride(Size arrangeSize) { //Canvas arranges children at their DesiredSize. //This means that Margin on children is actually respected and added //to the size of layout partition for a child. //Therefore, is Margin is 10 and Left is 20, the child's ink will start at 30. foreach (UIElement child in InternalChildren) { if (child == null) { continue; } double x = 0; double y = 0; //Compute offset of the child: //If Left is specified, then Right is ignored //If Left is not specified, then Right is used //If both are not there, then 0 double left = (double)InkCanvas.GetLeft(child); if (!DoubleUtil.IsNaN(left)) { x = left; } else { double right = (double)InkCanvas.GetRight(child); if (!DoubleUtil.IsNaN(right)) { x = arrangeSize.Width - child.DesiredSize.Width - right; } } double top = (double)InkCanvas.GetTop(child); if (!DoubleUtil.IsNaN(top)) { y = top; } else { double bottom = (double)InkCanvas.GetBottom(child); if (!DoubleUtil.IsNaN(bottom)) { y = arrangeSize.Height - child.DesiredSize.Height - bottom; } } child.Arrange(new Rect(new Point(x, y), child.DesiredSize)); } return(arrangeSize); }
private void RefreshUIElements(double dX, double dY, int repIndex) { for (int i = 0; i < _selectedElements.Count; i++) { var uiElement = _repetitions[repIndex].Obj1[i]; var originalElement = _selectedElements[i]; InkCanvas.SetLeft(uiElement, InkCanvas.GetLeft(originalElement) + dX); InkCanvas.SetTop(uiElement, InkCanvas.GetTop(originalElement) + dY); } }
public Property GetProperty() { Property p = new Property(); p.height = (int)this.Height; p.width = (int)this.Width; p.absoluteX = (int)InkCanvas.GetLeft(this); p.absoluteY = (int)InkCanvas.GetTop(this); return(p); }
private void SaveChild(string directoryPath, string directoryName) { DrawingSheet.UpdateLayout(); var fsPos = new StreamWriter(directoryPath + "\\" + directoryName + "_pos.txt"); for (var i = 0; i < DrawingSheet.Children.Count; i++) { Tools.ExportToPng(directoryPath + "\\" + directoryName + "_child" + i + ".png", DrawingSheet.Children[i] as Image); var pos = directoryName + "_child" + i + " " + InkCanvas.GetTop(DrawingSheet.Children[i]) + " " + InkCanvas.GetLeft(DrawingSheet.Children[i]); fsPos.WriteLine(pos); } fsPos.Close(); }
private List <MapDatabase.Layer> SaveLayers() { List <MapDatabase.Layer> _Layers = new List <MapDatabase.Layer>(); foreach (InkCanvas _InkCanvas in _canvasList.Children) { MapDatabase.Layer _Layer = new MapDatabase.Layer(); foreach (Image _Image in _InkCanvas.Children.OfType <Image>()) { Image img = _Image; ImageSource imgSource = img.Source; BitmapImage bmp = imgSource as BitmapImage; string path = bmp.UriSource.OriginalString; double x = InkCanvas.GetLeft(_Image); double y = InkCanvas.GetTop(_Image); double width = _Image.ActualWidth; double height = _Image.ActualHeight; MapDatabase.Image imga = new MapDatabase.Image { Path = path, X = x, Y = y, Width = width, Height = height }; _Layer.Images.Add(imga); } List <MapDatabase.Polygon> _Polygons = _Layer.Polygons; foreach (Stroke _Stroke in _InkCanvas.Strokes) { List <Point> _Points = new List <Point>(); foreach (StylusPoint _StylusPoint in _Stroke.StylusPoints) { Point _Point = new Point(); _Point.X = (int)_StylusPoint.X; _Point.Y = (int)_StylusPoint.Y; _Points.Add(_Point); } MapDatabase.Polygon _Polygon = new MapDatabase.Polygon(); _Polygon.Color = _Stroke.DrawingAttributes.Color; _Polygon.Points = _Points; _Polygons.Add(_Polygon); } _Layers.Add(_Layer); } return(_Layers); }
public void SaveFile(object sender, RoutedEventArgs e) { _MapDatabase._Layers = SaveLayers(); _MapDatabase._CStartPos.X = InkCanvas.GetLeft(_CStartPos); _MapDatabase._CStartPos.Y = InkCanvas.GetTop(_CStartPos); _MapDatabase._TStartPos.X = InkCanvas.GetLeft(_TStartPos); _MapDatabase._TStartPos.Y = InkCanvas.GetTop(_TStartPos); MemoryStream _MemoryStream = new MemoryStream(); _XmlSerializer.Serialize(_MemoryStream, _MapDatabase); byte[] _Buffer = _MemoryStream.ToArray(); File.WriteAllBytes(_FilePath, _Buffer); }
/// <summary> /// Returns the button at the given position, if any. Not currently used. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public bool FindButton(System.Windows.Point point) { Rect buttonLoc = new Rect(); foreach (Popup pop in activeButtonList) { Button button = (Button)pop.Child; buttonLoc.X = InkCanvas.GetLeft(button); buttonLoc.Y = InkCanvas.GetTop(button); buttonLoc.Size = button.RenderSize; if (buttonLoc.Contains(point)) { return(true); } } return(false); }
public override string ShapeToFormat(Shape shape) { Ellipse ellipse = (Ellipse)shape; if (Format == "SVG") { double radiusX = ellipse.Width / 2; double radiusY = ellipse.Height / 2; XElement svgEllipse = new XElement("ellipse"); svgEllipse.Add(new XAttribute("cx", dobuleToString(InkCanvas.GetLeft(ellipse) + radiusX))); svgEllipse.Add(new XAttribute("cy", dobuleToString(InkCanvas.GetTop(ellipse) + radiusY))); svgEllipse.Add(new XAttribute("rx", dobuleToString(radiusX))); svgEllipse.Add(new XAttribute("ry", dobuleToString(radiusY))); svgEllipse.Add(new XAttribute("fill", ellipse.Fill == null ? "none" : brushToString(ellipse.Fill))); svgEllipse.Add(new XAttribute("stroke", brushToString(ellipse.Stroke))); svgEllipse.Add(new XAttribute("stroke-width", ellipse.StrokeThickness.ToString())); return(svgEllipse.ToString()); } if (Format == "VGF") { double width = ellipse.Width; double height = ellipse.Height; double left = InkCanvas.GetLeft(ellipse); double top = InkCanvas.GetTop(ellipse); string stroke = ellipse.Stroke.ToString(); double thikness = ellipse.StrokeThickness; string fill = ellipse.Fill == null ? "noFill" : ellipse.Fill.ToString(); return($"Ellipse {left} {top} {width} {height} {stroke} {thikness} {fill};"); } if (Format == "JSON") { double radiusX = (ellipse).Width / 2; double radiusY = (ellipse).Height / 2; string CX = dobuleToString(InkCanvas.GetLeft(ellipse) + radiusX); string CY = dobuleToString(InkCanvas.GetTop(ellipse) + radiusY); string RX = dobuleToString(radiusX); string RY = dobuleToString(radiusY); string stroke = brushToString((ellipse).Stroke); string thikness = (ellipse).StrokeThickness.ToString(); string fill = (ellipse).Fill == null ? "none" : brushToString((ellipse).Fill); return($"{{\"type\":\"ellipse\", \"cx\":{CX},\"cy\":{CY},\"rx\":{RX},\"ry\":{RY},\" fill\":{fill},\"stroke\":\"{stroke}\",\"stroke-width\":{thikness}}}"); } return(""); }
public static void CloneElementsTo(IList <UIElement> targetCollection, IEnumerator sourceCollection, InkCanvas inkCanvas, int offset) { while (sourceCollection.MoveNext()) { if (!(sourceCollection.Current is UIElement)) { return; } var element = (UIElement)sourceCollection.Current; var clone = Clone(element, inkCanvas); if (clone == null) { continue; } targetCollection.Add(clone); InkCanvas.SetLeft(clone, InkCanvas.GetLeft(element) + offset); InkCanvas.SetTop(clone, InkCanvas.GetTop(element) + offset); } }
/// <summary> /// Draws the area and open a dialog to pick up a name for the area /// </summary> /// <param name="p"></param> public override async void Draw(Point p) { _areaPoints.Push(p); //Count two point to create the rectangle area if (_areaPoints.Count == 2) { Point p2 = _areaPoints.Pop(); Point p1 = _areaPoints.Pop(); this._fillBrush = new SolidColorBrush(ImageUtil.RandomColor()); // It the area type name is null, it come from the message box input if (_areaTypeName == "") { _areaTypeName = await _receiver.ViewModel.ShowAreaDialog(); } Area area = _receiver.ViewModel._plan.AddArea(p1, p2, _areaTypeName); // Add to the plan // Create the TextBlock object that contain the area name TextBlock textBlock = new TextBlock { Text = _areaTypeName, Foreground = Brushes.White, Width = 70, Height = 20, TextAlignment = TextAlignment.Center, LayoutTransform = new ScaleTransform(1, -1) }; //Add the textBlock to the canvas InkCanvas.SetLeft(textBlock, InkCanvas.GetLeft(_receiver.LastShape) + (_receiver.LastShape.Width / 2) - (textBlock.Width / 2)); InkCanvas.SetTop(textBlock, InkCanvas.GetTop(_receiver.LastShape) + (_receiver.LastShape.Height / 2) - (textBlock.Height / 2)); _receiver.ViewModel._mainWindow.canvas.Children.Add(textBlock); // Add to the history MainWindow.main.History = "Area"; _receiver.ViewModel._stackHistory.Push(new Tuple <Object, Object, string>(textBlock, area, "Area")); _receiver.LastShape = null; } }
private void drag() { if (imagesFollowMouse == true) { double CursorLeft = System.Windows.Forms.Cursor.Position.X; double CursorTop = System.Windows.Forms.Cursor.Position.Y; for (int i = 0; i < selectedImages.Count(); i++) { selectedImages[i].SetValue(InkCanvas.LeftProperty, (CursorLeft - (baseLeft - deltaLeft[i]))); selectedImages[i].SetValue(InkCanvas.TopProperty, (CursorTop - (baseTop - deltaTop[i]))); double SOFUKCINGCOLD = InkCanvas.GetLeft(selectedImages[i]); double IHATETHISPROJ = InkCanvas.GetTop(selectedImages[i]); selectedTextBlocks[i].SetValue(InkCanvas.LeftProperty, SOFUKCINGCOLD - 20); selectedTextBlocks[i].SetValue(InkCanvas.TopProperty, IHATETHISPROJ + 40 + 10); } } }
/// <summary> /// Override of <seealso cref="FrameworkElement.MeasureOverride" /> /// The code is similar to Canvas.MeasureOverride. The only difference we have is that /// InkCanvasInnerCanvas does report the size based on its children's sizes. /// </summary> /// <param name="constraint">Constraint size.</param> /// <returns>Computed desired size.</returns> protected override Size MeasureOverride(Size constraint) { Size childConstraint = new Size(Double.PositiveInfinity, Double.PositiveInfinity); Size newSize = new Size(); foreach (UIElement child in InternalChildren) { if (child == null) { continue; } child.Measure(childConstraint); // NOTICE-2006/02/03-WAYNEZEN, // We only honor Left and/or Top property for the measure. // For Right/Bottom, only the child.Width/Height will be used. Those properties will be used by the arrange // but not the measure. double left = (double)InkCanvas.GetLeft(child); if (!DoubleUtil.IsNaN(left)) { newSize.Width = Math.Max(newSize.Width, left + child.DesiredSize.Width); } else { newSize.Width = Math.Max(newSize.Width, child.DesiredSize.Width); } double top = (double)InkCanvas.GetTop(child); if (!DoubleUtil.IsNaN(top)) { newSize.Height = Math.Max(newSize.Height, top + child.DesiredSize.Height); } else { newSize.Height = Math.Max(newSize.Height, child.DesiredSize.Height); } } return(newSize); }
// Token: 0x060077AF RID: 30639 RVA: 0x00222714 File Offset: 0x00220914 protected override Size ArrangeOverride(Size arrangeSize) { foreach (object obj in base.InternalChildren) { UIElement uielement = (UIElement)obj; if (uielement != null) { double x = 0.0; double y = 0.0; double num = InkCanvas.GetLeft(uielement); if (!DoubleUtil.IsNaN(num)) { x = num; } else { double num2 = InkCanvas.GetRight(uielement); if (!DoubleUtil.IsNaN(num2)) { x = arrangeSize.Width - uielement.DesiredSize.Width - num2; } } double num3 = InkCanvas.GetTop(uielement); if (!DoubleUtil.IsNaN(num3)) { y = num3; } else { double num4 = InkCanvas.GetBottom(uielement); if (!DoubleUtil.IsNaN(num4)) { y = arrangeSize.Height - uielement.DesiredSize.Height - num4; } } uielement.Arrange(new Rect(new Point(x, y), uielement.DesiredSize)); } } return(arrangeSize); }
public override string ShapeToFormat(Shape shape) { Rectangle rect = (Rectangle)shape; if (Format == "SVG") { XElement svgRect = new XElement("rect"); svgRect.Add(new XAttribute("x", dobuleToString(InkCanvas.GetLeft(rect)))); svgRect.Add(new XAttribute("y", dobuleToString(InkCanvas.GetTop(rect)))); svgRect.Add(new XAttribute("width", dobuleToString(rect.Width))); svgRect.Add(new XAttribute("height", dobuleToString(rect.Height))); svgRect.Add(new XAttribute("fill", rect.Fill == null ? "none" : brushToString(rect.Fill))); svgRect.Add(new XAttribute("stroke", brushToString(rect.Stroke))); svgRect.Add(new XAttribute("stroke-width", rect.StrokeThickness.ToString())); return(svgRect.ToString()); } if (Format == "VGF") { double width = rect.Width; double height = rect.Height; double left = InkCanvas.GetLeft(rect); double top = InkCanvas.GetTop(rect); string stroke = rect.Stroke.ToString(); double thikness = rect.StrokeThickness; string fill = rect.Fill == null ? "noFill" : rect.Fill.ToString(); return($"Rectangle {left} {top} {width} {height} {stroke} {thikness} {fill};"); } if (Format == "JSON") { string X = dobuleToString(InkCanvas.GetLeft(rect)); string Y = dobuleToString(InkCanvas.GetTop(rect)); string W = dobuleToString(rect.Width); string H = dobuleToString((rect).Height); string stroke = brushToString((rect).Stroke); string thikness = (rect).StrokeThickness.ToString(); string fill = (rect).Fill == null ? "none" : brushToString((rect).Fill); return($"{{\"type\":\"rect\", \"x\":{X},\"y\":{Y},\"width\":{W},\"height\":{H},\"stroke\":\"{stroke}\", \"fill\":{fill},\"stroke-width\":{thikness}}}"); } return(""); }
private void inkCanvas_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (creatingTextBox) { e.Handled = true; inkCanvas.Children.Add(textBoxInCanvas); InkCanvas.SetLeft(textBoxInCanvas, e.GetPosition((IInputElement)sender).X); InkCanvas.SetTop(textBoxInCanvas, e.GetPosition((IInputElement)sender).Y); textBoxInCanvas.Focus(); editingText = true; creatingTextBox = false; } else if (editingText && !textBoxInCanvas.IsMouseOver) { e.Handled = true; string text = textBoxInCanvas.Text; double X = InkCanvas.GetLeft(textBoxInCanvas); double Y = InkCanvas.GetTop(textBoxInCanvas); textBoxInCanvas.Text = ""; inkCanvas.Children.Remove(textBoxInCanvas); Label label = new Label(); label.Content = text; inkCanvas.Children.Add(label); InkCanvas.SetLeft(label, X); InkCanvas.SetTop(label, Y); menuItemAddText.IsChecked = false; editingText = false; // 傳送文字方塊 string text 和座標 double X, Y給 server Packet packet = new Packet(); packet.makePacketAddTextBox(0, text, X.ToString(), Y.ToString()); homeWindow.sendToServer(this, packet); //echoWindow.receiveTextBox(text, X, Y); // } }
private List <MapDatabase.Layer> SaveLayers() { List <MapDatabase.Layer> _Layers = new List <MapDatabase.Layer>(); foreach (InkCanvas _InkCanvas in _CanvasList.Children) { MapDatabase.Layer _Layer = new MapDatabase.Layer(); foreach (Image _Image in _InkCanvas.Children.OfType <Image>()) { _Layer._Images.Add(new MapDatabase.Image { Path = ((BitmapImage)_Image.Source).UriSource.OriginalString, X = InkCanvas.GetLeft(_Image), Y = InkCanvas.GetTop(_Image), Width = _Image.ActualWidth, Height = _Image.ActualHeight }); } List <MapDatabase.Polygon> _Polygons = _Layer._Polygons; foreach (CustomStroke _Stroke in _InkCanvas.Strokes) { List <Point> _Points = new List <Point>(); foreach (StylusPoint _StylusPoint in _Stroke.StylusPoints) { Point _Point = new Point(); _Point.X = (int)_StylusPoint.X; _Point.Y = (int)_StylusPoint.Y; _Points.Add(_Point); } MapDatabase.Polygon _Polygon = new MapDatabase.Polygon(); _Polygon._Color = _Stroke.DrawingAttributes.Color; _Polygon._Points = _Points; _Polygons.Add(_Polygon); } _Layers.Add(_Layer); } return(_Layers); }
public void Window_SizeChanged(object sender, RoutedEventArgs e) { double prevHeight = inkCanvas.Height; double prevWidth = inkCanvas.Width; inkCanvas.Height = practiceDock.ActualHeight; inkCanvas.Width = practiceDock.ActualWidth; //must have a gate to scale the gate and strokes around if (gateImage != null) { float oldLeft = (float)InkCanvas.GetLeft(gateImage); float oldTop = (float)InkCanvas.GetTop(gateImage); Rect newBounds = centerDrawing(); System.Windows.Media.Matrix resizeMatrix = new System.Windows.Media.Matrix(); resizeMatrix.Translate(newBounds.X - oldLeft, newBounds.Y - oldTop); inkCanvas.Strokes.Transform(resizeMatrix, false); inkSketch.UpdateInkStrokes(inkCanvas.Strokes); } }
/// <summary> /// Returns the button at the given position, if any. Not currently used. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public Button FindButton(System.Windows.Point point) { double x = point.X; double y = point.Y; Button clicked = null; Rect buttonLoc = new Rect(); System.Windows.Point clickLoc = new System.Windows.Point(x, y); foreach (Popup pop in popList) { Button button = (Button)pop.Child; buttonLoc.Location = new Point(InkCanvas.GetLeft(button), InkCanvas.GetTop(button)); buttonLoc.Size = new Size(button.Width, button.Height); if (buttonLoc.Contains(clickLoc)) { clicked = button; break; } } return(clicked); }