public static Brush?GetBackgroundBrush(ResourceDictionary dict, Brush?defaultBrush = null) => GetBrush(dict, EditorFormatDefinition.BackgroundBrushId, defaultBrush);
/// <summary> /// Sets <see cref="MouseOverForegroundProperty"/> for <paramref name="element"/>. /// </summary> public static void SetMouseOverForeground(DependencyObject element, Brush?value) { element.SetValue(MouseOverForegroundProperty, value); }
public static void SetHoverSelectedForegroundBrush(UIElement element, Brush?value) => element.SetValue(HoverSelectedForegroundBrushProperty, value);
public static void UpdateMinimumTrackColor(this MauiSlider nativeSlider, ISlider slider, Brush?defaultForegroundColor) { if (slider.MinimumTrackColor.IsDefault()) { nativeSlider.Foreground = defaultForegroundColor; } else { nativeSlider.Foreground = slider.MinimumTrackColor.ToNative(); } }
public static void UpdateThumbColor(this MauiSlider nativeSlider, ISlider slider, Brush?defaultThumbColor) { var thumb = nativeSlider?.Thumb; if (thumb == null || slider?.ThumbColor == null || nativeSlider == null) { return; } nativeSlider.ThumbColorOver = slider.ThumbColor.ToNative(); BrushHelpers.UpdateColor(slider.ThumbColor, ref defaultThumbColor, () => thumb.Background, brush => thumb.Background = brush); }
public BasicTextSource(FontFamily fontFamily, double fontSize, Brush?foregroundColor = null) { FontFamily = fontFamily; FontSize = fontSize; ForegroundColor = foregroundColor ?? Brushes.Black; var fontRendering = FontRendering.CreateInstance(fontSize, default, null, ForegroundColor,
static Brush GetBrush(Brush?b) => b ?? Brushes.Transparent;
public static void UpdateTextColor(this AutoSuggestBox nativeControl, ISearchBar searchBar, Brush?defaultTextColorBrush, Brush?defaultTextColorFocusBrush, MauiSearchTextBox?queryTextBox) { if (queryTextBox == null) { return; } Color textColor = searchBar.TextColor; BrushHelpers.UpdateColor(textColor, ref defaultTextColorBrush, () => queryTextBox.Foreground, brush => queryTextBox.Foreground = brush); BrushHelpers.UpdateColor(textColor, ref defaultTextColorFocusBrush, () => queryTextBox.ForegroundFocusBrush, brush => queryTextBox.ForegroundFocusBrush = brush); }
public static void SetUnderlineBrush(UIElement element, Brush?value) { element.SetValue(UnderlineBrushProperty, value); }
private TexEnvironment(TexStyle style, ITeXFont mathFont, ITeXFont textFont, Brush?background, Brush?foreground) { if (style == TexStyle.Display || style == TexStyle.Text || style == TexStyle.Script || style == TexStyle.ScriptScript) { this.Style = style; } else { this.Style = TexStyle.Display; } this.MathFont = mathFont; TextFont = textFont; this.Background = background; this.Foreground = foreground; }
public static void UpdateCancelButtonColor(this AutoSuggestBox nativeControl, ISearchBar searchBar, MauiCancelButton?cancelButton, Brush?defaultDeleteButtonBackgroundColorBrush, Brush?defaultDeleteButtonForegroundColorBrush) { if (cancelButton == null || !cancelButton.IsReady) { return; } Color cancelColor = searchBar.CancelButtonColor; BrushHelpers.UpdateColor(cancelColor, ref defaultDeleteButtonForegroundColorBrush, () => cancelButton.ForegroundBrush, brush => cancelButton.ForegroundBrush = brush); if (cancelColor == null) { BrushHelpers.UpdateColor(null, ref defaultDeleteButtonBackgroundColorBrush, () => cancelButton.BackgroundBrush, brush => cancelButton.BackgroundBrush = brush); } else { // Determine whether the background should be black or white (in order to make the foreground color visible) var bcolor = cancelColor.ToWindowsColor().GetContrastingColor().ToColor(); BrushHelpers.UpdateColor(bcolor, ref defaultDeleteButtonBackgroundColorBrush, () => cancelButton.BackgroundBrush, brush => cancelButton.BackgroundBrush = brush); } }
/// <summary> /// returns a new renderer based on serieSetting /// </summary> protected Renderer?CreateGraphRenderer <TRecord>(int serieIndex, SerieSetting <TRecord> serieSetting) { if (isArea2Expected && serieSetting.SerieStyle != SerieStyleEnum.area2) { throw new Exception(string.Format("SerieStyle[{0}] '{1}, {2}' should be area2 because the previous data series had style aera1.", serieIndex, serieSetting.SerieStyle, (int)serieSetting.SerieStyle)); } //get stroke brush or default brush Brush strokeBrush; if (serieSetting.StrokeBrush != null) { strokeBrush = serieSetting.StrokeBrush; } else { //use default brushes if (serieIndex == 0) { strokeBrush = Brushes.LightGreen; } else if (serieIndex == 1) { strokeBrush = Brushes.LightBlue; } else if (serieIndex == 2) { strokeBrush = Brushes.LightGray; } else if (serieIndex == 3) { strokeBrush = Brushes.LightGray; } else if (serieIndex == 4) { strokeBrush = Brushes.Black; } else { strokeBrush = Brushes.Red; } } //get fill brush or use transparent version of stroke brush Brush?fillBrush = null; if (serieSetting.SerieStyle == SerieStyleEnum.line) { fillBrush = serieSetting.FillBrush; } else if (serieSetting.SerieStyle == SerieStyleEnum.area1) { if (serieSetting.FillBrush == null) { if (!(strokeBrush is SolidColorBrush strokeSolidColorBrush)) { fillBrush = new SolidColorBrush(Color.FromArgb(128, 240, 240, 240)); } else { Color strokeColor = strokeSolidColorBrush.Color; fillBrush = new SolidColorBrush(Color.FromArgb(128, strokeColor.R, strokeColor.G, strokeColor.B)); } } else { fillBrush = serieSetting.FillBrush; } }
public static void UpdatePlaceholderColor(this AutoSuggestBox nativeControl, ISearchBar searchBar, Brush?defaultPlaceholderColorBrush, Brush?defaultPlaceholderColorFocusBrush, MauiTextBox?queryTextBox) { if (queryTextBox == null) { return; } Color placeholderColor = searchBar.PlaceholderColor; BrushHelpers.UpdateColor(placeholderColor, ref defaultPlaceholderColorBrush, () => queryTextBox.PlaceholderForegroundBrush, brush => queryTextBox.PlaceholderForegroundBrush = brush); BrushHelpers.UpdateColor(placeholderColor, ref defaultPlaceholderColorFocusBrush, () => queryTextBox.PlaceholderForegroundFocusBrush, brush => queryTextBox.PlaceholderForegroundFocusBrush = brush); }
private void doOnRender(DrawingContext drawingContext) { if (Background!=null) { //draw background drawingContext.DrawRectangle(Background, null, new Rect(0, 0, RenderSize.Width, RenderSize.Height)); } //draw Border over background double borderWidthThickness = Math.Min(RenderSize.Width, BorderThickness.Left + BorderThickness.Right); double borderHeightThickness = Math.Min(RenderSize.Height, BorderThickness.Top + BorderThickness.Bottom); if (borderWidthThickness>0 || borderHeightThickness>0) { //enough space to draw at least some border if (BorderBrush!=null && BorderThickness.Left + BorderThickness.Top + BorderThickness.Right + BorderThickness.Bottom>0) { if (borderWidthThickness>=RenderSize.Width || borderHeightThickness>=RenderSize.Height) { //only space enough for part of the border drawingContext.DrawRectangle(BorderBrush, null, new Rect(0, 0, RenderSize.Width, RenderSize.Height)); } else { GeometryGroup borderGeometry = new GeometryGroup(); borderGeometry.Children.Add(new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height))); borderGeometry.Children.Add(new RectangleGeometry( new Rect(BorderThickness.Left, BorderThickness.Top, RenderSize.Width-borderWidthThickness, RenderSize.Height-borderHeightThickness))); drawingContext.DrawGeometry(BorderBrush, null, borderGeometry); } } } if (RenderSize.Width>BorderThickness.Left + BorderThickness.Right + Padding.Left + Padding.Left && RenderSize.Height>BorderThickness.Top + BorderThickness.Bottom + Padding.Top + Padding.Bottom) { //enough space to draw some content drawingContext.PushTransform(new TranslateTransform(BorderThickness.Left + Padding.Left, BorderThickness.Top + Padding.Top)); drawingContext.PushClip(new RectangleGeometry(new Rect(arrangeContentSize))); OnRenderContent(drawingContext, arrangeContentSize); drawingContext.Pop(); drawingContext.Pop(); #if DEBUG if (IsShowLayoutData) { //write layout data over content if (layoutDataBrush==null) { layoutDataBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)); } String layoutDataString = "Alignment H: " + HorizontalAlignment + ", V: " + VerticalAlignment + Environment.NewLine + "Margin L:" + format5(Margin.Left) + ", T: " + format5(Margin.Top) + ", R: " + format5(Margin.Right) + ", B: " + format5(Margin.Bottom) + Environment.NewLine + "Border L:" + format5(BorderThickness.Left) + ", T: " + format5(BorderThickness.Top) + ", R: " + format5(BorderThickness.Right) + ", B: " + format5(BorderThickness.Bottom) + Environment.NewLine + "Padding L:" + format5(Padding.Left) + ", T: " + format5(Padding.Top) + ", R: " + format5(Padding.Right) + ", B: " + format5(Padding.Bottom) + Environment.NewLine + " Width Height" + Environment.NewLine + "Size: " + format8(Width) + ", " + format8(Height) + Environment.NewLine + "MConstraint: " + format8(measureConstraintSize.Width) + ", " + format8(measureConstraintSize.Height) + Environment.NewLine + "MeasContent: " + format8(MeasureContentSize.Width) + ", " + format8(MeasureContentSize.Height) + Environment.NewLine + "MRequested: " + format8(measureRequestedSize.Width) + ", " + format8(measureRequestedSize.Height) + Environment.NewLine + "Desired: " + format8(DesiredSize.Width) + ", " + format8(DesiredSize.Height) + Environment.NewLine + "AConstraint: " + format8(arrangeConstraintSize.Width) + ", " + format8(arrangeConstraintSize.Height) + Environment.NewLine + "AranContent: " + format8(arrangeContentSize.Width) + ", " + format8(arrangeContentSize.Height) + Environment.NewLine + "ARequested: " + format8(arrangeRequestedSize.Width) + ", " + format8(arrangeRequestedSize.Height) + Environment.NewLine + "Render: " + format8(RenderSize.Width) + ", " + format8(RenderSize.Height) + Environment.NewLine + "Actual: " + format8(ActualWidth) + ", " + format8(ActualHeight); FormattedText formattedText = new FormattedText(layoutDataString, Thread.CurrentThread.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Courier New"), 12, layoutDataBrush, VisualTreeHelper.GetDpi(this).PixelsPerDip); drawingContext.DrawText(formattedText, new Point(BorderThickness.Left + Padding.Left, BorderThickness.Top + Padding.Top)); #endif } } }
private void RenderImage() { if (this.image != null) { this.image.Dispose(); this.image = null; } int width = this.ClientSize.Width; int height = this.ClientSize.Height; if (width > 0 && height > 0 && this.view != null && this.view.Lines != null) { // Draw a bitmap in memory that we can render from this.image = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(this.image)) using (SolidBrush backBrush = new(this.BackColor)) { g.FillRectangle(backBrush, 0, 0, width, height); const float GutterWidth = 2.0F; // Make sure each line is at least 1 pixel high float lineHeight = (float)Math.Max(1.0, this.GetPixelLineHeightF(1)); DiffViewLines lines = this.view.Lines; int numLines = lines.Count; for (int i = 0; i < numLines; i++) { DiffViewLine line = lines[i]; if (line.Edited) { backBrush.Color = DiffOptions.GetColorForEditType(line.EditType); float y = this.GetPixelLineHeightF(i); float fullFillWidth = width - (2 * GutterWidth); switch (line.EditType) { case EditType.Change: // Draw all the way across g.FillRectangle(backBrush, GutterWidth, y, fullFillWidth, lineHeight); break; case EditType.Delete: // Draw delete on the left and dead space on the right. g.FillRectangle(backBrush, GutterWidth, y, fullFillWidth / 2, lineHeight); using (Brush? deadBrush = DiffOptions.TryCreateDeadSpaceBrush(backBrush.Color)) { g.FillRectangle(deadBrush ?? backBrush, GutterWidth + (fullFillWidth / 2), y, fullFillWidth / 2, lineHeight); } break; case EditType.Insert: // Draw dead space on the left and insert on the right. using (Brush? deadBrush = DiffOptions.TryCreateDeadSpaceBrush(backBrush.Color)) { g.FillRectangle(deadBrush ?? backBrush, GutterWidth, y, fullFillWidth / 2, lineHeight); } g.FillRectangle(backBrush, GutterWidth + (fullFillWidth / 2), y, fullFillWidth / 2, lineHeight); break; } } } } } }
public static void SetUnderlineMouseOverSelectedBrush(UIElement element, Brush?value) { element.SetValue(UnderlineMouseOverSelectedBrushProperty, value); }
/// <inheritdoc /> public BasicTextSource2([NotNull] FontFamily fontFamily, double fontSize, [CanBeNull] Brush?foregroundColor = null) : base(fontFamily, fontSize, foregroundColor) { }
/// <summary> /// /// </summary> /// <param name="newRender"></param> /// <param name="pixelsPerDip"></param> /// <param name="textDecorations"></param> /// <param name="foregroundBrush"></param> /// <param name="style"></param> /// <param name="weight"></param> /// <param name="backgroundBrush"></param> public GenericTextRunProperties(FontRendering?newRender, double pixelsPerDip, TextDecorationCollection?textDecorations = null, Brush?foregroundBrush = null, FontStyle?style = null, FontWeight?weight = null, Brush backgroundBrush = null) { Typeface?typeface = newRender?.Typeface; if (style.HasValue || weight.HasValue) { typeface = new Typeface(new FontFamily(newRender?.Typeface.FontFamily.FamilyNames[XmlLanguage.GetLanguage("en-US")]), style ?? newRender?.Typeface.Style ?? default, weight ?? newRender?.Typeface.Weight ?? default, newRender?.Typeface.Stretch ?? default); } _typeface = typeface; _emSize = newRender?.FontSize ?? 12.0; _emHintingSize = _emSize; _textDecorations = textDecorations ?? newRender?.TextDecorations ?? new TextDecorationCollection(); _foregroundBrush = foregroundBrush ?? Brushes.Black; _backgroundBrush = backgroundBrush; // if (backgroundBrush != null && backgroundBrush.Opacity > 0.5) // { // _backgroundBrush = new SolidColorBrush(backgroundBrush.Color) {Opacity = 0.40}; // } _baselineAlignment = BaselineAlignment.Baseline; _culture = CultureInfo.CurrentUICulture; PixelsPerDip = pixelsPerDip; }
static Brush?GetBrush(ResourceDictionary dict, string brushId, string colorId, string opacityId, double?defaultOpacity, Brush?defaultBrush) { var brush = dict[brushId] as Brush; if (brush is null) { var color = dict[colorId] as Color?; if (color is not null) { brush = new SolidColorBrush(color.Value); } } if (brush is null) { brush = defaultBrush; } if (brush is null) { return(brush); } var opacity = dict[opacityId] as double? ?? defaultOpacity; if (opacity is not null) { brush = brush.Clone(); brush.Opacity = opacity.Value; } if (brush.CanFreeze) { brush.Freeze(); } return(brush); }
private static IEnumerable <IFeature> GetFeaturesInView(double resolution, LabelStyle labelStyle, IEnumerable <IFeature>?features, Pen line, Brush?fill) { if (features == null) { return(Enumerable.Empty <IFeature>()); } var margin = resolution * 50; var clusters = ClusterFeatures(features, margin, labelStyle, resolution); const int textHeight = 18; var result = new List <IFeature>(); foreach (var cluster in clusters) { if (cluster.Features?.Count > 1) { result.Add(CreateBoxFeature(resolution, cluster, line, fill)); } var offsetY = double.NaN; var orderedFeatures = cluster.Features?.OrderBy(f => f.Extent.Centroid.Y); if (orderedFeatures != null) { foreach (var pointFeature in orderedFeatures) { var position = CalculatePosition(cluster); offsetY = CalculateOffsetY(offsetY, textHeight); var labelText = labelStyle.GetLabelText(pointFeature); var labelFeature = CreateLabelFeature(position, labelStyle, offsetY, labelText); result.Add(labelFeature); } } } return(result); }
protected override void SetupDefaults(Slider nativeView) { DefaultForegroundColor = nativeView.Foreground; DefaultBackgroundColor = nativeView.Background; }
public async Task <MemoryStream?> BuildMemeAsync(Bitmap image, Tuple <Rectangle, string, Brush?>[] captions, string?font = null, int fsize = 16, Brush?defaultBrush = null) { var a = RegisterGraphics(image); var b = RegisterFont(font, fsize); var c = RegisterBrush(defaultBrush); await a; await b; await c; foreach (var line in captions) { await AddText(line.Item1, line.Item2, line.Item3); } var mem = new MemoryStream(); this.map?.Save(mem, ImageFormat.Png); mem?.Seek(0, SeekOrigin.Begin); return(mem); }
public static void UpdateMaximumTrackColor(this MauiSlider nativeSlider, ISlider slider, Brush?defaultBackgroundColor) { if (slider.MaximumTrackColor.IsDefault()) { nativeSlider.BorderBrush = defaultBackgroundColor; } else { nativeSlider.BorderBrush = slider.MaximumTrackColor.ToNative(); } }
public static void UpdatePlaceholderColor(this MauiTextBox textBox, IPlaceholder placeholder, Brush?defaultPlaceholderColorBrush, Brush?defaultPlaceholderColorFocusBrush) { Color placeholderColor = placeholder.PlaceholderColor; BrushHelpers.UpdateColor(placeholderColor, ref defaultPlaceholderColorBrush, () => textBox.PlaceholderForegroundBrush, brush => textBox.PlaceholderForegroundBrush = brush); BrushHelpers.UpdateColor(placeholderColor, ref defaultPlaceholderColorFocusBrush, () => textBox.PlaceholderForegroundFocusBrush, brush => textBox.PlaceholderForegroundFocusBrush = brush); }
void SetupDefaults(MauiTextBox nativeView) { _placeholderDefaultBrush = nativeView.PlaceholderForeground; _defaultPlaceholderColorFocusBrush = nativeView.PlaceholderForegroundFocusBrush; }
public static void SetBrush(DependencyObject element, Brush?value) => element.SetValue(BrushProperty, value);
/// <summary> /// Sets <see cref="IsSelectedBackgroundProperty"/> for <paramref name="element"/>. /// </summary> public static void SetIsSelectedBackground(DependencyObject element, Brush?value) { element.SetValue(IsSelectedBackgroundProperty, value); }
private void onSetBackground(Brush backgroundBrush) { oldBackground = comboBoxBorder !.Background; comboBoxBorder !.Background = backgroundBrush !; }
public static void SetDisabledForegroundBrush(UIElement element, Brush?value) => element.SetValue(DisabledForegroundBrushProperty, value);
public Paint(Brush?fill = null, Pen?stroke = null) { Fill = fill; Stroke = stroke; }