public XmlRenderer(System.Windows.Size size) { Size = size; m_stream = new MemoryStream(); m_writer = new XmlTextWriter(m_stream, Encoding.UTF8); m_writer.Formatting = Formatting.Indented; }
public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size) { var background = new Rectangle(); background.Width = size.Width; background.Height = size.Height; background.Fill = backgroundColor; var textBlock = new TextBlock(); textBlock.Width = 500; textBlock.Height = 500; textBlock.TextWrapping = TextWrapping.Wrap; textBlock.Text = text; textBlock.FontSize = textSize; textBlock.Foreground = new SolidColorBrush(Colors.White); textBlock.FontFamily = new FontFamily("Segoe WP"); var tileImage = "/Shared/ShellContent/" + filename; using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height); bitmap.Render(background, new TranslateTransform()); bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 }); var stream = store.CreateFile(tileImage); bitmap.Invalidate(); bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99); stream.Close(); } return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute); }
protected override void OnRender(DrawingContext dc) { Size size = new Size(base.ActualWidth, base.ActualHeight); int tickCount = (int)((this.Maximum - this.Minimum) / this.TickFrequency) + 1; if ((this.Maximum - this.Minimum) % this.TickFrequency == 0) tickCount -= 1; Double tickFrequencySize; // Calculate tick's setting tickFrequencySize = (size.Width * this.TickFrequency / (this.Maximum - this.Minimum)); string text = ""; FormattedText formattedText = null; double num = this.Maximum - this.Minimum; int i = 0; // Draw each tick text for (i = 0; i <= tickCount; i++) { text = Convert.ToString(Convert.ToInt32(this.Minimum + this.TickFrequency * i), 10); //g.DrawString(text, font, brush, drawRect.Left + tickFrequencySize * i, drawRect.Top + drawRect.Height/2, stringFormat); formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("ru-Ru"), FlowDirection.LeftToRight, new Typeface("Arial"), 8, Brushes.Black); dc.DrawText(formattedText, new Point((tickFrequencySize * i), 30)); } }
/// <summary> /// Prints this instance. /// </summary> public bool Print() { try { PrintDialog printDlg = new System.Windows.Controls.PrintDialog(); bool? results = printDlg.ShowDialog(); if (results == null || results == false) return false; //get selected printer capabilities System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket); //get the size of the printer page System.Windows.Size printSize = new System.Windows.Size( capabilities.PageImageableArea.ExtentHeight, capabilities.PageImageableArea.ExtentWidth); // Build print view this.Height = printSize.Height; this.Width = printSize.Width; Measure(printSize); Arrange(new System.Windows.Rect(printSize)); XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue); printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape; xpsdw.WriteAsync(this); } catch (Exception ex) { MessageBox.Show(ex.GetBaseException().Message, "Printing Error", MessageBoxButton.OK, MessageBoxImage.Error); return false; } return true; }
protected override Size ArrangeOverride(Size finalSize) { if (Children.Count == 0) return finalSize; var children = Children.OfType<UIElement>().ToArray(); var actualTop = 0d; var currentNumOfChildrenInRow = 0; foreach (var child in children) { child.Arrange(new Rect( _elementWidth * currentNumOfChildrenInRow, actualTop, _elementWidth, _elementHeight)); currentNumOfChildrenInRow++; if (currentNumOfChildrenInRow != _maxElementPerRow) continue; actualTop += _elementHeight; currentNumOfChildrenInRow = 0; } var size = new Size( _elementWidth * _maxElementPerRow, actualTop + _elementHeight); size.Width = Math.Max(size.Width, finalSize.Width); size.Height = Math.Max(size.Height, finalSize.Height); return size; }
protected override Size MeasureOverride(Size availableSize) { onPreApplyTemplate(); Size theChildSize = getItemSize(); foreach (UIElement child in Children) { child.Measure(theChildSize); } int childrenPerRow; // Figure out how many children fit on each row if (availableSize.Width == Double.PositiveInfinity) { childrenPerRow = this.Children.Count; } else { childrenPerRow = Math.Max(1, (int)Math.Floor(availableSize.Width / this.ItemWidth)); } // Calculate the width and height this results in double width = childrenPerRow * this.ItemWidth; var fudge = (width - childrenPerRow * ItemWidth) / childrenPerRow; double height = (this.ItemHeight +fudge )* (Math.Floor((double)(this.Children.Count +childrenPerRow - 1) / childrenPerRow) ); height = (height.IsValid()) ? height : 0; return new Size(width, height); }
protected override Size MeasureOverride(Size availableSize) { if (Children.Count == 0) return new Size(); var children = Children.OfType<UIElement>().ToArray(); // Damit die Children eine DesiredSize haben, muss erstmal Measure gemacht werden children.ForEachElement(it => it.Measure(availableSize)); // Was ist das breiteste / höchste Element? var widestWidth = children.Max(it => it.DesiredSize.Width); _elementHeight = children.Max(it => it.DesiredSize.Height); // Wieviele Elemente bekommt man in eine Zeile? _maxElementPerRow = (int)(availableSize.Width / widestWidth); if (_maxElementPerRow == 0) _maxElementPerRow = 1; _elementWidth = availableSize.Width / _maxElementPerRow; var resultingHeight = ((children.Count() - 1) / _maxElementPerRow + 1) * _elementHeight; var desiredSize = new Size(availableSize.Width, resultingHeight); return desiredSize; }
protected override Size ArrangeOverride(Size finalSize) { if (GetValues(this) != null) { double total = 0.0; for (int i = 0; i < InternalChildren.Count; i++) { total += (double)(GetValues(this)[i]); } double offsetAngle = 0.0; double radius = finalSize.Width < finalSize.Height ? finalSize.Width / 2 : finalSize.Height / 2; //radius -= 2; Point beginFigure = new Point(finalSize.Width / 2, finalSize.Height / 2); Point lineToBeforeTransform = new Point(beginFigure.X + radius, beginFigure.Y); for (int i = 0; i < InternalChildren.Count; i++) { ContentControl container = InternalChildren[i] as ContentControl; double wedgeAngle = (double)(GetValues(this)[i]) * 360 / total; RotateTransform rt = new RotateTransform(offsetAngle, beginFigure.X, beginFigure.Y); container.SetValue(PiePanel.BeginFigurePointProperty, beginFigure); container.SetValue(PiePanel.LineToPointProperty, rt.Transform(lineToBeforeTransform)); container.SetValue(PiePanel.WedgeAngleProperty, wedgeAngle); offsetAngle += wedgeAngle; Rect r = new Rect(finalSize); container.Arrange(r); } } return finalSize; }
private FixedPage CreateFifthPageContent() { //PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); UIElement visual = BuildDrawing(); // CreateThirdVisual(false); FixedPage.SetLeft(visual, 0); FixedPage.SetTop(visual, 0); double pageWidth = 96 * 8.5; double pageHeight = 96 * 11; fixedPage.Width = pageWidth; fixedPage.Height = pageHeight; fixedPage.Children.Add((UIElement)visual); Size sz = new Size(8.5 * 96, 11 * 96); fixedPage.Measure(sz); fixedPage.Arrange(new Rect(new Point(), sz)); fixedPage.UpdateLayout(); //((IAddChild)pageContent).AddChild(fixedPage); return fixedPage; }
/// <summary> /// Overrides MeasureOverride /// </summary> /// <param name="availableSize"></param> /// <returns></returns> protected override Size MeasureOverride(Size availableSize) { if (Symbol is ESRI.ArcGIS.Client.Symbols.FillSymbol || Symbol is ESRI.ArcGIS.Client.Symbols.LineSymbol) { SetPath(availableSize); return base.MeasureOverride(availableSize); } else if (Symbol is ESRI.ArcGIS.Client.Symbols.MarkerSymbol) { // Set the margin to null else the desiredsize would be impacted by this margin // For example with a negative margin, the desired size is going towards 0 which can't be the right size of the swatch UIElement child = GetChild(); if (child is FrameworkElement) ((FrameworkElement)child).Margin = new Thickness(0.0); // Now measure without the margin child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Size size = child.DesiredSize; // Take care of the child transform to define the size of the swatch // For example with a scale of 2, the swatch size must be twice the desired size // with a rotation, the swatch size must take care of this rotation Transform childTransform = child == null ? null : child.RenderTransform; if (childTransform != null) { Rect rect = childTransform.TransformBounds(new Rect(new Point(0, 0), size)); size.Height = rect.Height; size.Width = rect.Width; } return size; } else return base.MeasureOverride(availableSize); }
/// <summary> /// Provides the behavior for the Arrange pass of Silverlight layout. Classes can override this method to define their own Arrange pass behavior. /// </summary> /// <param name="finalSize">The final area within the parent that this object should use to arrange itself and its children.</param> /// <returns> /// The actual size that is used after the element is arranged in layout. /// </returns> protected override Size ArrangeOverride(Size finalSize) { if (Symbol is ESRI.ArcGIS.Client.Symbols.MarkerSymbol) { UIElement child = GetChild(); Transform childTransform = child == null ? null : child.RenderTransform; if (childTransform != null) { // Arrange the symbol following it's desired size, the final size which is taking care of the transform is not the good one Size size = child.DesiredSize.Height == 0 && child.DesiredSize.Width == 0 ? finalSize : child.DesiredSize; child.Arrange(new Rect(new Point(0, 0), size)); // Now we need to translate the symbol in order that the visual part of the symbol be in the snapshot Rect rect = childTransform.TransformBounds(new Rect(new Point(0, 0), child.DesiredSize)); // visual position of the symbol after transformation child.RenderTransformOrigin = new Point(0, 0); // for the swatch, the transform origin must be (0,0) whatever the transform origin used in the map if (rect.X != 0 || rect.Y != 0) RenderTransform = new TranslateTransform { X = -rect.X, Y = -rect.Y }; // Center the symbol return finalSize; } } return base.ArrangeOverride(finalSize); }
/// <inheritdoc/> protected override Size MeasureOverride(Size availableSize) { foreach (FoldingMarginMarker m in markers) { m.Measure(availableSize); } return new Size(SizeFactor * (double)GetValue(TextBlock.FontSizeProperty), 0); }
private void OnDragInitialize(object sender, DragInitializeEventArgs args) { args.AllowedEffects = DragDropEffects.All; if (args.OriginalSource.GetType() == typeof(Telerik.Windows.Controls.RadListBoxItem)) { var draggedShape = (args.OriginalSource as Telerik.Windows.Controls.RadListBoxItem).ChildrenOfType<RadDiagramShapeBase>().FirstOrDefault(); if (draggedShape != null) { var shapeSize = new Size(draggedShape.ActualWidth, draggedShape.ActualHeight); if (shapeSize.Width > 0 && shapeSize.Height > 0) { var dropInfo = new DiagramDropInfo(shapeSize, SerializationService.Default.SerializeItems(new List<IDiagramItem> {draggedShape})); args.Data = dropInfo; args.DragVisualOffset = new Point(args.RelativeStartPoint.X - (shapeSize.Width / 2), args.RelativeStartPoint.Y - (shapeSize.Height / 2)); var draggingImage = new System.Windows.Controls.Image { Source = new Telerik.Windows.Media.Imaging.RadBitmap(draggedShape).Bitmap, Width = shapeSize.Width, Height = shapeSize.Height }; args.DragVisual = draggingImage; } } } }
/// <summary> /// Calculate the actual size because it is unknown otherwise, since we /// are using a canvas. /// </summary> protected override Size MeasureOverride(Size constraint) { Size size = new Size(); foreach (UIElement element in this.InternalChildren) { double left = Canvas.GetLeft(element); double top = Canvas.GetTop(element); left = double.IsNaN(left) ? 0 : left; top = double.IsNaN(top) ? 0 : top; //measure desired size for each child element.Measure(constraint); Size desiredSize = element.DesiredSize; if (!double.IsNaN(desiredSize.Width) && !double.IsNaN(desiredSize.Height)) { size.Width = Math.Max(size.Width, left + desiredSize.Width); size.Height = Math.Max(size.Height, top + desiredSize.Height); } } // add margin size.Width += 10; size.Height += 10; return size; }
protected override Size MeasureOverride(Size availableSize) { dynamicOrder.Clear(); foreach (UIElement e in Children) e.Measure(infiniteSize); if (RowsToRender == 2) { Size size = FitsInDynamicRows(availableSize, 2, Children); if (!size.IsEmpty) return size; } else { List<UIElement> ordered = (from UIElement e in Children orderby e.DesiredSize.Width descending select e).ToList(); bool swap = false; IEnumerable<UIElement> elements; while ((elements = Get3Elements(ordered, swap)) != null) { swap ^= true; foreach (UIElement e in elements) dynamicOrder.Add(e); } Size size = FitsInDynamicRows(availableSize, 3, dynamicOrder); if (!size.IsEmpty) return size; } return new Size(48, 3*MaxSmallHeight); }
/// <inheritdoc/> protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); var hwndSource = PresentationSource.FromVisual(this) as HwndSource; Debug.Assert(hwndSource != null); if (hwndSource != null) { hwndSource.AddHook(WndProc); wpfDpi = new Size(96.0 * hwndSource.CompositionTarget.TransformToDevice.M11, 96.0 * hwndSource.CompositionTarget.TransformToDevice.M22); var w = Width; var h = Height; WindowDpi = GetDpi(hwndSource.Handle) ?? wpfDpi; // For some reason, we can't initialize the non-fit-to-size property, so always force // manual mode. When we're here, we should already have a valid Width and Height Debug.Assert(h > 0 && !double.IsNaN(h)); Debug.Assert(w > 0 && !double.IsNaN(w)); SizeToContent = SizeToContent.Manual; if (!wpfSupportsPerMonitorDpi) { double scale = DisableDpiScalingAtStartup ? 1 : WpfPixelScaleFactor; Width = w * scale; Height = h * scale; if (WindowStartupLocation == WindowStartupLocation.CenterOwner || WindowStartupLocation == WindowStartupLocation.CenterScreen) { Left -= (w * scale - w) / 2; Top -= (h * scale - h) / 2; } } } WindowUtils.UpdateWin32Style(this); }
public ZoomableInlineAdornment(UIElement content, ITextView parent, Size desiredSize) { _parent = parent; Debug.Assert(parent is IInputElement); _originalSize = _desiredSize = new Size( Math.Max(double.IsNaN(desiredSize.Width) ? 100 : desiredSize.Width, 10), Math.Max(double.IsNaN(desiredSize.Height) ? 100 : desiredSize.Height, 10) ); // First time through, we want to reduce the image to fit within the // viewport. if (_desiredSize.Width > parent.ViewportWidth) { _desiredSize.Width = parent.ViewportWidth; _desiredSize.Height = _originalSize.Height / _originalSize.Width * _desiredSize.Width; } if (_desiredSize.Height > parent.ViewportHeight) { _desiredSize.Height = parent.ViewportHeight; _desiredSize.Width = _originalSize.Width / _originalSize.Height * _desiredSize.Height; } ContextMenu = MakeContextMenu(); Focusable = true; MinWidth = MinHeight = 50; Children.Add(content); GotFocus += OnGotFocus; LostFocus += OnLostFocus; }
protected override Size MeasureOverride(Size availableSize) { m_itemHeight = ItemRender.ItemHeight; ScrollMax = Math.Max(0, m_itemHeight* (m_list == null? 0 : m_list.Count) - m_clipSize.Height + 2 * m_itemHeight); ViewportSize = m_clipSize.Height; return new Size(Width, ScrollMax ); }
public IClipboardObject AddAsHtml(FrameworkElement fe, Size imageSize, Size imageElementSize) { if (fe == null) throw new NullReferenceException(nameof(fe)); var bmp = fe.RenderToBitmap(imageSize); var img_src = string.Empty; var use_inline_image = false; if (use_inline_image) { // Inline images are not actually supported by Office applications, so don't use it. // maybe in future... var img_data = bmp.ToBitmap().ToArray(); var base64_img_data = Convert.ToBase64String(img_data); img_src = $"data:image/png;charset=utf-8;base64, {base64_img_data}"; } else { // create a temp file with image and use it as a source var tmp = Path.GetTempFileName(); bmp.Save(tmp); img_src = new Uri(tmp, UriKind.Absolute).ToString(); } var html_data = CF_HTML.PrepareHtmlFragment($"<img height=\"{imageElementSize.Height}\" width=\"{imageElementSize.Width}\" src=\"{img_src}\" />"); Data.SetData(DataFormats.Html, html_data); return this; }
protected override Size MeasureOverride(Size availableSize) { _perimeter = 0; _maxChildHeight = 0; // Find the tallest child and determine the perimeter // based on the width of all of the children after // measuring all of the them and letting them size // to content by passing Double.PositiveInfinity as // the available size. foreach (UIElement uie in Children) { uie.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); _perimeter += uie.DesiredSize.Width; _maxChildHeight = Math.Max(_maxChildHeight, uie.DesiredSize.Height); } // If the marginal angle is not 0, 90 or 180 // then the adjustFactor is needed. if (Children.Count > 2 && Children.Count != 4) _adjustFactor = 10; // Determine the radius of the circle layout and determine // the RadialPanel's DesiredSize. _radius = _perimeter / (2 * Math.PI) + _adjustFactor; double _squareSize = 2 * (_radius + _maxChildHeight); return new Size(_squareSize, _squareSize); }
protected override Size MeasureOverride(Size availableSize) { Size infiniteSize = new Size(double.PositiveInfinity, double.PositiveInfinity); double curX = 0, curY = 0, curLineHeight = 0; foreach (UIElement child in Children) { child.Measure(infiniteSize); if (curX + child.DesiredSize.Width > availableSize.Width) { //Wrap to next line curY += curLineHeight; curX = 0; curLineHeight = 0; } curX += child.DesiredSize.Width; if (child.DesiredSize.Height > curLineHeight) curLineHeight = child.DesiredSize.Height; } curY += curLineHeight; Size resultSize = new Size(); resultSize.Width = double.IsPositiveInfinity(availableSize.Width) ? curX : availableSize.Width; resultSize.Height = double.IsPositiveInfinity(availableSize.Height) ? curY : availableSize.Height; return resultSize; }
protected override Size ArrangeOverride (Size finalSize) { Tester.WriteLine ("ArrangeOverride input = " + finalSize.ToString ()); Size output = base.MeasureOverride (finalSize); Tester.WriteLine ("ArrangeOverride output = " + output.ToString ()); return output; }
public PageCompositor(BookModel book, int fontSize, Size pageSize, IList<BookImage> images) { _book = book; _fontSize = fontSize; _pageSize = pageSize; _images = images; }
protected override Size ArrangeOverride(Size finalSize) { if(ParentRow == null) return base.ArrangeOverride(finalSize); double totalWidth = 0d; Children.OfType<TimespanHeaderCell>().ToList().ForEach(cell => { double width = cell.DesiredSize.Width; double x = totalWidth + ParentRow.CellBorderThickness.Left + ParentRow.CellBorderThickness.Right; if (x + width > finalSize.Width) { width -= (x + width) - finalSize.Width; } if (width < 0) width = 0; cell.Arrange(new Rect(x, 0, width, finalSize.Height)); totalWidth += width; } ); return finalSize; }
//------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- #region Protected Methods /// <summary> /// Content measurement. /// </summary> /// <param name="constraint">Constraint size.</param> /// <returns>Computed desired size.</returns> protected sealed override Size MeasureOverride(Size constraint) { Size desiredSize = new Size(); if (_suspendLayout) { desiredSize = this.DesiredSize; } else if (Document != null) { // Create bottomless formatter, if necessary. EnsureFormatter(); // Format bottomless content. _formatter.Format(constraint); // DesiredSize is set to the calculated size of the page. // If hosted by ScrollViewer, desired size is limited to constraint. if (_scrollData != null) { desiredSize.Width = Math.Min(constraint.Width, _formatter.DocumentPage.Size.Width); desiredSize.Height = Math.Min(constraint.Height, _formatter.DocumentPage.Size.Height); } else { desiredSize = _formatter.DocumentPage.Size; } } return desiredSize; }
protected override Size ArrangeOverride( Size finalSize ) { foreach ( UIElement child in this.InternalChildren ) { child.Arrange( new Rect( new Point( 0, 0 ), child.DesiredSize ) ); } return finalSize; }
protected override Size MeasureOverride (Size availableSize) { Tester.WriteLine ("MeasureOverride input = " + availableSize.ToString ()); Size output = base.MeasureOverride (availableSize); Tester.WriteLine ("MeasureOverride output = " + output.ToString ()); return output; }
/// <summary> /// Measures the size required for all the child elements in this panel. /// </summary> /// <param name="constraint">The size constraint given by our parent.</param> /// <returns>The requested size for this panel including all children</returns> protected override Size MeasureOverride(Size constraint) { double col1Width = 0; double col2Width = 0; RowHeights.Clear(); // First, measure all the left column children for (int i = 0; i < VisualChildrenCount; i += 2) { var child = Children[i]; child.Measure(constraint); col1Width = Math.Max(child.DesiredSize.Width, col1Width); RowHeights.Add(child.DesiredSize.Height); } // Then, measure all the right column children, they get whatever remains in width var newWidth = Math.Max(0, constraint.Width - col1Width - ColumnSpacing); Size newConstraint = new Size(newWidth, constraint.Height); for (int i = 1; i < VisualChildrenCount; i += 2) { var child = Children[i]; child.Measure(newConstraint); col2Width = Math.Max(child.DesiredSize.Width, col2Width); RowHeights[i / 2] = Math.Max(RowHeights[i / 2], child.DesiredSize.Height); } Column1Width = col1Width; return new Size( col1Width + ColumnSpacing + col2Width, RowHeights.Sum() + ((RowHeights.Count - 1) * RowSpacing)); }
protected override sw.Size MeasureOverride(sw.Size constraint) { var size = base.MeasureOverride(constraint); // WPF has problems with multiple rows or columns with GridUnitType.Star // 1) it doesn't autosize correctly to the largest row/column // 2) it doesn't position elements correctly until next layout pass if (RowDefinitions.Count > 1 && (double.IsInfinity(constraint.Height) || !IsLoaded)) { double maxHeight = 0; double totalHeight = 0; int totalRows = 0; for (int i = 0; i < RowDefinitions.Count; i++) { var rd = RowDefinitions[i]; if (rd.Height.IsStar) { double rowHeight = 0; for (int childIndex = 0; childIndex < Children.Count; childIndex++) { var child = Children[childIndex]; var row = GetRow(child); if (row != i) { continue; } //child.Measure(constraint); var desired = child.DesiredSize.Height; if (!double.IsInfinity(desired)) { rowHeight = Math.Max(rowHeight, desired); } } maxHeight = Math.Max(rowHeight, maxHeight); totalHeight += rowHeight; totalRows++; } } if (totalRows > 1) { size.Height = Math.Max(0, size.Height - totalHeight + maxHeight * totalRows); } } if (ColumnDefinitions.Count > 1 && (double.IsInfinity(constraint.Width) || !IsLoaded)) { double maxWidth = 0; double totalWidth = 0; int totalColumns = 0; for (int i = 0; i < ColumnDefinitions.Count; i++) { var cd = ColumnDefinitions[i]; if (cd.Width.IsStar) { double columnWidth = 0; for (int childIndex = 0; childIndex < Children.Count; childIndex++) { var child = Children[childIndex]; var row = GetColumn(child); if (row != i) { continue; } //child.Measure(constraint); var desired = child.DesiredSize.Width; if (!double.IsInfinity(desired)) { columnWidth = Math.Max(columnWidth, desired); } } maxWidth = Math.Max(columnWidth, maxWidth); totalWidth += columnWidth; totalColumns++; } } if (totalColumns > 1) { size.Width = Math.Max(0, size.Width - totalWidth + maxWidth * totalColumns); } } return(size); }
public static Bitmap ToBitmap(this UIElement element, Size size, PixelFormat pixelFormat) { return(element.ToRenderTargetBitmap(size, pixelFormat) .ToBitmap()); }
/// <summary> /// Method that starts or pauses the recording /// </summary> private async void RecordPause() { Extras.CreateTemp(_pathTemp); switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / FpsIntegerUpDown.Value }; _snapDelay = null; ListFrames = new List <FrameInfo>(); FrameCount = 0; await Task.Factory.StartNew(UpdateScreenDpi); #region Sizing if (UserSettings.All.FullScreenMode) { _size = new Size((int)_sizeScreen.X, (int)_sizeScreen.Y); } else { _size = new Size((int)Math.Round((Width - Constants.HorizontalOffset) * _scale), (int)Math.Round((Height - Constants.VerticalOffset) * _scale)); } #endregion HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsIntegerUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); UnregisterEvents(); #region Start if (UserSettings.All.UsePreStart) { Title = $"Screen To Gif ({FindResource("Recorder.PreStart")} 2s)"; RecordPauseButton.IsEnabled = false; Stage = Stage.PreStarting; _preStartCount = 1; //Reset timer to 2 seconds, 1 second to trigger the timer so 1 + 1 = 2 _preStartTimer.Start(); } else { if (UserSettings.All.ShowCursor) { #region If Show Cursor if (!UserSettings.All.FullScreenMode) { if (UserSettings.All.AsyncRecording) { _capture.Tick += CursorAsync_Elapsed; } else { _capture.Tick += Cursor_Elapsed; } _capture.Start(); } else { _capture.Tick += FullCursor_Elapsed; _capture.Start(); } Stage = Stage.Recording; AutoFitButtons(); #endregion } else { #region If Not if (!UserSettings.All.FullScreenMode) { if (UserSettings.All.AsyncRecording) { _capture.Tick += NormalAsync_Elapsed; } else { _capture.Tick += Normal_Elapsed; } _capture.Start(); } else { _capture.Tick += Full_Elapsed; _capture.Start(); } Stage = Stage.Recording; AutoFitButtons(); #endregion } } break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = "Screen To Gif"; DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; #endregion } }
public static SizeF ToEto(this sw.Size value) { return(new SizeF((float)value.Width, (float)value.Height)); }
protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint) { // Ask for no space Child.Measure(new System.Windows.Size(0, 0)); return(new System.Windows.Size(0, 0)); }
protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint) { var s = base.MeasureOverride(constraint); return(Backend.MeasureOverride(constraint, s)); }
/// <summary> /// Arrange the children in the panel using the calculations from measure pass. /// </summary> /// <param name="finalSize">Total area available to arrange the controls</param> /// <returns>Total used area</returns> protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize) { double closedExpandersTotalHeight = 0; // Total minimum height required by closed expanders and expanders with user defined height. double openExpandersTotalHeight = 0; // Total size asked by all open expanders foreach (UIElement child in this.Children) { Expander childExpander = child as Expander; if (childExpander != null) { // Get a height if user has resized double?userHeight = (double?)childExpander.GetValue(UserDefinedSizeProperty); if (userHeight != null) { closedExpandersTotalHeight += (double)userHeight; } else if (childExpander.IsExpanded) { openExpandersTotalHeight += childExpander.DesiredSize.Height; } else { closedExpandersTotalHeight += childExpander.DesiredSize.Height; } } else if (child as VerticalDragThumb != null) { closedExpandersTotalHeight += child.DesiredSize.Height; } } // Start arranging double usedHeight = 0; double usedWidth = 0; double openSpace = finalSize.Height - closedExpandersTotalHeight; double openHeightDistributionFactor = openSpace / openExpandersTotalHeight; // Multiplication factor for distributing available free space double currentChildHeight = 0; foreach (UIElement child in this.Children) { Expander childExpander = child as Expander; if (childExpander != null) { double?userHeight = (double?)childExpander.GetValue(UserDefinedSizeProperty); // Find height to allocate if (userHeight != null) { currentChildHeight = (double)userHeight; } else if (childExpander.IsExpanded) { currentChildHeight = child.DesiredSize.Height * openHeightDistributionFactor; } else { currentChildHeight = childExpander.DesiredSize.Height; } // Set height property so that its contents wont draw beyond this height childExpander.Height = currentChildHeight - (childExpander.Margin.Top + childExpander.Margin.Bottom + childExpander.Padding.Top + childExpander.Padding.Bottom); childExpander.Arrange( new Rect(0, usedHeight, finalSize.Width, currentChildHeight )); childExpander.SetValue(AllocatedSizeProperty, currentChildHeight); } else if (child as VerticalDragThumb != null) { currentChildHeight = child.DesiredSize.Height; child.Arrange(new Rect(0, usedHeight, finalSize.Width, child.DesiredSize.Height)); } usedHeight += currentChildHeight; usedWidth = child.DesiredSize.Width > usedWidth ? child.DesiredSize.Width : usedWidth; } return(new Size(finalSize.Width, usedHeight)); }
private PathFigureCollection GetFigures() { List <PathFigure> figures = new List <PathFigure>(); // 원 중심 (Xc, Yc)이고 반지름 r을 가지는 // 원의 방정식 : (x - Xc)^2 + (y - Yc)^2 = r^2 // y = Yc ± Math.Sqrt(Math.Pow(r,2) - Math.Pow(x - Xc, 2)); // x = Xc ± Math.Sqrt(Math.Pow(r,2) - Math.Pow(y - Yc, 2)); double centerX = Circle.Center.X; double centerY = Circle.Center.Y; double r = Circle.Radius; double w = m_InputImage.Width; double h = m_InputImage.Height; double distX = Math.Abs(centerY); double distY = Math.Abs(centerX); double distW = Math.Abs(centerX - w); double distH = Math.Abs(centerY - h); var size = new System.Windows.Size(r, r); int location = (distX < r ? 1 : 0) + (distY < r ? 2 : 0) + (distH < r ? 4 : 0) + (distW < r ? 8 : 0); double tmpXVal = Math.Pow(r, 2) >= Math.Pow(centerY, 2) ? Math.Sqrt(Math.Pow(r, 2) - Math.Pow(centerY, 2)) : 0; double tmpYVal = Math.Pow(r, 2) >= Math.Pow(centerX, 2) ? Math.Sqrt(Math.Pow(r, 2) - Math.Pow(centerX, 2)) : 0; double tmpWVal = Math.Pow(r, 2) >= Math.Pow(centerX - w, 2) ? Math.Sqrt(Math.Pow(r, 2) - Math.Pow(w - centerX, 2)) : 0; double tmpHVal = Math.Pow(r, 2) >= Math.Pow(centerY - h, 2) ? Math.Sqrt(Math.Pow(r, 2) - Math.Pow(h - centerY, 2)) : 0; switch (location) { // 원이 이미지 안에 온전히 있거나 완전히 벗어난 경우, case 0: break; // 원이 y = 0 인 직선에만 두 점에 걸린 경우, case 1: //원이 이미지 밖을 벗어난 경우, if (centerX < -r || centerX > w + r) { break; } var loc1_p0 = new Point(centerX - tmpXVal, 0); var loc1_p1 = new Point(centerX + tmpXVal, 0); bool loc1_isLargeArc = centerY > 0 ? true : false; figures.Add(new PathFigure(loc1_p1, new ArcSegment[] { new ArcSegment(loc1_p0, size, 0, loc1_isLargeArc, SweepDirection.Clockwise, true) }, false)); break; // 원이 x = 0 인 직선에만 두 점에 걸린 경우, case 2: //원이 이미지 밖을 벗어난 경우, if (centerY < -r || centerY > h + r) { break; } var loc2_p0 = new Point(0, centerY - tmpYVal); var loc2_p1 = new Point(0, centerY + tmpYVal); var loc2_isLargeArc = centerX > 0 ? true : false; figures.Add(new PathFigure(loc2_p0, new ArcSegment[] { new ArcSegment(loc2_p1, size, 0, loc2_isLargeArc, SweepDirection.Clockwise, true) }, false)); break; // 원이 y = h 인 직선에만 두 점에 걸린 경우, case 4: //원이 이미지 밖을 벗어난 경우, if (centerX < -r || centerX > w + r) { break; } var loc4_p0 = new Point(centerX - tmpHVal, h); var loc4_p1 = new Point(centerX + tmpHVal, h); bool loc4_isLargeArc = centerY < h ? true : false; figures.Add(new PathFigure(loc4_p0, new ArcSegment[] { new ArcSegment(loc4_p1, size, 0, loc4_isLargeArc, SweepDirection.Clockwise, true) }, false)); break; // 원이 x = w 인 직선에만 두 점에 걸린 경우, case 8: //원이 이미지 밖을 벗어난 경우, if (centerY < -r || centerY > h + r) { break; } var loc8_p0 = new Point(w, centerY - tmpWVal); var loc8_p1 = new Point(w, centerY + tmpWVal); bool loc8_isLargeArc = centerX < w ? true : false; figures.Add(new PathFigure(loc8_p1, new ArcSegment[] { new ArcSegment(loc8_p0, size, 0, loc8_isLargeArc, SweepDirection.Clockwise, true) }, false)); break; // 원이 y = 0 인 직선과 x = 0 인 직선에 각각 두 점에 걸린 경우, case 3: //원이 이미지 밖을 벗어난 경우, if (centerX < 0 && centerY < 0 && Math.Sqrt(Math.Pow(centerX, 2) + Math.Pow(centerY, 2)) > r) { break; } var loc3_p0 = new Point(centerX - tmpXVal, 0); var loc3_p1 = new Point(centerX + tmpXVal, 0); var loc3_p2 = new Point(0, centerY - tmpYVal); var loc3_p3 = new Point(0, centerY + tmpYVal); if (loc3_p0.X > 0 && loc3_p2.Y > 0) { figures.Add(new PathFigure(loc3_p2, new ArcSegment[] { new ArcSegment(loc3_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); figures.Add(new PathFigure(loc3_p1, new ArcSegment[] { new ArcSegment(loc3_p3, size, 0, true, SweepDirection.Clockwise, true) }, false)); } else if (loc3_p0.X > 0) { figures.Add(new PathFigure(loc3_p1, new ArcSegment[] { new ArcSegment(loc3_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else if (loc3_p2.Y > 0) { figures.Add(new PathFigure(loc3_p2, new ArcSegment[] { new ArcSegment(loc3_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc3_p1, new ArcSegment[] { new ArcSegment(loc3_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 y = 0 인 직선과 y = h 인 직선에 각각 두 점에 걸린 경우, case 5: //원이 이미지 밖을 벗어난 경우, if (centerX < -r || centerX > w + r) { break; } var loc5_p0 = new Point(centerX - tmpXVal, 0); var loc5_p1 = new Point(centerX + tmpXVal, 0); var loc5_p2 = new Point(centerX - tmpHVal, h); var loc5_p3 = new Point(centerX + tmpHVal, h); figures.Add(new PathFigure(loc5_p1, new ArcSegment[] { new ArcSegment(loc5_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); figures.Add(new PathFigure(loc5_p2, new ArcSegment[] { new ArcSegment(loc5_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); break; // 원이 y = 0 인 직선과 x = w 인 직선에 각각 두 점에 걸린 경우, case 9: //원이 이미지 밖을 벗어난 경우, if (centerX > w && centerY < 0 && Math.Sqrt(Math.Pow(centerX - w, 2) + Math.Pow(centerY, 2)) > r) { break; } var loc9_p0 = new Point(centerX - tmpXVal, 0); var loc9_p1 = new Point(centerX + tmpXVal, 0); var loc9_p2 = new Point(w, centerY - tmpWVal); var loc9_p3 = new Point(w, centerY + tmpWVal); if (loc9_p1.X < w && loc9_p2.Y > 0) { figures.Add(new PathFigure(loc9_p1, new ArcSegment[] { new ArcSegment(loc9_p2, size, 0, false, SweepDirection.Clockwise, true) }, false)); figures.Add(new PathFigure(loc9_p3, new ArcSegment[] { new ArcSegment(loc9_p0, size, 0, true, SweepDirection.Clockwise, true) }, false)); } else if (loc9_p1.X < w) { figures.Add(new PathFigure(loc9_p1, new ArcSegment[] { new ArcSegment(loc9_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else if (loc9_p2.Y > 0) { figures.Add(new PathFigure(loc9_p3, new ArcSegment[] { new ArcSegment(loc9_p2, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc9_p3, new ArcSegment[] { new ArcSegment(loc9_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 x = 0 인 직선과 y = h 인 직선에 각각 두 점에 걸린 경우, case 6: //원이 이미지 밖을 벗어난 경우, if (centerX < 0 && centerY > h && Math.Sqrt(Math.Pow(centerX, 2) + Math.Pow(centerY - h, 2)) > r) { break; } var loc6_p0 = new Point(0, centerY - tmpYVal); var loc6_p1 = new Point(0, centerY + tmpYVal); var loc6_p2 = new Point(centerX - tmpHVal, h); var loc6_p3 = new Point(centerX + tmpHVal, h); if (loc6_p0.X > 0 && loc6_p3.Y < h) { figures.Add(new PathFigure(loc6_p2, new ArcSegment[] { new ArcSegment(loc6_p1, size, 0, false, SweepDirection.Clockwise, true) }, false)); figures.Add(new PathFigure(loc6_p0, new ArcSegment[] { new ArcSegment(loc6_p3, size, 0, true, SweepDirection.Clockwise, true) }, false)); } else if (loc6_p0.X > 0) { figures.Add(new PathFigure(loc6_p1, new ArcSegment[] { new ArcSegment(loc6_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else if (loc6_p3.Y < h) { figures.Add(new PathFigure(loc6_p2, new ArcSegment[] { new ArcSegment(loc6_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc6_p0, new ArcSegment[] { new ArcSegment(loc6_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 x = 0 인 직선과 x = w 인 직선에 각각 두 점에 걸린 경우, case 10: //원이 이미지 밖을 벗어난 경우, if (centerY < -r || centerY > h + r) { break; } var loc10_p0 = new Point(0, centerY - tmpYVal); var loc10_p1 = new Point(0, centerY + tmpYVal); var loc10_p2 = new Point(w, centerY - tmpWVal); var loc10_p3 = new Point(w, centerY + tmpWVal); figures.Add(new PathFigure(loc10_p0, new ArcSegment[] { new ArcSegment(loc10_p2, size, 0, false, SweepDirection.Clockwise, true) }, false)); figures.Add(new PathFigure(loc10_p3, new ArcSegment[] { new ArcSegment(loc10_p1, size, 0, false, SweepDirection.Clockwise, true) }, false)); break; // 원이 y = h 인 직선과 x = w 인 직선에 각각 두 점에 걸린 경우, case 12: //원이 이미지 밖을 벗어난 경우, if (centerX > w && centerY > h && Math.Sqrt(Math.Pow(centerX - w, 2) + Math.Pow(centerY - h, 2)) > r) { break; } var loc12_p0 = new Point(centerX - tmpHVal, h); var loc12_p1 = new Point(centerX + tmpHVal, h); var loc12_p2 = new Point(w, centerY - tmpWVal); var loc12_p3 = new Point(w, centerY + tmpWVal); if (loc12_p1.X < w && loc12_p3.Y < h) { figures.Add(new PathFigure(loc12_p3, new ArcSegment[] { new ArcSegment(loc12_p1, size, 0, false, SweepDirection.Clockwise, true) }, false)); figures.Add(new PathFigure(loc12_p0, new ArcSegment[] { new ArcSegment(loc12_p2, size, 0, true, SweepDirection.Clockwise, true) }, false)); } else if (loc12_p1.X < w) { figures.Add(new PathFigure(loc12_p0, new ArcSegment[] { new ArcSegment(loc12_p1, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else if (loc12_p3.Y < h) { figures.Add(new PathFigure(loc12_p3, new ArcSegment[] { new ArcSegment(loc12_p2, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc12_p0, new ArcSegment[] { new ArcSegment(loc12_p2, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 y = 0 인 직선과 x = 0 인 직선, y = h 인 직선에 각각 두 점에 걸린 경우, case 7: var loc7_p0 = new Point(centerX - tmpXVal, 0); var loc7_p1 = new Point(centerX + tmpXVal, 0); var loc7_p2 = new Point(0, centerY - tmpYVal); var loc7_p3 = new Point(0, centerY + tmpYVal); var loc7_p4 = new Point(centerX - tmpHVal, h); var loc7_p5 = new Point(centerX + tmpHVal, h); if (loc7_p1.X > 0) { if (loc7_p5.X < 0) { figures.Add(new PathFigure(loc7_p1, new ArcSegment[] { new ArcSegment(loc7_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc7_p1, new ArcSegment[] { new ArcSegment(loc7_p5, size, 0, false, SweepDirection.Clockwise, true) }, false)); if (loc7_p0.X > 0) { figures.Add(new PathFigure(loc7_p2, new ArcSegment[] { new ArcSegment(loc7_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc7_p4.X > 0) { figures.Add(new PathFigure(loc7_p4, new ArcSegment[] { new ArcSegment(loc7_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } } } else if (loc7_p5.X > 0) { figures.Add(new PathFigure(loc7_p2, new ArcSegment[] { new ArcSegment(loc7_p5, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc7_p2, new ArcSegment[] { new ArcSegment(loc7_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 y = 0 인 직선과 x = 0 인 직선, x = w 인 직선에 각각 두 점에 걸린 경우, case 11: var loc11_p0 = new Point(centerX - tmpXVal, 0); var loc11_p1 = new Point(centerX + tmpXVal, 0); var loc11_p2 = new Point(0, centerY - tmpYVal); var loc11_p3 = new Point(0, centerY + tmpYVal); var loc11_p4 = new Point(w, centerY - tmpWVal); var loc11_p5 = new Point(w, centerY + tmpWVal); if (loc11_p5.Y > 0) { if (loc11_p3.Y < 0) { figures.Add(new PathFigure(loc11_p5, new ArcSegment[] { new ArcSegment(loc11_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc11_p5, new ArcSegment[] { new ArcSegment(loc11_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); if (loc11_p2.Y > 0) { figures.Add(new PathFigure(loc11_p2, new ArcSegment[] { new ArcSegment(loc11_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc11_p4.Y > 0) { figures.Add(new PathFigure(loc11_p1, new ArcSegment[] { new ArcSegment(loc11_p4, size, 0, false, SweepDirection.Clockwise, true) }, false)); } } } else if (loc11_p3.Y > 0) { figures.Add(new PathFigure(loc11_p1, new ArcSegment[] { new ArcSegment(loc11_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc11_p1, new ArcSegment[] { new ArcSegment(loc11_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 y = 0 인 직선과 y = h 인 직선, x = w 인 직선에 각각 두 점에 걸린 경우, case 13: var loc13_p0 = new Point(centerX - tmpXVal, 0); var loc13_p1 = new Point(centerX + tmpXVal, 0); var loc13_p2 = new Point(centerX - tmpHVal, h); var loc13_p3 = new Point(centerX + tmpHVal, h); var loc13_p4 = new Point(w, centerY - tmpWVal); var loc13_p5 = new Point(w, centerY + tmpWVal); if (loc13_p0.X < w) { if (loc13_p2.X > w) { figures.Add(new PathFigure(loc13_p5, new ArcSegment[] { new ArcSegment(loc13_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc13_p2, new ArcSegment[] { new ArcSegment(loc13_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); if (loc13_p3.X < w) { figures.Add(new PathFigure(loc13_p5, new ArcSegment[] { new ArcSegment(loc13_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc13_p1.X < w) { figures.Add(new PathFigure(loc13_p1, new ArcSegment[] { new ArcSegment(loc13_p4, size, 0, false, SweepDirection.Clockwise, true) }, false)); } } } else if (loc13_p2.X < w) { figures.Add(new PathFigure(loc13_p2, new ArcSegment[] { new ArcSegment(loc13_p4, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc13_p5, new ArcSegment[] { new ArcSegment(loc13_p4, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 x = 0 인 직선과 y = h 인 직선, x = w 인 직선에 각각 두 점에 걸린 경우, case 14: var loc14_p0 = new Point(0, centerY - tmpYVal); var loc14_p1 = new Point(0, centerY + tmpYVal); var loc14_p2 = new Point(centerX - tmpHVal, h); var loc14_p3 = new Point(centerX + tmpHVal, h); var loc14_p4 = new Point(w, centerY - tmpWVal); var loc14_p5 = new Point(w, centerY + tmpWVal); if (loc14_p0.Y < h) { if (loc14_p4.Y > h) { figures.Add(new PathFigure(loc14_p0, new ArcSegment[] { new ArcSegment(loc14_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc14_p0, new ArcSegment[] { new ArcSegment(loc14_p4, size, 0, false, SweepDirection.Clockwise, true) }, false)); if (loc14_p5.Y < h) { figures.Add(new PathFigure(loc14_p5, new ArcSegment[] { new ArcSegment(loc14_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc14_p1.Y < h) { figures.Add(new PathFigure(loc14_p2, new ArcSegment[] { new ArcSegment(loc14_p1, size, 0, false, SweepDirection.Clockwise, true) }, false)); } } } else if (loc14_p4.Y < h) { figures.Add(new PathFigure(loc14_p2, new ArcSegment[] { new ArcSegment(loc14_p4, size, 0, false, SweepDirection.Clockwise, true) }, false)); } else { figures.Add(new PathFigure(loc14_p2, new ArcSegment[] { new ArcSegment(loc14_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; // 원이 모든 직선에 각각 두 점에 걸린 경우, case 15: var loc15_p0 = new Point(centerX - tmpXVal, 0); var loc15_p1 = new Point(centerX + tmpXVal, 0); var loc15_p2 = new Point(0, centerY - tmpYVal); var loc15_p3 = new Point(0, centerY + tmpYVal); var loc15_p4 = new Point(centerX - tmpHVal, h); var loc15_p5 = new Point(centerX + tmpHVal, h); var loc15_p6 = new Point(w, centerY - tmpWVal); var loc15_p7 = new Point(w, centerY + tmpWVal); if (loc15_p0.X >= 0 && loc15_p0.X <= w && loc15_p2.Y >= 0 && loc15_p2.Y <= h) { figures.Add(new PathFigure(loc15_p2, new ArcSegment[] { new ArcSegment(loc15_p0, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc15_p1.X >= 0 && loc15_p1.X <= w && loc15_p6.Y >= 0 && loc15_p6.Y <= h) { figures.Add(new PathFigure(loc15_p1, new ArcSegment[] { new ArcSegment(loc15_p6, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc15_p5.X >= 0 && loc15_p5.X <= w && loc15_p7.Y >= 0 && loc15_p7.Y <= h) { figures.Add(new PathFigure(loc15_p7, new ArcSegment[] { new ArcSegment(loc15_p5, size, 0, false, SweepDirection.Clockwise, true) }, false)); } if (loc15_p4.X >= 0 && loc15_p4.X <= w && loc15_p3.Y >= 0 && loc15_p3.Y <= h) { figures.Add(new PathFigure(loc15_p4, new ArcSegment[] { new ArcSegment(loc15_p3, size, 0, false, SweepDirection.Clockwise, true) }, false)); } break; default: throw new Exception("Invalid location number."); } return(new PathFigureCollection(figures)); }
protected override Size MeasureOverride(Size availableSize) { return(new Size(24, 24)); }
public override sw.Size GetPreferredSize(sw.Size constraint) { return(base.GetPreferredSize(Conversions.ZeroSize)); }
public static sw.Size Subtract(this sw.Size size1, sw.Size size2) { return(new sw.Size(Math.Max(0, size1.Width - size2.Width), Math.Max(0, size1.Height - size2.Height))); }
private void Snap() { if (ListFrames.Count == 0) { #region If Fullscreen if (UserSettings.All.FullScreenMode) { _size = new Size((int)_sizeScreen.X, (int)_sizeScreen.Y); } else { _size = new Size((int)Math.Round((Width - Constants.HorizontalOffset) * _scale), (int)Math.Round((Height - Constants.VerticalOffset) * _scale)); } #endregion DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); IsRecording = true; } _snapDelay = UserSettings.All.SnapshotDefaultDelay; #region Take Screenshot (All possibles types) if (UserSettings.All.ShowCursor) { if (UserSettings.All.FullScreenMode) { FullCursor_Elapsed(null, null); } else { if (UserSettings.All.AsyncRecording) { CursorAsync_Elapsed(null, null); } else { Cursor_Elapsed(null, null); } } } else { if (UserSettings.All.FullScreenMode) { Full_Elapsed(null, null); } else { if (UserSettings.All.AsyncRecording) { NormalAsync_Elapsed(null, null); } else { Normal_Elapsed(null, null); } } } #endregion }
protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) { ControlRoot.Measure(availableSize.ToAvaloniaSize()); return(ControlRoot.DesiredSize.ToWpfSize()); }
// Whenever a control gets a change affecting its size/appearance, // it keep literaly *waiting* for a call to Arrange(), sometimes even if not truly needed. // In this cases ArrangeOverride is called, and we 'refresh' the controls that require it // (this is done by all the containers inheriting from Panel). protected override SW.Size ArrangeOverride(SW.Size finalSize) { ArrangeChildren(false); return(base.ArrangeOverride(finalSize)); }
/// <summary> /// When overridden in a derived class, measures the size in layout required for child elements and determines a size for the <see cref="T:System.Windows.FrameworkElement"/>-derived class. /// </summary> /// <returns> /// The size that this element determines it needs during layout, based on its calculations of child element sizes. /// </returns> /// <param name="availableSize">The available size that this element can give to child elements. Infinity can be specified as a value to indicate that the element will size to whatever content is available.</param> protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) { // Sort children leftChildren.Clear(); rightChildren.Clear(); otherChildren.Clear(); for (int i = 0; i < InternalChildren.Count; i++) { FrameworkElement child = InternalChildren[i] as FrameworkElement; if (child != null) { if (child.HorizontalAlignment == HorizontalAlignment.Left) { leftChildren.Add(child); } else if (child.HorizontalAlignment == HorizontalAlignment.Right) { rightChildren.Add(child); } else { otherChildren.Add(child); } } } lastRightIndex = rightChildren.Count; lastLeftIndex = leftChildren.Count; // Measure children Size infinity = new Size(double.PositiveInfinity, double.PositiveInfinity); Size zero = new Size(0, 0); double width = 0; double height = 0; bool canAdd = true; // Right children for (int i = 0; i < rightChildren.Count; i++) { if (canAdd) { rightChildren[i].Measure(infinity); height = Math.Max(rightChildren[i].DesiredSize.Height, height); if (width + rightChildren[i].DesiredSize.Width <= availableSize.Width) { width += rightChildren[i].DesiredSize.Width; } else { canAdd = false; rightChildren[i].Measure(zero); lastRightIndex = i; lastLeftIndex = 0; } } else { rightChildren[i].Measure(zero); } } // Left children for (int i = 0; i < leftChildren.Count; i++) { if (canAdd) { leftChildren[i].Measure(infinity); height = Math.Max(leftChildren[i].DesiredSize.Height, height); if (width + leftChildren[i].DesiredSize.Width <= availableSize.Width) { width += leftChildren[i].DesiredSize.Width; } else { canAdd = false; leftChildren[i].Measure(zero); lastLeftIndex = i; } } else { leftChildren[i].Measure(zero); } } // Collapse other children for (int i = 0; i < otherChildren.Count; i++) { otherChildren[i].Measure(zero); } return(new Size(width, height)); }
public static sw.Size Add(this sw.Size size1, sw.Size size2) { return(new sw.Size(size1.Width + size2.Width, size1.Height + size2.Height)); }
private void MakeBitmap() { while (true) { _newText.WaitOne(); GlyphTypeface glyphTypeface = null; if (_glyphTypeface != null) { lock (_glyphTypeface) { glyphTypeface = _glyphTypeface; } } if (glyphTypeface != null) { if (_lines == null || _lines.Length == 0) { _img = null; } else { if (_lines[0].VobSubMergedPack != null) { var bitmaps = _lines.Select(l => l.GetImage()).ToArray(); int bw = bitmaps.Max(b => b.Width); int bh = bitmaps.Sum(b => b.Height); BitmapSource bimage = CreateBitmap((int)bw, (int)bh, 96, dc => { double ypos = 0; for (int lb = 0; lb < bitmaps.Count(); lb++) { var bs = bitmaps[lb].ToBitmapSource(); Point bLoc = new Point((bw - bs.Width) / 2, ypos); Size bSize = new Size(bs.Width, bs.Height); ypos += bs.Height; dc.DrawImage(bs, new Rect(bLoc, bSize)); } }); bimage.Freeze(); _img = bimage; } else { var lines = new List <string>(_lines.Select(l => l.Text).SelectMany(t => t.Split(new string[] { Environment.NewLine }, 10000, StringSplitOptions.None))).ToArray(); { ushort[][] glyphIndexes = new ushort[lines.Length][]; double[][] advanceWidths = new double[lines.Length][]; double[] totalWidth = new double[lines.Length]; int l = 0; foreach (var text in lines) { glyphIndexes[l] = new ushort[text.Length]; advanceWidths[l] = new double[text.Length]; for (int n = 0; n < text.Length; n++) { if (glyphTypeface.CharacterToGlyphMap.ContainsKey(text[n])) { ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]]; glyphIndexes[l][n] = glyphIndex; double width = glyphTypeface.AdvanceWidths[glyphIndex] * _fontSize; advanceWidths[l][n] = width; totalWidth[l] += width; } } l++; } double w = totalWidth.Max(lw => lw) + _marginLeft + _marginRight; double h = (lines.Length * _fontSize) + _fontSize / 4 + _marginBottom; BitmapSource image = CreateBitmap((int)w, (int)h, 96, dc => { int line = 1; if (_back != Brushes.Transparent) { dc.DrawRectangle(_back, null, new Rect(0d, 0d, w, h)); } foreach (var text in lines) { if (string.IsNullOrEmpty(text)) { line++; continue; } var origin = new Point((w - totalWidth[line - 1]) / 2, line * _fontSize); var orig = ((SolidColorBrush)_stroke.Clone()).Color; var strokeBrush = new SolidColorBrush { Color = new Color() { B = orig.B, R = orig.R, G = orig.G, A = _strokeGlow ? (byte)35 : orig.A } }; var glyphRun = new GlyphRun(glyphTypeface, 0, false, _fontSize, glyphIndexes[line - 1], origin, advanceWidths[line - 1], null, null, null, null, null, null); if (_underline) { double y = origin.Y; y -= (glyphTypeface.Baseline + _typeface.UnderlinePosition * _fontSize); for (double i = _strokeThickness; i > 0; i--) { dc.DrawLine( new Pen(strokeBrush, (_typeface.UnderlineThickness * _fontSize) + i), new Point(origin.X - _strokeThickness / 2, y), new Point(origin.X + totalWidth[line - 1] + _strokeThickness / 2, y)); if (!_strokeGlow) { break; } } } var geo = glyphRun.BuildGeometry(); for (double i = _strokeThickness; i > 0; i--) { dc.DrawGeometry(null, new Pen(strokeBrush, i), geo); if (!_strokeGlow) { break; } } dc.DrawGlyphRun(_fill, glyphRun); if (_underline) { double y = origin.Y; y -= (glyphTypeface.Baseline + _typeface.UnderlinePosition * _fontSize); dc.DrawLine(new Pen(_fill, _typeface.UnderlineThickness * _fontSize), new Point(origin.X, y), new Point(origin.X + totalWidth[line - 1], y)); } line++; } }); image.Freeze(); _img = image; } } } } try { _newText.Release(); } catch { } Dispatcher.Invoke(((Action)(() => { _newText.WaitOne(); InvalidateVisual(); })), DispatcherPriority.Render, new object[] { }); } }
public OxFigure() { Color = SelectionLayer.GetInstance.CurrentColor; size = new Size(0, 0); }
public override sw.Size GetPreferredSize(sw.Size constraint) { return(base.GetPreferredSize(sw.Size.Empty)); }
/// <summary> /// Method that starts or pauses the recording /// </summary> internal async void RecordPause() { switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / FpsIntegerUpDown.Value }; _snapDelay = null; Project = new ProjectInfo().CreateProjectFolder(ProjectByType.ScreenRecorder); _keyList.Clear(); FrameCount = 0; await Task.Factory.StartNew(UpdateScreenDpi); //Sizing. _size = new Size((int)Math.Round((Width - Constants.HorizontalOffset) * _scale), (int)Math.Round((Height - Constants.VerticalOffset) * _scale)); HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsIntegerUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); UnregisterEvents(); #region Start if (UserSettings.All.UsePreStart) { Title = $"Screen To Gif ({FindResource("Recorder.PreStart")} {UserSettings.All.PreStartValue}s)"; RecordPauseButton.IsEnabled = false; Stage = Stage.PreStarting; _preStartCount = UserSettings.All.PreStartValue - 1; _preStartTimer.Start(); } else { if (UserSettings.All.ShowCursor) { #region If Show Cursor if (UserSettings.All.AsyncRecording) { _capture.Tick += CursorAsync_Elapsed; } else { _capture.Tick += Cursor_Elapsed; } _capture.Start(); Stage = Stage.Recording; AutoFitButtons(); #endregion } else { #region If Not if (UserSettings.All.AsyncRecording) { _capture.Tick += NormalAsync_Elapsed; } else { _capture.Tick += Normal_Elapsed; } _capture.Start(); Stage = Stage.Recording; AutoFitButtons(); #endregion } } break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = "Screen To Gif"; DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; #endregion } }
private static CustomPopupPlacement[] CustomPopupPlacementCallback(Size popupSize, Size targetSize, Point offset) { var p = new Point { Y = targetSize.Height - offset.Y, X = -offset.X }; return(new[] { new CustomPopupPlacement(p, PopupPrimaryAxis.Horizontal) }); }
public void UpdateWindowSize(System.Windows.Size CurrentWindowSize) { _CurrentDXWindowSize = DxContainer.ClientSize; needsReset = true; }
public void PerformOperation(object sender, RoutedEventArgs e) { RadioButton li = sender as RadioButton; // Strings used to display results String syntaxString, resultType, operationString; ///The local variables point1, point2, vector2, etc are defined in each ///case block for readability reasons. Each variable is contained within ///the scope of each case statement. switch (li.Name) { //begin switch case "rb1": { // Translates a Point by a Vector using the overloaded + operator. System.Windows.Point point1 = new System.Windows.Point(10, 5); Vector vector1 = new Vector(20, 30); System.Windows.Point pointResult = new System.Windows.Point(); pointResult = point1 + vector1; // pointResult is equal to (-10,-25) // Displaying Results syntaxString = "pointResult = point1 + vector1;"; resultType = "Point"; operationString = "Translating a Point by a Vector"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb2": { //<Snippet10> // Adds a Vector to a Vector using the overloaded + operator. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Vector vectorResult = new Vector(); // vectorResult is equal to (65,100) vectorResult = vector1 + vector2; //</Snippet10> // Displaying Results syntaxString = "vectorResult = vector1 + vector2;"; resultType = "Vector"; operationString = "Adding a Vector to a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb3": { // Adds a Vector to a Vector using the static Add method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Vector vectorResult = new Vector(); vectorResult = Vector.Add(vector1, vector2); // vectorResult is equal to (65,100) // Displaying Results syntaxString = "vectorResult = Vector.Add(vector1, vector2);"; resultType = "Vector"; operationString = "Adding a Vector to a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb4": { // Translates a Point by a Vector using the static Add method. Vector vector1 = new Vector(20, 30); System.Windows.Point point1 = new System.Windows.Point(10, 5); System.Windows.Point pointResult = new System.Windows.Point(); pointResult = Vector.Add(vector1, point1); // vectorResult is equal to (30,35) // Displaying Results syntaxString = "pointResult = Vector.Add(vector1, point1);"; resultType = "Point"; operationString = "Translating a Point by a Vector"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb5": { // Subtracts a Vector from a Vector using the overloaded - operator. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Vector vectorResult = new Vector(); vectorResult = vector1 - vector2; // vector Result is equal to (-25, -40) // Displaying Results syntaxString = "vectorResult = vector1 - vector2;"; resultType = "Vector"; operationString = "Subtracting a Vector from a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb6": { // Subtracts a Vector from a Vector using the static Subtract method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Vector vectorResult = new Vector(); vectorResult = Vector.Subtract(vector1, vector2); // vector Result is equal to (-25, -40) // Displaying Results syntaxString = "Vector.Subtract(vector1, vector2);"; resultType = "Vector"; operationString = "Subtracting a Vector from a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb7": { // Multiplies a Vector by a Scalar using the overloaded * operator. Vector vector1 = new Vector(20, 30); Double scalar1 = 75; Vector vectorResult = new Vector(); vectorResult = vector1 * scalar1; // vectorResult is equal to (1500,2250) // Displaying Results syntaxString = "vectorResult = vector1 * scalar1;"; resultType = "Vector"; operationString = "Multiplies a Vector by a Scalar"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb8": { // Multiplies a Scalar by a Vector using the overloaded * operator. Vector vector1 = new Vector(20, 30); Double scalar1 = 75; Vector vectorResult = new Vector(); vectorResult = scalar1 * vector1; // vectorResult is equal to (1500,2250) // Displaying Results syntaxString = "vectorResult = scalar1 * vector1;"; resultType = "Vector"; operationString = "Multiplies a Scalar by a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb9": { // Multiplies a Vector by a Vector using the overloaded * operator. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Double doubleResult; doubleResult = vector1 * vector2; // doubleResult is equal to 3000 // Displaying Results syntaxString = "doubleResult = vector1 * vector2;"; resultType = "Double"; operationString = "Multiplies a Vector by a Vector"; ShowResults(doubleResult.ToString(), syntaxString, resultType, operationString); break; } case "rb10": { // Multiplies a Vector by a Matrix using the overloaded * operator. Vector vector1 = new Vector(20, 30); Matrix matrix1 = new Matrix(40, 50, 60, 70, 80, 90); Vector vectorResult = new Vector(); vectorResult = vector1 * matrix1; // vector Result is equal to (2600,3100) // Displaying Results syntaxString = "vectorResult = vector1 * matrix1;"; resultType = "Vector"; operationString = "Multiplies a Vector by a Matrix"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb11": { // Multiplies a Vector by a Scalar using the static Multiply method. Vector vector1 = new Vector(20, 30); Double scalar1 = 75; Vector vectorResult = new Vector(); vectorResult = Vector.Multiply(vector1, scalar1); // vectorResult is equal to (1500,2250) // Displaying Results syntaxString = "vectorResult = Vector.Multiply(vector1, scalar1);"; resultType = "Vector"; operationString = "Multiplies a Vector by a Scalar"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb12": { // Multiplies a Scalar by a Vector using the static Multiply method. Vector vector1 = new Vector(20, 30); Double scalar1 = 75; Vector vectorResult = new Vector(); vectorResult = Vector.Multiply(scalar1, vector1); // vectorResult is equal to (1500,2250) // Displaying Results syntaxString = "vectorResult = Vector.Multiply(scalar1, vector1);"; resultType = "Vector"; operationString = "Multiplies a Scalar by a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb13": { // Multiplies a Vector by a Vector using the static Multiply method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Double doubleResult; doubleResult = Vector.Multiply(vector1, vector2); // doubleResult is equal to 3000 // Displaying Results syntaxString = "DoubleResult = Vector.Multiply(vector1,vector2);"; resultType = "Double"; operationString = "Multiplies a Vector by a Vector"; ShowResults(doubleResult.ToString(), syntaxString, resultType, operationString); break; } case "rb14": { // Multiplies a Vector by a Matrix using the static Multiply method. Vector vector1 = new Vector(20, 30); Matrix matrix1 = new Matrix(40, 50, 60, 70, 80, 90); Vector vectorResult = new Vector(); vectorResult = Vector.Multiply(vector1, matrix1); // vector Result is equal to (2600,3100) // Displaying Results syntaxString = "vectorResult = Vector.Multiply(vector1,matrix1);"; resultType = "Vector"; operationString = "Multiplies a Vector by a Matrix"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb15": { // Divides a Vector by a Scalar using the overloaded / operator. Vector vector1 = new Vector(20, 30); Vector vectorResult = new Vector(); Double scalar1 = 75; vectorResult = vector1 / scalar1; // vectorResult is approximately equal to (0.26667,0.4) // Displaying Results syntaxString = "vectorResult = vector1 / scalar1;"; resultType = "Vector"; operationString = "Dividing a Vector by a Scalar"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb16": { // Divides a Vector by a Double using the static Divide method. Vector vector1 = new Vector(20, 30); Vector vectorResult = new Vector(); Double scalar1 = 75; vectorResult = Vector.Divide(vector1, scalar1); // vectorResult is approximately equal to (0.26667,0.4) // Displaying Results syntaxString = "vectorResult = Vector.Divide(vector1, scalar1);"; resultType = "Vector"; operationString = "Dividing a Vector by a Scalar"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb17": { // Gets the hashcode of a Vector structure Vector vector1 = new Vector(20, 30); int vectorHashCode; vectorHashCode = vector1.GetHashCode(); // Displaying Results syntaxString = "vectorHashCode = vector1.GetHashCode();"; resultType = "int"; operationString = "Getting the hashcode of a Vector"; ShowResults(vectorHashCode.ToString(), syntaxString, resultType, operationString); break; } case "rb18": { // Gets the length of a Vector. Vector vector1 = new Vector(20, 30); Double length; length = vector1.Length; // length is approximately equal to 36.0555 // Displaying Results syntaxString = "length = vector1.Length();"; resultType = "Double"; operationString = "Getting the length of a Vector"; ShowResults(length.ToString(), syntaxString, resultType, operationString); break; } case "rb19": { // Gets the square of the length of a Vector. Vector vector1 = new Vector(20, 30); Double lengthSq; lengthSq = vector1.LengthSquared; // lengthSq is equal to 1300 // Displaying Results syntaxString = "lengthSq = vector1.LengthSquared;"; resultType = "Double"; operationString = "Getting the length square of a Vector"; ShowResults(lengthSq.ToString(), syntaxString, resultType, operationString); break; } case "rb20": { // Normalizes a Vector using the Normalize method. Vector vector1 = new Vector(20, 30); vector1.Normalize(); // vector1 is approximately equal to (0.5547,0.8321) // Displaying Results syntaxString = "vector1.Normalize();"; resultType = "Vector"; operationString = "Normalizing a Vector"; ShowResults(vector1.ToString(), syntaxString, resultType, operationString); break; } case "rb21": { // Calculates the angle between two Vectors using the static AngleBetween method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Double angleBetween; angleBetween = Vector.AngleBetween(vector1, vector2); // angleBetween is approximately equal to 0.9548 // Displaying Results syntaxString = "angleBetween = Vector.AngleBetween(vector1, vector2);"; resultType = "Double"; operationString = "Calculating the angle between two Vectors"; ShowResults(angleBetween.ToString(), syntaxString, resultType, operationString); break; } case "rb22": { // Calculates the cross product of two Vectors using the static CrossProduct method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Double crossProduct; crossProduct = Vector.CrossProduct(vector1, vector2); // crossProduct is equal to 50 // Displaying Results syntaxString = "crossProduct = Vector.CrossProduct(vector1,vector2);"; resultType = "Double"; operationString = "Calculating the crossproduct of two Vectors"; ShowResults(crossProduct.ToString(), syntaxString, resultType, operationString); break; } case "rb23": { // Calculates the determinant of two Vectors using the static Determinant method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Double determinant; determinant = Vector.Determinant(vector1, vector2); // determinant is equal to 50 // Displaying Results syntaxString = "determinant = Vector.Determinant(vector1, vector2);"; resultType = "Double"; operationString = "Calculating the determinant of two Vectors"; ShowResults(determinant.ToString(), syntaxString, resultType, operationString); break; } case "rb24": { // Checks if two Vectors are equal using the overloaded equality operator. // Declaring vecto1 and initializing x,y values Vector vector1 = new Vector(20, 30); // Declaring vector2 without initializing x,y values Vector vector2 = new Vector(); // Boolean to hold the result of the comparison Boolean areEqual; // assigning values to vector2 vector2.X = 45; vector2.Y = 70; // Comparing Vectors for equality areEqual = (vector1 == vector2); // areEqual is False // Displaying Results syntaxString = "areEqual = (vector1 == vector2);"; resultType = "Boolean"; operationString = "Checking if two vectors are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb25": { // Checks if two Vectors are equal using the static Equals method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Boolean areEqual; areEqual = Vector.Equals(vector1, vector2); // areEqual is False // Displaying Results syntaxString = "areEqual = Vector.Equals(vector1, vector2);"; resultType = "Boolean"; operationString = "Checking if two vectors are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb26": { // Compares an Object and a Vector for equality using the non-static Equals method. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Boolean areEqual; areEqual = vector1.Equals(vector2); // areEqual is False // Displaying Results syntaxString = "areEqual = vector1.Equals(vector2);"; resultType = "Boolean"; operationString = "Checking if two vectors are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb27": { // Converts a string representation of a vector into a Vector structure Vector vectorResult = new Vector(); vectorResult = Vector.Parse("1,3"); // vectorResult is equal to (1,3) // Displaying Results syntaxString = "vectorResult = Vector.Parse(\"1,3\");"; resultType = "Vector"; operationString = "Converting a string into a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb28": { // Checks if two Vectors are not equal using the overloaded inequality operator. Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); Boolean areNotEqual; areNotEqual = (vector1 != vector2); // areNotEqual is True // Displaying Results syntaxString = "areNotEqual = (vector1 != vector2);"; resultType = "Boolean"; operationString = "Checking if two points are not equal"; ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb29": { // Negates a Vector using the Negate method. Vector vector1 = new Vector(20, 30); Vector vectorResult = new Vector(); vector1.Negate(); // vector1 is equal to (-20, -30) // Displaying Results syntaxString = "vector1.Negate();"; resultType = "void"; operationString = "Negating a vector"; ShowResults(vector1.ToString(), syntaxString, resultType, operationString); break; } case "rb30": { // Negates a Vector using the overloaded unary negation operator. Vector vector1 = new Vector(20, 30); Vector vectorResult = new Vector(); vectorResult = -vector1; // vectorResult is equal to (-20, -30) // Displaying Results syntaxString = "vectorResult = -vector1;"; resultType = "Vector"; operationString = "Negating a vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb31": { // Gets a String representation of a Vector structure Vector vector1 = new Vector(20, 30); String vectorString; vectorString = vector1.ToString(); // vectorString is equal to 10,5 // Displaying Results syntaxString = "vectorString = vector1.ToString();"; resultType = "String"; operationString = "Getting the string representation of a Vector"; ShowResults(vectorString.ToString(), syntaxString, resultType, operationString); break; } case "rb32": { // Explicitly converts a Vector structure into a Size structure // Returns a Size. Vector vector1 = new Vector(20, 30); System.Windows.Size size1 = new System.Windows.Size(); size1 = (System.Windows.Size)vector1; // size1 has a width of 20 and a height of 30 // Displaying Results syntaxString = "size1 = (Size)vector1;"; resultType = "Size"; operationString = "Expliciting casting a Vector into a Size"; ShowResults(size1.ToString(), syntaxString, resultType, operationString); break; } case "rb33": { // Explicitly converts a Vector structure into a Point structure // Returns a Point. Vector vector1 = new Vector(20, 30); System.Windows.Point point1 = new System.Windows.Point(); point1 = (System.Windows.Point)vector1; // point1 is equal to (20, 30) // Displaying Results syntaxString = "point1 = (Point)vector1;"; resultType = "Point"; operationString = "Expliciting casting a Vector into a Point"; ShowResults(point1.ToString(), syntaxString, resultType, operationString); break; } // task example. this case statement is not referenced from the list of radio buttons case "rb40": { // adds two vectors using Add and + Vector vector1 = new Vector(20, 30); Vector vector2 = new Vector(45, 70); vector1 = vector1 + vector2; // vector1 is now equal to (65, 100) vector1 = Vector.Add(vector1, vector2); // vector1 is now equal to (110, 170) // Displaying Results syntaxString = "vectorResult = Vector.Negate(vector1);"; resultType = "Vector"; operationString = "Negating a vector"; ShowResults(vector1.ToString(), syntaxString, resultType, operationString); break; } default: break; } // end switch }
protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize) { base.ArrangeOverride(finalSize); UpdateSize(); return(finalSize); }
public static RenderTargetBitmap ToRenderTargetBitmap(this UIElement element, Size size, PixelFormat pixelFormat) { var result = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, pixelFormat); element.Measure(size); element.Arrange(new Rect(size)); result.Render(element); return(result); }
public static void SaveImage(this UIElement element, Size size, string fileName) { SaveImage(element, size, GetPixelFormat(fileName), fileName); }
/// <summary> /// Parametre olarak aldıgı Size degerine göre gelen Image i yeni boyutunu ayarlar /// </summary> /// <param name="imgToResize"></param> /// <param name="size"></param> /// <returns></returns> public static System.Windows.Controls.Image ResizeImage(this System.Windows.Controls.Image imgToResize, System.Windows.Size size) { imgToResize.Width = size.Width; imgToResize.Height = size.Height; return(imgToResize); }
public static RenderTargetBitmap ToRenderTargetBitmap(this UIElement element, Size size) { return(element.ToRenderTargetBitmap(size, PixelFormats.Pbgra32)); }
/// <summary> /// Arranges the content of a System.Windows.Controls.Canvas element. /// </summary> /// <param name="arrangeSize"></param> /// <returns></returns> protected override System.Windows.Size ArrangeOverride(System.Windows.Size arrangeSize) { var offset = new Vector(arrangeSize.Width / 2, arrangeSize.Height / 2); if (_slices != null) { double radius = Math.Min(arrangeSize.Width / 2, arrangeSize.Height / 2); double startAngle = 0; var fullCircle = new Circle { Radius = radius }; double minimumArcAngle = MinimumArcLength / fullCircle.Circumference * 2 * Math.PI; foreach (IPieSlice slice in _slices) { PieChartSliceItem item = _sliceItems[slice]; double relativeValue = item.Slice.Value / SumOfSlices; double openAngle = Math.Max(relativeValue * 2 * Math.PI, minimumArcAngle); item.Center = (Point)offset; item.StartAngle = startAngle; item.OpenAngle = openAngle; item.Radius = radius; item.Arrange(new Rect(0, 0, arrangeSize.Width, arrangeSize.Height)); startAngle += openAngle; } } foreach (var pair in _valueItems) { IPieSlice slice = pair.Key; PieChartValueItem item = pair.Value; PieChartSliceItem sliceItem = _sliceItems[slice]; System.Windows.Size desiredSize = item.DesiredSize; Rect rect = FindValuePosition(sliceItem.Shape, desiredSize); if (sliceItem.Shape.Contains(rect)) { item.Visibility = Visibility.Visible; item.Arrange(rect); } else { item.Visibility = Visibility.Collapsed; } } foreach (var pair in _titleItems) { IPieSlice slice = pair.Key; PieChartLabelItem item = pair.Value; PieChartSliceItem sliceItem = _sliceItems[slice]; System.Windows.Size desiredSize = item.DesiredSize; Vector specificOffset; switch (sliceItem.Direction) { case SliceDirection.TopRight: specificOffset = new Vector(0, -desiredSize.Height); break; case SliceDirection.BottomRight: specificOffset = new Vector(0, 0); break; case SliceDirection.BottomLeft: specificOffset = new Vector(-desiredSize.Width, 0); break; default: specificOffset = new Vector(-desiredSize.Width, -desiredSize.Height); break; } Circle circle = sliceItem.Shape.Circle; circle.Radius += LabelMargin; Point position = circle.GetPoint(sliceItem.Angle) + specificOffset; var rect = new Rect(position, desiredSize); item.Arrange(rect); } return(arrangeSize); }
/// <summary> /// A default implementation of MeasureOverride to be used by all WPF widgets /// </summary> /// <param name="constraint">Size constraints</param> /// <param name="wpfMeasure">Size returned by the base MeasureOverride</param> /// <returns></returns> public System.Windows.Size MeasureOverride(System.Windows.Size constraint, System.Windows.Size wpfMeasure) { var defNaturalSize = eventSink.GetDefaultNaturalSize(); if (!double.IsPositiveInfinity(constraint.Width)) { defNaturalSize.Width = Math.Min(defNaturalSize.Width, constraint.Width); } if (!double.IsPositiveInfinity(constraint.Height)) { defNaturalSize.Height = Math.Min(defNaturalSize.Height, constraint.Height); } // -2 means use the WPF default, -1 use the XWT default, any other other value is used as custom natural size var nw = DefaultNaturalWidth; if (nw == -1) { nw = defNaturalSize.Width; if (nw == 0) { nw = wpfMeasure.Width; } wpfMeasure.Width = nw; } else if (nw != -2) { wpfMeasure.Width = nw; } var nh = DefaultNaturalHeight; if (nh == -1) { nh = defNaturalSize.Height; if (nh == 0) { nh = wpfMeasure.Height; } wpfMeasure.Height = nh; } else if (nh != -2) { wpfMeasure.Height = nh; } // If we are calculating the default preferred size of the widget we end here. // See note above about when GetPreferred* methods are called. if (calculatingPreferredSize) { return(wpfMeasure); } if ((enabledEvents & WidgetEvent.PreferredSizeCheck) != 0) { Context.InvokeUserCode(delegate { // Calculate the preferred width through the frontend if there is an overriden OnGetPreferredWidth, but only do it // if we are not given a constraint. If there is a width constraint, we'll use that constraint value for calculating the height var cw = double.IsPositiveInfinity(constraint.Width) ? SizeConstraint.Unconstrained : constraint.Width; var ch = double.IsPositiveInfinity(constraint.Height) ? SizeConstraint.Unconstrained : constraint.Height; var ws = eventSink.GetPreferredSize(cw, ch); wpfMeasure = new System.Windows.Size(ws.Width, ws.Height); }); } return(wpfMeasure); }
public static void AskToPrint( FrameworkElement ctrl , string printJobDesc = "Scaled Visual") { PrintDialog print = new PrintDialog(); if (print.ShowDialog() != true) return; PrintCapabilities capabilities = print.PrintQueue.GetPrintCapabilities(print.PrintTicket); double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / ctrl.ActualWidth, capabilities.PageImageableArea.ExtentHeight / ctrl.ActualHeight); //Transform oldTransform = ctrl.LayoutTransform; ctrl.LayoutTransform = new ScaleTransform(scale, scale); //Size oldSize = new Size(ctrl.ActualWidth, ctrl.ActualHeight); Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); ctrl.Measure(sz); ((UIElement)ctrl).Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); ctrl.Focus(); print.PrintVisual(ctrl, printJobDesc); //ctrl.LayoutTransform = oldTransform; //ctrl.Measure(oldSize); //((UIElement)ctrl).Arrange(new Rect(new Point(0, 0), // oldSize)); }
public void PreparePrinting(PrintTicket printTicket, Size pageSize) { printTicket.PageOrientation = pageSize.Height >= pageSize.Width ? PageOrientation.Portrait : PageOrientation.Landscape; var printExtension = _reportProvider as IReportPrintExtension; if (printExtension != null) printExtension.PreparePrinting(printTicket, pageSize); }