/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image ProcessImage(ImageFactory factory) { Bitmap newImage = null; Image image = factory.Image; try { BorderLayer borderLayer = this.DynamicParameter; int width = borderLayer.Width; Color backgroundColor = borderLayer.BackroundColor; bool top = borderLayer.Top; bool bottom = borderLayer.Bottom; bool right = borderLayer.Right; bool left = borderLayer.Left; //create a border image. newImage = this.BorderImage(image, width, backgroundColor, top, bottom, left, right); newImage.Tag = image.Tag; image.Dispose(); image = newImage; } catch { if (newImage != null) { newImage.Dispose(); } } return(image); }
/// <summary> /// Add Border to the current image /// </summary> /// <param name="borderLayer"></param> /// <returns></returns> public ImageFactory Border(BorderLayer borderLayer) { if (this.ShouldProcess) { if (borderLayer.Width < 0) { borderLayer.Width = 0; } Borders borders = new Borders { DynamicParameter = borderLayer }; this.Image = borders.ProcessImage(this); } return(this); }
/// <summary> /// The position in the original string where the first character of the captured substring was found. /// </summary> /// <param name="queryString"> /// The query string to search. /// </param> /// <returns> /// The zero-based starting position in the original string where the captured substring was found. /// </returns> public int MatchRegexIndex(string queryString) { int index = 0; //set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; foreach (Match match in this.RegexPattern.Matches(queryString)) { if (match.Success) { if (index == 0) { //Set the index on the first instance only. this.SortOrder = match.Index; BorderLayer borderLayer; string toParse = match.Value; if (toParse.Contains("bgcolor")) { borderLayer = new BorderLayer( this.ParseWidth(toParse), this.ParseColor(toParse), this.ParseEdge(TopRegex, toParse), this.ParseEdge(BottomRegex, toParse), this.ParseEdge(LeftRegex, toParse), this.ParseEdge(RightRegex, toParse) ); } else { int width; int.TryParse(match.Value.Split('=')[1], out width); borderLayer = new BorderLayer(width, this.ParseEdge(TopRegex, toParse), this.ParseEdge(BottomRegex, toParse), this.ParseEdge(LeftRegex, toParse), this.ParseEdge(RightRegex, toParse) ); } this.DynamicParameter = borderLayer; } index += 1; } } return(this.SortOrder); }
protected override IProperty InterpretInternal(String name, Match valueMatch) { //width int bw = Int32.Parse(valueMatch.Groups[1].Value); //style BorderStyle bs = BorderStyle.None; switch (valueMatch.Groups[2].Value) { case "hidden": bs = BorderStyle.Hidden; break; case "dotted": bs = BorderStyle.Dotted; break; case "dashed": bs = BorderStyle.Dashed; break; case "solid": bs = BorderStyle.Solid; break; case "double": bs = BorderStyle.Double; break; } BorderLayer bl = null; if (!BluCSSParser.DebuggerMode) { Match match = CSSConstants.REGEX_COLOUR.Match(valueMatch.Groups[3].Value); Color cssColor = null; if ((match = CSSConstants.REGEX_COLOUR_RGBA.Match(valueMatch.Groups[3].Value)).Success) cssColor = BluCSSParser.RGBA.Interpret(name, match.Value) as Color; else if ((match = CSSConstants.REGEX_COLOUR_HSLA.Match(valueMatch.Groups[3].Value)).Success) cssColor = BluCSSParser.HSLA.Interpret(name, match.Value) as Color; else if ((match = CSSConstants.REGEX_COLOUR_HEX.Match(valueMatch.Groups[3].Value)).Success) cssColor = BluCSSParser.Hex.Interpret(name, match.Value) as Color; else if ((match = CSSConstants.REGEX_COLOUR_KEYWORD.Match(valueMatch.Groups[3].Value)).Success) cssColor = BluCSSParser.Keyword.Interpret(name, match.Value) as Color; //color Microsoft.Xna.Framework.Color bc = new Microsoft.Xna.Framework.Color((int)cssColor.R, (int)cssColor.G, (int)cssColor.B, (int)(cssColor.A * 255.0f)); bl = new BorderLayer(name, bw, bs, bc); } else bl = new BorderLayer(name, bw, bs); return bl; }
private void load(OsuGameBase osuGame, IFrameBasedClock framedClock) { beatmap.BindTo(osuGame.Beatmap); try { rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value); rulesetContainer.Clock = framedClock; } catch (Exception e) { Logger.Error(e, "Could not load beatmap sucessfully!"); return; } var layerBelowRuleset = new BorderLayer { RelativeSizeAxes = Axes.Both, Child = CreateLayerContainer() }; var layerAboveRuleset = CreateLayerContainer(); layerAboveRuleset.Child = new HitObjectMaskLayer(rulesetContainer.Playfield, this); layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerAboveRuleset); RadioButtonCollection toolboxCollection; InternalChild = new GridContainer { RelativeSizeAxes = Axes.Both, Content = new[] { new Drawable[] { new FillFlowContainer { Name = "Sidebar", RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Right = 10 }, Children = new Drawable[] { new ToolboxGroup { Child = toolboxCollection = new RadioButtonCollection { RelativeSizeAxes = Axes.X } } } }, new Container { Name = "Content", RelativeSizeAxes = Axes.Both, Children = new Drawable[] { layerBelowRuleset, rulesetContainer, layerAboveRuleset } } }, }, ColumnDimensions = new[] { new Dimension(GridSizeMode.Absolute, 200), } }; toolboxCollection.Items = CompositionTools.Select(t => new RadioButton(t.Name, () => setCompositionTool(t))) .Prepend(new RadioButton("Select", () => setCompositionTool(null))) .ToList(); toolboxCollection.Items[0].Select(); }
private static void DrawMicroBorders(RenderContext ctx, BorderLayer layer) { const byte FILL_ALPHA = 64; float[] edgex, edgey; PathUtil.PathType borderPathType = ctx.styles.microBorderStyle == MicroBorderStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex; RenderUtil.HexEdges(borderPathType, out edgex, out edgey); XSolidBrush solidBrush = new XSolidBrush(); XPen pen = new XPen(XColor.Empty); ctx.styles.microBorders.pen.Apply(ref pen); foreach (Sector sector in ctx.selector.Sectors) { XGraphicsPath sectorClipPath = null; using (RenderUtil.SaveState(ctx.graphics)) { // This looks craptacular for Candy style borders :( if (ctx.clipOutsectorBorders && (layer == BorderLayer.Fill || ctx.styles.microBorderStyle != MicroBorderStyle.Curve)) { Sector.ClipPath clip = sector.ComputeClipPath(borderPathType); if (!ctx.tileRect.IntersectsWith(clip.bounds)) continue; sectorClipPath = new XGraphicsPath(clip.clipPathPoints, clip.clipPathPointTypes, XFillMode.Alternate); if (sectorClipPath != null) ctx.graphics.IntersectClip(sectorClipPath); } ctx.graphics.SmoothingMode = XSmoothingMode.AntiAlias; foreach (Border border in sector.Borders) { BorderPath borderPath = border.ComputeGraphicsPath(sector, borderPathType); XGraphicsPath drawPath = borderPath.borderPathPoints.Length > 0 ? new XGraphicsPath(borderPath.borderPathPoints, borderPath.borderPathTypes, XFillMode.Alternate) : null; XGraphicsPath clipPath = new XGraphicsPath(borderPath.clipPathPoints, borderPath.clipPathTypes, XFillMode.Alternate); Color? borderColor = border.Color; LineStyle? borderStyle = border.Style; SectorStylesheet.StyleResult ssr = sector.ApplyStylesheet("border", border.Allegiance); borderStyle = borderStyle ?? ssr.GetEnum<LineStyle>("style") ?? LineStyle.Solid; borderColor = borderColor ?? ssr.GetColor("color") ?? ctx.styles.microBorders.pen.color; if (layer == BorderLayer.Stroke && borderStyle.Value == LineStyle.None) continue; if (ctx.styles.grayscale || !ColorUtil.NoticeableDifference(borderColor.Value, ctx.styles.backgroundColor)) { borderColor = ctx.styles.microBorders.pen.color; // default } pen.Color = borderColor.Value; pen.DashStyle = LineStyleToDashStyle(borderStyle.Value); if (ctx.styles.microBorderStyle != MicroBorderStyle.Curve) { // Clip to the path itself - this means adjacent borders don't clash using (RenderUtil.SaveState(ctx.graphics)) { ctx.graphics.IntersectClip(clipPath); if (layer == BorderLayer.Fill) { solidBrush.Color = Color.FromArgb(FILL_ALPHA, borderColor.Value); ctx.graphics.DrawPath(solidBrush, clipPath); } if (layer == BorderLayer.Stroke && drawPath != null) ctx.graphics.DrawPath(pen, drawPath); } } else { if (layer == BorderLayer.Fill) { solidBrush.Color = Color.FromArgb(FILL_ALPHA, borderColor.Value); ctx.graphics.DrawClosedCurve(solidBrush, borderPath.clipPathPoints); } if (layer == BorderLayer.Stroke) { foreach (PointF[] curve in borderPath.curvePoints) { // TODO: Investigate DrawClosedCurve to handle endings // Would need to have path computer tell whether // or not the path was actually a closed loop // Can do it by clipping borders to sector, but that loses // bottom/right overlaps ctx.graphics.DrawCurve(pen, curve, 0.6f); } } } } } } }
private void load(OsuGameBase osuGame) { try { rulesetContainer = CreateRulesetContainer(ruleset, osuGame.Beatmap.Value); // TODO: should probably be done at a RulesetContainer level to share logic with Player. rulesetContainer.Clock = new InterpolatingFramedClock((IAdjustableClock)osuGame.Beatmap.Value.Track ?? new StopwatchClock()); } catch (Exception e) { Logger.Error(e, "Could not load beatmap sucessfully!"); return; } HitObjectOverlayLayer hitObjectOverlayLayer = CreateHitObjectOverlayLayer(); SelectionLayer selectionLayer = new SelectionLayer(rulesetContainer.Playfield); var layerBelowRuleset = new BorderLayer { RelativeSizeAxes = Axes.Both, Child = CreateLayerContainer() }; var layerAboveRuleset = CreateLayerContainer(); layerAboveRuleset.Children = new Drawable[] { selectionLayer, // Below object overlays for input hitObjectOverlayLayer, selectionLayer.CreateProxy() // Proxy above object overlays for selections }; layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerAboveRuleset); RadioButtonCollection toolboxCollection; InternalChild = new GridContainer { RelativeSizeAxes = Axes.Both, Content = new[] { new Drawable[] { new FillFlowContainer { Name = "Sidebar", RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Right = 10 }, Children = new Drawable[] { new ToolboxGroup { Child = toolboxCollection = new RadioButtonCollection { RelativeSizeAxes = Axes.X } } } }, new Container { Name = "Content", RelativeSizeAxes = Axes.Both, Children = new Drawable[] { layerBelowRuleset, rulesetContainer, layerAboveRuleset } } }, }, ColumnDimensions = new[] { new Dimension(GridSizeMode.Absolute, 200), } }; selectionLayer.ObjectSelected += hitObjectOverlayLayer.AddOverlay; selectionLayer.ObjectDeselected += hitObjectOverlayLayer.RemoveOverlay; toolboxCollection.Items = new[] { new RadioButton("Select", () => setCompositionTool(null)) } .Concat( CompositionTools.Select(t => new RadioButton(t.Name, () => setCompositionTool(t))) ) .ToList(); toolboxCollection.Items[0].Select(); }
private void DrawMicroBorders(BorderLayer layer) { const byte FILL_ALPHA = 64; float[] edgex, edgey; PathUtil.PathType borderPathType = styles.microBorderStyle == MicroBorderStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex; RenderUtil.HexEdges(borderPathType, out edgex, out edgey); XSolidBrush solidBrush = new XSolidBrush(); XPen pen = new XPen(XColor.Empty); styles.microBorders.pen.Apply(ref pen); foreach (Sector sector in selector.Sectors) { XGraphicsPath sectorClipPath = null; using (RenderUtil.SaveState(graphics)) { // This looks craptacular for Candy style borders :( if (ClipOutsectorBorders && (layer == BorderLayer.Fill || styles.microBorderStyle != MicroBorderStyle.Curve)) { Sector.ClipPath clip = sector.ComputeClipPath(borderPathType); if (!tileRect.IntersectsWith(clip.bounds)) continue; sectorClipPath = new XGraphicsPath(clip.clipPathPoints, clip.clipPathPointTypes, XFillMode.Alternate); if (sectorClipPath != null) graphics.IntersectClip(sectorClipPath); } graphics.SmoothingMode = XSmoothingMode.AntiAlias; foreach (Border border in sector.Borders) { BorderPath borderPath = border.ComputeGraphicsPath(sector, borderPathType); XGraphicsPath drawPath = new XGraphicsPath(borderPath.points, borderPath.types, XFillMode.Alternate); Color? borderColor = border.Color; LineStyle? borderStyle = border.Style; SectorStylesheet.StyleResult ssr = sector.ApplyStylesheet("border", border.Allegiance); borderStyle = borderStyle ?? ssr.GetEnum<LineStyle>("style") ?? LineStyle.Solid; borderColor = borderColor ?? ssr.GetColor("color") ?? styles.microBorders.pen.color; if (layer == BorderLayer.Stroke && borderStyle.Value == LineStyle.None) continue; if (styles.grayscale || !ColorUtil.NoticeableDifference(borderColor.Value, styles.backgroundColor)) { borderColor = styles.microBorders.pen.color; // default } pen.Color = borderColor.Value; pen.DashStyle = LineStyleToDashStyle(borderStyle.Value); if (styles.microBorderStyle != MicroBorderStyle.Curve) { // Clip to the path itself - this means adjacent borders don't clash using (RenderUtil.SaveState(graphics)) { graphics.IntersectClip(drawPath); switch (layer) { case BorderLayer.Fill: solidBrush.Color = Color.FromArgb(FILL_ALPHA, borderColor.Value); graphics.DrawPath(solidBrush, drawPath); break; case BorderLayer.Stroke: graphics.DrawPath(pen, drawPath); break; } } } else { switch (layer) { case BorderLayer.Fill: solidBrush.Color = Color.FromArgb(FILL_ALPHA, borderColor.Value); graphics.DrawClosedCurve(solidBrush, borderPath.points); break; case BorderLayer.Stroke: foreach (var segment in borderPath.curves) { if (segment.closed) graphics.DrawClosedCurve(pen, segment.points, 0.6f); else graphics.DrawCurve(pen, segment.points, 0.6f); } break; } } } } } }
private void load([NotNull] OsuGameBase osuGame, [NotNull] IAdjustableClock adjustableClock, [NotNull] IFrameBasedClock framedClock, [CanBeNull] BindableBeatDivisor beatDivisor) { this.adjustableClock = adjustableClock; if (beatDivisor != null) { this.beatDivisor.BindTo(beatDivisor); } beatmap.BindTo(osuGame.Beatmap); try { rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value); rulesetContainer.Clock = framedClock; } catch (Exception e) { Logger.Error(e, "Could not load beatmap sucessfully!"); return; } HitObjectMaskLayer hitObjectMaskLayer = new HitObjectMaskLayer(this); SelectionLayer selectionLayer = new SelectionLayer(rulesetContainer.Playfield); var layerBelowRuleset = new BorderLayer { RelativeSizeAxes = Axes.Both, Child = CreateLayerContainer() }; var layerAboveRuleset = CreateLayerContainer(); layerAboveRuleset.Children = new Drawable[] { selectionLayer, // Below object overlays for input hitObjectMaskLayer, selectionLayer.CreateProxy() // Proxy above object overlays for selections }; layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerAboveRuleset); RadioButtonCollection toolboxCollection; InternalChild = new GridContainer { RelativeSizeAxes = Axes.Both, Content = new[] { new Drawable[] { new FillFlowContainer { Name = "Sidebar", RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Right = 10 }, Children = new Drawable[] { new ToolboxGroup { Child = toolboxCollection = new RadioButtonCollection { RelativeSizeAxes = Axes.X } } } }, new Container { Name = "Content", RelativeSizeAxes = Axes.Both, Children = new Drawable[] { layerBelowRuleset, rulesetContainer, layerAboveRuleset } } }, }, ColumnDimensions = new[] { new Dimension(GridSizeMode.Absolute, 200), } }; selectionLayer.ObjectSelected += hitObjectMaskLayer.AddOverlay; selectionLayer.ObjectDeselected += hitObjectMaskLayer.RemoveOverlay; selectionLayer.SelectionCleared += hitObjectMaskLayer.RemoveSelectionOverlay; selectionLayer.SelectionFinished += hitObjectMaskLayer.AddSelectionOverlay; toolboxCollection.Items = new[] { new RadioButton("Select", () => setCompositionTool(null)) } .Concat( CompositionTools.Select(t => new RadioButton(t.Name, () => setCompositionTool(t))) ) .ToList(); toolboxCollection.Items[0].Select(); }