private bool GroupContains(GroupedSvgElems search, SvgElement elem) { if (search.Any(i => i == elem)) { return(true); } foreach (var i in elem.Children) { if (GroupContains(search, i)) { return(true); } } return(false); }
private void InitGroups(SvgSkin skin) { // groups svg elements by fill and stroke var all = skin.SvgDocument.Children.FindSvgElementsOf <SvgVisualElement>() .Where(e => e.ContainsAttribute("fill") || e.ContainsAttribute("stroke")); _groups.Clear(); var grouped = all.GroupBy(e => new { e.Fill, e.Stroke }).ToList(); foreach (var group in grouped) { var g = new GroupedSvgElems(group.Key.Fill, group.Key.Stroke); g.AddRange(group.AsEnumerable()); _groups.Add(g); } }
private void SelectGroup(GroupedSvgElems group) { if (_selectedGroup == group) { return; } _selectingGroup = true; if (_selectedGroup != null) { RestoreGroup(); } _selectedGroup = group; colorPicker.Mode = ColorPickerControl.ColorSelectMode.None; colorPicker.PrimaryEnabled = pnlFill.Visible = group.Fill is SvgColourServer; colorPicker.SecondaryEnabled = pnlStroke.Visible = group.Stroke is SvgColourServer; Color cFill = Color.Empty; if (group.Fill is SvgColourServer cf) { cFill = cf.Colour; } colorPicker.PrimaryColor = _bkpFill = _selFill = cFill; Color cStroke = Color.Empty; if (group.Stroke is SvgColourServer sf) { cStroke = sf.Colour; } colorPicker.SecondaryColor = _bkpStroke = _selStroke = cStroke; // instantly highlight and resync timer if (cbFlash.Checked) { HighlightGroup(true); timer.Stop(); timer.Start(); } _selectingGroup = false; }
public SkinRemapperForm(string path, ColorRemap remap) : this() { _skin = new SvgSkin(); _skin.Load(path); Remap = remap; remap.ApplyToSkin(this._skin); var highlightElems = _skin.Buttons.Where(b => b.Pressed != null).Select(b => b.Pressed) .Union(_skin.Sticks.Where(s => s.Pressed != null).Select(s => s.Pressed)); var nonHighlightElems = _skin.Buttons.Where(b => b.Element != null).Select(b => b.Element) .Union(_skin.Sticks.Where(s => s.Element != null).Select(s => s.Element)) .Union(_skin.Triggers.Where(t => t.Element != null).Select(t => t.Element)); // split remap groups into highlight/non-highlight/base categories foreach (var group in remap.Groups) { var grpHl = new GroupedSvgElems(group.Fill, group.Stroke); var grpNonHl = new GroupedSvgElems(group.Fill, group.Stroke); var grpBase = new GroupedSvgElems(group.Fill, group.Stroke); foreach (var elem in group) { bool hl = GroupContains(elem, highlightElems); bool nonHl = GroupContains(elem, nonHighlightElems); if (hl) { grpHl.Add(elem); } if (nonHl) { grpNonHl.Add(elem); } if (!hl && !nonHl) { grpBase.Add(elem); } } if (grpNonHl.Count == 0 && grpBase.Count == 0) { // this is entirely a HL group _highlights.Add(group); } else if (grpHl.Count == 0 && grpBase.Count == 0) { // this is entirely a non-HL group _nonHighlights.Add(group); } else if (grpHl.Count == 0 && grpNonHl.Count == 0) { _base.Add(group); } else { // split up if (grpHl.Any()) { _highlights.Add(grpHl); } if (grpNonHl.Any()) { _nonHighlights.Add(grpNonHl); } if (grpBase.Any()) { _base.Add(grpBase); } } } tbSkinName.DataBindings.Add("Text", Remap, "Name"); lbGroups.DisplayMember = nameof(GroupedSvgElems.Name); PopulateListbox(); }
private bool GroupContains(GroupedSvgElems search, IEnumerable <SvgElement> elems) { return(elems.Any(e => GroupContains(search, e))); }