private void AddColorPointButton_Click(object sender, RoutedEventArgs e) { ColorPointModel checkedCp = CurrentColorPoints.FirstOrDefault(p => p.IsChecked == true); if (checkedCp != null && CurrentColorPoints.Count < 7) { int checkedIndex = CurrentColorPoints.IndexOf(checkedCp); int insertIndex; double insertX; if (checkedIndex == CurrentColorPoints.Count - 1) // last { insertIndex = checkedIndex; insertX = (checkedCp.PixelX + CurrentColorPoints[checkedIndex - 1].PixelX) / 2; } else { insertIndex = checkedIndex + 1; insertX = (checkedCp.PixelX + CurrentColorPoints[checkedIndex + 1].PixelX) / 2; } if (Math.Abs(insertX - checkedCp.PixelX) > 12) { ColorPointModel newCp = new ColorPointModel { PixelX = insertX, Color = checkedCp.Color, }; CurrentColorPoints.Insert(insertIndex, newCp); mColorPatternVM.OnCustomizeChanged(); newCp.IsChecked = true; } } }
public void RefreshCurrentCPs() { CurrentColorPoints.Clear(); List <ColorPointModel> d_cps; if (Select == -1) { SetColorPointBorders(CustomizeColorPoints); d_cps = CustomizeColorPoints; } else if (Select < DefaultColorPointListCollection.Count) { d_cps = DefaultColorPointListCollection[Select]; } else { d_cps = DefaultColorPointListCollection[DefaultColorPointListCollection.Count - 1]; } foreach (var d_cp in d_cps) { var cp = ColorPointModel.Copy(d_cp); CurrentColorPoints.Add(cp); } CurrentColorPoints[0].IsChecked = true; RaisePropertyChanged("CurrentColorForground"); RaisePropertyChanged("CustomizeColorForground"); }
public void OnCustomizeChanged() { var oldCPs = GetCustomizedLightData(); SetColorPointBorders(CurrentColorPoints.ToList()); CustomizeColorPoints.Clear(); foreach (var cp in CurrentColorPoints) { CustomizeColorPoints.Add(ColorPointModel.Copy(cp)); } var newCPs = GetCustomizedLightData(); ReUndoManager.Store(new ColorPatternModifyCommand(mInfoModel, oldCPs, newCPs, Select, -1)); Select = -1; RaisePropertyChanged("CurrentColorForground"); RaisePropertyChanged("CustomizeColorForground"); }
private void RemoveColorPointButton_Click(object sender, RoutedEventArgs e) { ColorPointModel checkedCp = CurrentColorPoints.FirstOrDefault(p => p.IsChecked == true); if (checkedCp != null && CurrentColorPoints.Count > 2) { int curIndex = CurrentColorPoints.IndexOf(checkedCp); int needCheckedIndex; if (curIndex == CurrentColorPoints.Count - 1) // last { needCheckedIndex = curIndex - 1; } else { needCheckedIndex = curIndex; } CurrentColorPoints.Remove(checkedCp); mColorPatternVM.OnCustomizeChanged(); CurrentColorPoints[needCheckedIndex].IsChecked = true; } }
private void ParsingLayers(XmlNodeList layerNodes) { foreach (XmlNode node in layerNodes) { XmlElement element = (XmlElement)node; string layerName = element.GetAttribute("name"); string eye = element.GetAttribute("Eye"); LayerModel layer = new LayerModel(layerName); layer.Eye = bool.Parse(eye); layer.TriggerAction = element.GetAttribute("trigger"); // parsing effects XmlNode effectsNode = element.SelectSingleNode("effects"); foreach (XmlNode effectNode in effectsNode.ChildNodes) { XmlElement element2 = (XmlElement)effectNode; int type = Int32.Parse(element2.SelectSingleNode("type").InnerText); List <ColorPointModel> colorPoints = new List <ColorPointModel>(); XmlNode colorPointListNode = element2.SelectSingleNode("colorPointList"); foreach (XmlNode colorpoint in colorPointListNode.ChildNodes) { ColorPointModel cp = new ColorPointModel(); XmlElement element3 = (XmlElement)colorpoint; cp.Color = new Color { A = Byte.Parse(element3.SelectSingleNode("a").InnerText), R = Byte.Parse(element3.SelectSingleNode("r").InnerText), G = Byte.Parse(element3.SelectSingleNode("g").InnerText), B = Byte.Parse(element3.SelectSingleNode("b").InnerText), }; cp.Offset = double.Parse(element3.SelectSingleNode("offset").InnerText); colorPoints.Add(cp); } EffectInfoModel info = new EffectInfoModel(type) { InitColor = new Color { A = Byte.Parse(element2.SelectSingleNode("a").InnerText), R = Byte.Parse(element2.SelectSingleNode("r").InnerText), G = Byte.Parse(element2.SelectSingleNode("g").InnerText), B = Byte.Parse(element2.SelectSingleNode("b").InnerText), }, DoubleColor1 = new Color { A = Byte.Parse(element2.SelectSingleNode("d1a").InnerText), R = Byte.Parse(element2.SelectSingleNode("d1r").InnerText), G = Byte.Parse(element2.SelectSingleNode("d1g").InnerText), B = Byte.Parse(element2.SelectSingleNode("d1b").InnerText), }, DoubleColor2 = new Color { A = Byte.Parse(element2.SelectSingleNode("d2a").InnerText), R = Byte.Parse(element2.SelectSingleNode("d2r").InnerText), G = Byte.Parse(element2.SelectSingleNode("d2g").InnerText), B = Byte.Parse(element2.SelectSingleNode("d2b").InnerText), }, Type = type, Speed = Int32.Parse(element2.SelectSingleNode("speed").InnerText), Angle = Int32.Parse(element2.SelectSingleNode("angle").InnerText), RandomRangeMax = Int32.Parse(element2.SelectSingleNode("randomRangeMax").InnerText), RandomRangeMin = Int32.Parse(element2.SelectSingleNode("randomRangeMin").InnerText), ColorModeSelection = Int32.Parse(element2.SelectSingleNode("colormodeselection").InnerText), High = Int32.Parse(element2.SelectSingleNode("high").InnerText), Low = Int32.Parse(element2.SelectSingleNode("low").InnerText), PatternSelect = Int32.Parse(element2.SelectSingleNode("patternSelect").InnerText), CustomizedPattern = new List <ColorPointModel>(colorPoints), ColorSegmentation = bool.Parse(element2.SelectSingleNode("colorSegmentation").InnerText), RainbowSpecialEffects = bool.Parse(element2.SelectSingleNode("rainbowRotation").InnerText), RainbowSpecialMode = Int32.Parse(element2.SelectSingleNode("rotationMode").InnerText), }; if (!IsTriggerEffect(type)) { TimelineEffect eff = new TimelineEffect(type); eff.StartTime = Int32.Parse(element2.SelectSingleNode("start").InnerText); eff.DurationTime = Int32.Parse(element2.SelectSingleNode("duration").InnerText); eff.Info = info; layer.AddTimelineEffect(new EffectLineViewModel(eff)); } else { TriggerEffect eff = new TriggerEffect(type); eff.StartTime = Int32.Parse(element2.SelectSingleNode("start").InnerText); eff.DurationTime = Int32.Parse(element2.SelectSingleNode("duration").InnerText); eff.Info = info; layer.AddTriggerEffect(eff); layer.IsTriggering = true; } } // parsing zones XmlNode devicesNode = element.SelectSingleNode("devices"); foreach (XmlNode deviceNode in devicesNode.ChildNodes) { Dictionary <int, int[]> zoneDictionary = new Dictionary <int, int[]>(); List <int> zones = new List <int>(); XmlElement element2 = (XmlElement)deviceNode; string typeName = element2.GetAttribute("type"); int type = GetTypeByTypeName(typeName); XmlNodeList indexNodes = element2.ChildNodes; foreach (XmlNode index in indexNodes) { zones.Add(Int32.Parse(index.InnerText)); } zoneDictionary.Add(type, zones.ToArray()); layer.AddDeviceZones(zoneDictionary); } LayerPage.AddLayer(layer); } }