public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null) { float width = ActualPosition.Width; float height = ActualPosition.Height; float barWidth = BarWidth.Value(); if (barWidth == 0) { barWidth = 0.001f; } float availableWidth = width - barWidth; float percentage = Value.Value() / MaxValue.Value(); float sliderHeight = SliderHeight.Value(); if (sliderHeight == 0) { sliderHeight = 0.001f; } float sliderTop = (height / 2f) - (sliderHeight / 2f); FloatRectangle sliderRect = new FloatRectangle(0 + ActualPosition.X, sliderTop + ActualPosition.Y, width, sliderHeight); FloatRectangle barRect = new FloatRectangle(availableWidth * percentage + ActualPosition.X, ActualPosition.Y, barWidth, height); if (SliderTexture.HasValue()) { using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch)) { spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture(SliderTexture.Value(), true), screen.Translate(sliderRect).Value.ToRectangle, Color.White); } } else { spriteBatch.DrawSolidRectangle(screen.Translate(sliderRect).Value, SliderColor.Value().Value *opacity, clip); } if (BarTexture.HasValue()) { using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch)) { spriteBatch.Draw(Solids.Instance.AssetLibrary.GetTexture(BarTexture.Value(), true), screen.Translate(barRect).Value.ToRectangle, Color.White); } } else { spriteBatch.DrawSolidRectangle(screen.Translate(barRect).Value, BarColor.Value().Value *opacity, clip); } }
public ColorPickerControl() { InitializeComponent(); qcac = new QuickColorAccessControl(this); qcac.wrpQuickColors.Visibility = Visibility.Hidden; qcac.HorizontalAlignment = HorizontalAlignment.Left; qcac.VerticalAlignment = VerticalAlignment.Top; SliderColor sc = new SliderColor(); UpdateEllipse(); elpCurrentColor.DataContext = sc; //Binding b = new Binding("ColorBrush"); //SetBinding(Ellipse.FillProperty, b); }
protected void DrawHorizontalLabel(ChartValueItem entry, SKCanvas canvas, SKRect frame, SKRect chart) { if (!DisplayHorizontalValuesBySlider) { return; } // Draws the horizontal value the slider is on // if (string.IsNullOrEmpty(entry?.Label)) { return; } float x = chart.GetInsideXValue(TouchedPoint.X); if (ChartType == ChartType.Bar) { x = entry.Point.X; } // Draws background using (var boundPaint = new SKPaint { Color = SliderColor.ToSKColor(), StrokeCap = SKStrokeCap.Round, Style = SKPaintStyle.StrokeAndFill, StrokeWidth = SliderWidth }) { var bounds = boundPaint.GetBounds( entry.Label, x, frame.Bottom + HorizontalTextSize + (HorizontalTextSize / 4), padding: InternalSliderDetailPadding); if (bounds.Right > frame.Right) { bounds.Left = frame.Right - bounds.Width + SliderWidth; bounds.Right = frame.Right + SliderWidth; } else if (bounds.Left < frame.Left) { bounds.Right = frame.Left + bounds.Width - SliderWidth; bounds.Left = frame.Left - SliderWidth; } canvas.DrawRoundRect(new SKRoundRect(bounds, SliderDetailCornerRadius), boundPaint); // Draws text using (var textPaint = new SKPaint { IsAntialias = true, TextSize = HorizontalTextSize, Color = SliderDetailTextColor.ToSKColor(), Typeface = FontTypeService.GetFontFamily(GetType().Assembly), TextAlign = SKTextAlign.Center, FakeBoldText = true }) { canvas.DrawText(entry.Label, bounds.MidX, bounds.MidY + (bounds.Height / 4), textPaint); } } }
private void DrawBars(SKCanvas canvas, SKRect frame, SKRect chart) { // Selected bar width var selectedValueItems = ChartEntries.GetChartValueItemFromX(chart.GetInsideXValue(TouchedPoint.X), chart, chart.GetItemWidth(MaxItems)); var selectedTags = selectedValueItems?.Select(x => x.ChartValueItem.Tag); // Invoke command with selected items SelectedValuesCommand?.Execute(new SelectedChartValueItemArgs { ChartValueItems = selectedValueItems, TouchedPoint = new SKPoint(chart.GetInsideXValue(TouchedPoint.X), TouchedPoint.Y) }); using (var paint = new SKPaint { IsAntialias = true, Style = SKPaintStyle.StrokeAndFill, StrokeCap = SKStrokeCap.Butt, }) { var groupedItems = ChartEntries.Where(x => x.IsVisible).SelectMany(x => x.Items).GroupBy(x => x.Tag.ToString()).OrderBy(x => x.Key); // Calc max items in one group var maxItemsInGroups = groupedItems.Max(x => x.Count()); // Calc how many groups there is var groupCount = groupedItems.Count(); // Calc how many bars there will be var totalBars = groupCount * maxItemsInGroups; var internalGroupMargin = maxItemsInGroups == 1 ? BarMargin : GroupMargin; var internalBarMargin = maxItemsInGroups == 1 ? 0 : BarMargin; var internalBarWidth = MinimumBarWidth; float itemWidth; if (AllowScroll) { // Calc total item width itemWidth = internalBarWidth * maxItemsInGroups + ((maxItemsInGroups - 1) * barMargin); } else { itemWidth = chart.Width / groupCount; itemWidth -= internalGroupMargin; internalBarWidth = (itemWidth / maxItemsInGroups) - ((maxItemsInGroups - 1) * barMargin); } int groupIndex = 0; float scrollLeftPadding = 0; float left = 0; float groupLeft = 0; float right = 0; groupCenters = new List <GroupChartItem>(); foreach (var groupedItem in groupedItems) { int itemIndex = 0; groupLeft = left; if (!AllowScroll && IsSliderVisible && selectedTags?.Contains(groupedItem.Key) == true) { var item = groupedItem.OrderByDescending(x => x.Value).First(); paint.Color = SliderColor.ToSKColor(); paint.PathEffect = SKPathEffect.CreateCorner(SliderCornerRadius); var bounds = new SKRect( item.Point.X - (itemWidth * .5f) - (groupMargin * .5f), item.Point.Y - (itemWidth * .5f), item.Point.X + (itemWidth * .5f) + (groupMargin * .5f), chart.Bottom + HorizontalTextSize); paint.StrokeWidth = 0; canvas.DrawRect(bounds, paint); } foreach (var item in groupedItem) { var parent = ChartEntries.FirstOrDefault(x => x.Items.Contains(item)); SKRect bounds = new SKRect(); if (AllowScroll) { if (left == 0) { left = itemWidth.FromDpiAdjusted(); groupLeft = left; scrollLeftPadding = left; } else if (itemIndex != 0) { left += internalBarMargin; } right = left + internalBarWidth; bounds = new SKRect( left, item.Point.Y, right, chart.Bottom); left = right; } else { left = (item.Point.X - (itemWidth * .5f)) + (internalBarWidth * itemIndex) + (internalBarMargin * itemIndex); right = left + internalBarWidth; bounds = new SKRect( left, item.Point.Y, right, chart.Bottom); } paint.StrokeWidth = 0; if (parent.UseDashedEffect) { paint.Color = parent.Color.ToSKColor().AsTransparency(); paint.PathEffect = SKPathEffect.CreateCorner(BarCornerRadius); canvas.DrawRect(bounds, paint); paint.Color = parent.Color.ToSKColor(); paint.PathEffect = SKPathEffect.CreateDash(new float[] { StrokeDashFirst, StrokeDashSecond }, StrokeDashPhase); paint.StrokeWidth = bounds.Width; canvas.DrawLine(bounds.MidX, bounds.Bottom, bounds.MidX, bounds.Top, paint); } else { paint.Color = parent.Color.ToSKColor(); paint.PathEffect = SKPathEffect.CreateCorner(BarCornerRadius); canvas.DrawRect(bounds, paint); } itemIndex++; } left += internalGroupMargin; groupIndex++; var groupCenterPosition = groupLeft + (itemWidth / 2); groupCenters.Add(new GroupChartItem { Label = groupedItem.FirstOrDefault().Label, Position = groupCenterPosition.FromDpiAdjusted(), Tag = groupedItem.Key }); } if (AllowScroll) { var requestedWidth = right.FromDpiAdjusted() + frame.Left.FromDpiAdjusted(); if (requestedWidth != this.WidthRequest) { this.WidthRequest = requestedWidth; } else { SetStartPosition(groupCenters); IsInitialized = true; } if (ScrollComponent != null) { var deviceWidth = Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Width; var halfDeviceWidth = ((float)(deviceWidth / 2)).FromDpiAdjusted(); var frameLeftVal = frame.Left.FromDpiAdjusted(); var rectRightMarginVal = ChartRectMargin.Right.FromDpiAdjusted(); var leftPadding = halfDeviceWidth - frameLeftVal - scrollLeftPadding.FromDpiAdjusted(); var rightPadding = halfDeviceWidth - frameLeftVal - rectRightMarginVal - itemWidth.FromDpiAdjusted(); ScrollComponent.Padding = new Thickness(leftPadding, 0, rightPadding, 0); ScrollComponent.Margin = new Thickness(frame.Left.FromDpiAdjusted(), 0, ChartRectMargin.Right.FromDpiAdjusted(), 0); if (Selector != null) { Selector.WidthRequest = itemWidth.FromDpiAdjusted(); Selector.Margin = new Thickness(halfDeviceWidth, 0, 0, this.Height - frame.Bottom.FromDpiAdjusted()); } if (!isScrollEventActive) { ScrollComponent.Scrolled += ScrollComponent_Scrolled; isScrollEventActive = true; } } if (SwipeNotificationLeft != null) { SwipeNotificationLeft.Margin = new Thickness(frame.Left.FromDpiAdjusted(), 0, 0, this.Height - frame.Bottom.FromDpiAdjusted()); SwipeNotificationLeft.WidthRequest = ScrollComponent.Padding.Left; } if (SwipeNotificationRight != null) { SwipeNotificationRight.Margin = new Thickness(0, 0, ChartRectMargin.Right.FromDpiAdjusted(), this.Height - frame.Bottom.FromDpiAdjusted()); SwipeNotificationRight.WidthRequest = ScrollComponent.Padding.Left; } } } DrawHorizontalLabel(selectedValueItems?.FirstOrDefault()?.ChartValueItem, canvas, frame, chart); }
protected void DrawHorizontalLabels(SKCanvas canvas, SKRect frame, SKRect chart) { if (HorizontalLabelMode != LabelMode.None) { if (!string.IsNullOrEmpty(MinLabel) && !string.IsNullOrEmpty(MaxLabel)) { canvas.DrawHorizontalText(MinLabel, chart.Left, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Center, isBold: true); canvas.DrawHorizontalText(MaxLabel, chart.Right, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Center, isBold: true); } } if (!string.IsNullOrEmpty(HorizontalUnit)) { canvas.DrawHorizontalText(HorizontalUnit, chart.Right, frame.Bottom + (HorizontalLabelTextSize * 2), HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Left); } if (DisplayHorizontalValuesBySlider && IsSliderVisible) { var x = ChartType == ChartType.Linear ? TouchedPoint.X : chart.GetInsideXValue(TouchedPoint.X); var valueItems = ChartEntries.GetChartValueItemFromX(x, frame, MaxItems, ChartType == ChartType.Linear); var entry = valueItems?.FirstOrDefault()?.ChartValueItem; if (string.IsNullOrEmpty(entry?.Label)) { return; } x = ChartType == ChartType.Linear ? chart.GetInsideXValue(TouchedPoint.X) : entry.Point.X; canvas.DrawHorizontalText(entry.Label, x, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, SliderColor.ToSKColor(), SKTextAlign.Center, isBold: true); } else if (HorizontalLabelMode == LabelMode.All) { var items = ChartValuesDistinct; if (items?.Any() != true) { return; } var points = ChartEntries.FirstOrDefault().Items.Select(x => x.Point).ToArray(); for (int i = 0; i < items.Count(); i++) { var entry = items.ElementAt(i); var point = points[i]; if (string.IsNullOrEmpty(entry?.Label) || entry?.Label == MinLabel || entry?.Label == MaxLabel) { continue; } canvas.DrawHorizontalText(entry.Label, point.X, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Center); } } }