public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var color = (string) value; try { TypeConverter colorConverter = new ColorConverter(); var baseColor = (Color) colorConverter.ConvertFromString(color); var c2 = Color.FromArgb(25, baseColor.R, baseColor.G, baseColor.B); var colorBrush = new LinearGradientBrush(); colorBrush.StartPoint = new Point(0, 0); colorBrush.EndPoint = new Point(0, 1); colorBrush.GradientStops.Add(new GradientStop(c2, 0.15)); colorBrush.GradientStops.Add(new GradientStop(baseColor, 0.85)); colorBrush.GradientStops.Add(new GradientStop(c2, 1)); return colorBrush; } catch (Exception) { return Brushes.DarkRed; } }
private void definirBarra(double imc, string avaliacao) { TypeConverter cc = new ColorConverter(); string texto = "IMC"; Console.WriteLine("IMC: " + imc); rectObesityBar.Width = 340 * (imc / 50.0); switch (avaliacao) { case "Normal": rectObesityBar.Fill = (SolidColorBrush)new BrushConverter().ConvertFromString("Blue"); texto = "Seu IMC está bom"; break; case "Magro": rectObesityBar.Fill = (SolidColorBrush)new BrushConverter().ConvertFromString("Green"); texto = "Você está subnutrido"; break; case "Obeso": rectObesityBar.Fill = (SolidColorBrush)new BrushConverter().ConvertFromString("Red"); texto = "Você está com obesidade"; break; } lblResultado.Content = texto; }
private void Initialize() { try { ColorConverter cc = new ColorConverter(); _colourStart = new byte[3]; _colourStop = new byte[3]; _brushPosted = (Color)ColorConverter.ConvertFromString("#FF0DE251"); _brushNotPosted = (Color)ColorConverter.ConvertFromString("#FFEA402F"); _colourStart[0] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStartR")); _colourStart[1] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStartG")); _colourStart[2] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStartB")); _colourStop[0] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStopR")); _colourStop[1] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStopG")); _colourStop[2] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStopB")); _brushNotTransparent = new RadialGradientBrush( Color.FromRgb(_colourStart[0], _colourStart[1], _colourStart[2]), Color.FromRgb(_colourStop[0], _colourStop[1], _colourStop[2])); OverrideSelectionEvent += UIPictureBox_OverrideSelectionEvent; } catch (Exception) { } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var ratio = System.Convert.ToDouble(value) / Scale; if (ratio > 1.0 || ratio < 0.0) { throw new ArgumentException("value must lie between 0 and Scale."); } var dif = 255 * (1 - ratio); byte a = Color.A, r = Color.R, g = Color.G, b = Color.B; switch (ScaleOption) { case ScaleOption.ScaleAlphaOnly: a = System.Convert.ToByte(ratio * 255); break; case ScaleOption.ScaleRedOnly: g = CalculateComponent(ratio, dif, g); b = CalculateComponent(ratio, dif, b); break; case ScaleOption.ScaleGreenOnly: b = CalculateComponent(ratio, dif, b); r = CalculateComponent(ratio, dif, r); break; case ScaleOption.ScaleBlueOnly: r = CalculateComponent(ratio, dif, r); g = CalculateComponent(ratio, dif, g); break; case ScaleOption.ScaleRgb: r = CalculateComponent(ratio, dif, r); g = CalculateComponent(ratio, dif, g); b = CalculateComponent(ratio, dif, b); break; default: throw new NotImplementedException(); } var newColor = Color.FromArgb(a, r, g, b); if (targetType == typeof(Color)) { return newColor; } if (targetType == typeof(Brush)) { return new SolidColorBrush(newColor); } if (targetType == typeof(string)) { var con = new ColorConverter(); con.ConvertToString(null, culture, newColor); } throw new NotSupportedException(); }
public ButtonOfDevice(XElement dev) { InitializeComponent(); if (dev.Parent.Name == "Adapter") { //this.usercontrol.Width = 120; this.Width = 120; this.grid.Width = 110; this.Code.Width = 110; this.Tag1.Width = 110; this.Tag2.Width = 110; this.Tag3.Width = 110; this.Tag4.Width = 110; this.Tag5.Width = 110; this.Power.Width = 110; this.line2.X2 += 50; this.line3.X1 += 50; this.line3.X2 += 50; this.line1.Stroke = Brushes.Red; this.line2.Stroke = Brushes.Red; this.line3.Stroke = Brushes.Red; this.line1.StrokeThickness = 4; this.line3.StrokeThickness = 0; } if (dev.Element("Name").Value == "电源模块") { this.line1.Stroke = Brushes.Red; this.line2.Stroke = Brushes.Red; this.line3.Stroke = Brushes.Red; this.line1.StrokeThickness = 4; this.line3.StrokeThickness = 0; } ColorConverter cc = new ColorConverter(); Color c = (Color)cc.ConvertFrom(dev.Parent.Attribute("color").Value); this.Code.Background = new SolidColorBrush(c); this.Margin = new Thickness(5, 0, 0, 0); this.Code.Content = dev.Element("Code").Value.ToString(); this.Tag1.Content = dev.Element("Tags").Attribute("tag1").Value; this.Tag2.Content = dev.Element("Tags").Attribute("tag2").Value; this.Tag3.Content = dev.Element("Tags").Attribute("tag3").Value; this.Tag4.Content = dev.Element("Tags").Attribute("tag4").Value; this.Tag5.Content = dev.Element("Tags").Attribute("tag5").Value; this.Power.Content = Convert.ToInt32(dev.Element("OutCurrent").Value) - Convert.ToInt32(dev.Element("InCurrent").Value); if (Convert.ToInt32(this.Power.Content.ToString()) == 0) { this.line1.StrokeThickness = 0; this.line2.Stroke = Brushes.Green; this.line3.StrokeThickness = 0; } }
private LinearGradientBrush CreateBrush(string baseColor, string centerColor) { var converter = new ColorConverter(); var linearGradientBrush = new LinearGradientBrush(); linearGradientBrush.StartPoint = new Point(0.5, 0); linearGradientBrush.EndPoint = new Point(0.5, 1); linearGradientBrush.GradientStops.Add(new GradientStop((Color)converter.ConvertFrom(baseColor), 0)); linearGradientBrush.GradientStops.Add(new GradientStop((Color)converter.ConvertFrom(centerColor), 0.5)); linearGradientBrush.GradientStops.Add(new GradientStop((Color)converter.ConvertFrom(baseColor), 1)); return linearGradientBrush; }
/// <summary> /// Initializes a new instance of the <see cref="RubberbandAdorner"/> class. /// </summary> /// <param name="canvas">The canvas.</param> /// <param name="dragStartPoint">The drag start point.</param> public RubberbandAdorner(Desktop canvas, Point? dragStartPoint) : base(canvas) { ColorConverter cconverter = new ColorConverter(); this.desktop = canvas; this.startPoint = dragStartPoint; this.rubberbandPen = new Pen(new SolidColorBrush((Color)cconverter.ConvertFrom("#FF7AA3D4")), 1); this.rubberbandPen.DashStyle = new DashStyle(); this.backgroundBrush = new SolidColorBrush((Color)cconverter.ConvertFrom("#FFC5D5E9")); this.backgroundBrush.Opacity = 0.40; }
private Color ConvertToColor(string colorString) { try { var colorConverter = new ColorConverter(); return colorConverter.ConvertFromString(colorString); } catch (Exception) { throw new InvalidCastException("String provided is not in a recognized Hex format."); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var airline = (Airline) value; try { TypeConverter colorConverter = new ColorConverter(); var c = (Color) colorConverter.ConvertFromString(airline.Profile.Color); return new SolidColorBrush(c); } catch { return Brushes.White; } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var converter = new ColorConverter(); switch ((TaskState)value) { case TaskState.Normal: //#13aa13 return new SolidColorBrush((Color)converter.ConvertFrom("#00CC00")); case TaskState.Warning: //#b8a400 return new SolidColorBrush((Color)converter.ConvertFrom("#FFFF00")); //"#d9bf1b" case TaskState.Error: //#d21313 return new SolidColorBrush((Color)converter.ConvertFrom("#FF0000")); } throw new NotImplementedException("Could not convert state to color"); }
public static int colorizing(System.Windows.Media.Color color) { if (color == System.Windows.Media.Colors.White) { return 16777215; } int iColor = color.R + 0xFF * color.G + 0xFFFF * color.B; string myHex = new ColorConverter().ConvertToString(iColor); //Console.WriteLine(iColor+" spalva R: "+color.R+" G: "+color.G+" B: "+color.B+" "+ myHex); //string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B); //Color colorAfter = (Color)ColorConverter.ConvertFromString(myHex); //Color colorAfter = ConvertStringToColor(myHex); //Console.WriteLine(iColor + " spalva R: " + colorAfter.R + " G: " + colorAfter.G + " B: " + colorAfter.B + " " + myHex); iColor = Int32.Parse(myHex); return iColor; }
//public Light Lighting { get; private set; } public FullScene() { // Define the camera var camera = new PerspectiveCamera(); camera.Position = new Point3D(0, .25, 10); camera.LookDirection = new Vector3D(0, 0, -1); //camera.LookDirection = new Vector3D(0, -.05, -1); camera.UpDirection = new Vector3D(0, 1, 0); camera.FieldOfView = 60; //var camera = new OrthographicCamera(); //camera.Position = new Point3D(0, 0, 85); //camera.LookDirection = new Vector3D(0, -.05, -4); //camera.NearPlaneDistance = 0; //camera.FarPlaneDistance = 100; ColorConverter conv = new ColorConverter(); var color = (Color)conv.ConvertFrom("#ffffff"); //var ambient = new AmbientLight(color); var pos = new Point3D(0, 10, 10); var spotlight = new SpotLight(); spotlight.Color = color; spotlight.Position = pos; spotlight.InnerConeAngle = 180; spotlight.OuterConeAngle = 90; spotlight.Direction = new Vector3D(pos.X * -1, pos.Y * -1, pos.Z * -1); // Define a lighting model // Collect the components this.modelGroup = new Model3DGroup(); this.modelGroup.Children.Add(ambientLight); this.modelGroup.Children.Add(spotlight); ModelVisual3D visual = new ModelVisual3D(); visual.Content = this.modelGroup; Viewport3D viewport = new Viewport3D(); viewport.Children.Add(visual); viewport.Camera = camera; this.Viewport = viewport; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Color color = (Color)System.Convert.ChangeType(value, typeof(Color)); Color parameterColor; if (parameter is Color) parameterColor = (Color)parameter; else { var converter = new System.Windows.Media.ColorConverter(); parameterColor = (Color)converter.ConvertFrom(parameter); } return Color.FromArgb( (byte)(color.A * parameterColor.A / 255), (byte)(color.R * parameterColor.R / 255), (byte)(color.G * parameterColor.G / 255), (byte)(color.B * parameterColor.B / 255) ); }
/// <summary> /// 色をブラシに変換します。 /// </summary> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { if (targetType != typeof(Brush) && targetType != typeof(SolidColorBrush)) { throw new InvalidOperationException( "変換先のオブジェクトがブラシではありません。"); } if (value.GetType() == typeof(Color)) { var brush = new SolidColorBrush((Color)value); brush.Freeze(); return brush; } else if (value.GetType() == typeof(string)) { var converter = new ColorConverter(); var color = (Color)converter.ConvertFrom(value); var brush = new SolidColorBrush((Color)value); brush.Freeze(); return brush; } return null; } catch (InvalidCastException ex) { Log.ErrorException(ex, "ColorToSolidColorBrushConverter: " + "ブラシに変換できませんでした。"); return Brushes.Red; } }
public static void SetValue(string key, string value) { try { var type = Default[key].GetType() .Name; switch (type) { case "Boolean": Default[key] = Convert.ToBoolean(value); break; case "Color": var cc = new ColorConverter(); var color = cc.ConvertFrom(value); Default[key] = color ?? Colors.Black; break; case "Double": Default[key] = Convert.ToDouble(value); break; case "Font": var fc = new FontConverter(); var font = fc.ConvertFromString(value); Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12); break; default: Default[key] = value; break; } } catch (SettingsPropertyNotFoundException ex) { Logging.Log(LogManager.GetCurrentClassLogger(), "", ex); } catch (SettingsPropertyWrongTypeException ex) { Logging.Log(LogManager.GetCurrentClassLogger(), "", ex); } }
public static Color GetColor(this Configuration cfg, string key, Color defaultColor) { string colorString = cfg.GetValue<string>(key); if (colorString != null) { ColorConverter converter = new ColorConverter(); if (converter.CanConvertFrom(typeof(string))) { try { Color color = (Color)converter.ConvertFrom(null, null, colorString); return color; } catch (Exception) { stdio.ErrorFormat("color setting {0} = {1} not supported", key, colorString); } } } return defaultColor; }
public void SetValue(string key, string value, CultureInfo cultureInfo) { try { var type = Default[key].GetType() .Name; switch (type) { case "Boolean": Default[key] = Boolean.Parse(value); break; case "Color": var cc = new ColorConverter(); var color = cc.ConvertFrom(value); Default[key] = color ?? Colors.Black; break; case "Double": Default[key] = Double.Parse(value, cultureInfo); break; case "Font": var fc = new FontConverter(); var font = fc.ConvertFromString(value); Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12); break; case "Int32": Default[key] = Int32.Parse(value, cultureInfo); break; default: Default[key] = value; break; } } catch (Exception ex) { Logging.Log(LogManager.GetCurrentClassLogger(), "", ex); } RaisePropertyChanged(key); }
private static void Buttons_MouseLeave(object sender, MouseEventArgs e) => ((Button)sender).Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Settings.Theme.ButtonBackgroundColor)) { Opacity = Settings.Theme.ButtonTransparency / 100.0 };
private void ConfigureAndTriggerSchedule(DAL.Schedule currentSchedule) { Boolean CoreWorkingOK = true; si.sie("ConfigureAndTriggerSchedule"); string allTickerText = ""; KillTicker(); Boolean tickerFound = false; TickerMetaToUse = ""; contentCollection.Clear(); try { //"text 0 690 1024 80 clWhite Arial 48 5" gridFive.Visibility = Visibility.Collapsed; gridFour.Visibility = Visibility.Collapsed; gridThree.Visibility = Visibility.Collapsed; gridTwo.Visibility = Visibility.Collapsed; #region CollectContentCollection try { foreach (DAL.Content item in proxy.CollectMedia()) { contentCollection.Add(item); } } catch (Exception ex) { CoreWorkingOK = false; contentCollection.Clear(); } si.sii("Content Collection Count = " + contentCollection.Count().ToString()); //if there is an error the collection is cleared and loaded from xml, if it worked the collection is saved for future use if (contentCollection.Count > 0) { SerializeContentCollection(@"c:\tmp\content.xml"); } else { contentCollection.Clear(); if (FTPONLY) { contentCollection = DeSerializeContentCollection(@"c:\tmp\xml\content.xml"); } else { contentCollection = DeSerializeContentCollection(@"c:\tmp\content.xml"); } }; #endregion si.sii("Collecting Media in Content Collection"); CollectMediaInContentCollection(); //Collect All Media si.sii("Collect this loop:"+currentSchedule.Loopname); #region CollectCurrentLoop try { if (CoreWorkingOK) { currentLoop = proxy.CollectThisLoop(currentSchedule.Loopname); //Collect Loop SerializeCurrentLoop(@"c:\tmp\loop.xml"); } else { currentLoop = null; } } catch (Exception) { currentLoop = null; } if (currentLoop == null) si.sii("Current Loop is NULL possibly because Core isn't working - Collect from XML"); si.sii("FTP Only Variable = "+FTPONLY.ToString()); if (currentLoop == null) { if (FTPONLY) { si.sii(@"INSIDE FTP ONLY - Deserializing c:\tmp\xml\loops.xml"); ObservableCollection<Loop> lc = new ObservableCollection<Loop>(); //DAL.LoopCollection lc = new LoopCollection(); try { lc = DeSerializeLoopCollection(@"c:\tmp\xml\loops.xml"); si.sii(@"Items in Loops.xml:"+lc.Count.ToString()); } catch (Exception e3) { si.six(e3); } foreach (var l in lc) { si.sii("Stepping through loops.xml:"+l.Name+"/"+l.Templatename+"/"+l.Templateid.ToString()); if (l.Name == currentSchedule.Loopname) { currentLoop = l; si.sii("Current Loop = "+currentLoop.Name); break; } } } else { currentLoop = DeSerializeCurrentLoop(@"c:\tmp\loop.xml"); } } #endregion try { LastLoopTick = proxy.CollectDelta("loop"); LastTickerTick = proxy.CollectDelta("ticker"); } catch (Exception) { } #region CollectTemplateCollection si.sii("Collect this template:" + currentLoop.Templatename); try { templateCollection = proxy.CollectZonesForThisTemplateName(currentLoop.Templatename); //CollectTemplate } catch (Exception) { templateCollection.Clear(); } if (templateCollection.Count > 0) { SerializeTemplateCollection(@"c:\tmp\template.xml"); } else { if (FTPONLY) { try { templateCollection.Clear(); //TemplateCollection tmpCollection = new TemplateCollection(); ObservableCollection<Template> tmpCollection = new ObservableCollection<DAL.Template>(); tmpCollection = DeSerializeTemplateCollection(@"c:\tmp\xml\template.xml"); foreach (var t in tmpCollection) { if (t.Name == currentLoop.Templatename && t.Zonename != "_template") { templateCollection.Add(t); si.sii("Template Zone Added = " + t.Name + "/" + t.Zonename + "/" + t.Zonedescription); } } si.sii("Zones in Template = "+templateCollection.Count.ToString()); } catch (Exception x1) { si.six(x1); } } else { templateCollection = DeSerializeTemplateCollection(@"c:\tmp\template.xml"); foreach (var t in templateCollection) { si.sii("Template Zone Added = " + t.Name + "/" + t.Zonename + "/" + t.Zonedescription); } si.sii("Zones in Template = " + templateCollection.Count.ToString()); } } #endregion //Populate Zones contentQ.Clear(); contentQ2.Clear(); contentQ3.Clear(); contentQ4.Clear(); contentQ5.Clear(); int count = 1; int tickerInCount = 0; //equals count where ticker is found, 0 by default means no ticker int backGroundCount = 0; // //equals count where ticker is found, 0 by default means background is empty (we hide this grid) string TickerBackgroundColour = ""; double TickerOpacity = 0; allTickerText = ""; si.sii("==============================="); si.sii("==============================="); foreach (var item in templateCollection) { try { if (CoreWorkingOK) { loopContentCollection = proxy.CollectLoopContentForZoneByName(item.Zonename, currentLoop.Name); SerializeLoopContentCollection(@"c:\tmp\zone\" + item.Zonename + ".xml", loopContentCollection); } else if (FTPONLY && File.Exists(@"c:\tmp\xml\allloopcontent.xml")) { //LoopContentCollection tmpLCC = new LoopContentCollection(); ObservableCollection<LoopContent> tmpLCC = new ObservableCollection<LoopContent>(); si.sii("Collecting from tmpxml alllloopcontent.xml"); tmpLCC = DeSerializeLoopContentCollection(@"c:\tmp\xml\allloopcontent.xml"); si.sii("LoopContent Items collected from xml = " + tmpLCC.Count.ToString()); loopContentCollection.Clear(); foreach (LoopContent c in tmpLCC) { si.sii("STEPPING THROUGH Loop Content tmpLCC:" + c.Medianame); if (c.Zonename == item.Zonename && c.Loopname == currentLoop.Name) { si.sii("ADDING TO LOOP Content Collection Content tmpLCC:" + c.Medianame); loopContentCollection.Add(c); } } } else { loopContentCollection = DeSerializeLoopContentCollection(@"c:\tmp\zone\" + item.Zonename + ".xml"); } } catch (Exception ei) { si.six(ei); } if (item.ZoneType.ToLower() == "Location and Weather strip".ToLower()) { tbLocation.Text = Properties.Settings.Default.ClientID.ToUpper(); borderWeatherStrip.Visibility = Visibility.Visible; UpdateWeather(); } if (item.ZoneType.ToLower() == "Weather Box".ToLower()) { tbLocation.Text = Properties.Settings.Default.ClientID.ToUpper(); borderWeatherRight.Visibility = Visibility.Visible; UpdateWeather(); } si.sii(item.Zonename + "/" + item.X + "/" + item.Width); foreach (var lc in loopContentCollection) { #region First Configure the Ticker try { foreach (var cc in contentCollection) { if (cc.Contenttype == "Ticker" && lc.Mediaid == cc.Id) { //Return All TickerMeta allTickerText += cc.Metadata8 + " "; TickerMeta = "text"; TickerMeta += " " + item.X.ToString(); //"text 0 690 1024 80 clWhite Arial 48 5" TickerMeta += " " + item.Y.ToString(); TickerMeta += " " + item.Width.ToString(); TickerMeta += " " + item.Height.ToString(); Color tickerC = new Color(); ColorConverter ccv = new ColorConverter(); string tickerColour = cc.Metadata4; TickerMeta += " $00" + tickerColour.Substring(7, 2) + tickerColour.Substring(5, 2) + tickerColour.Substring(3, 2);//0000FF";// Color.FromRgb(0xFF, 0xFF, 0xFF).ToString(); //Color TickerBackgroundColour = cc.Metadata6; TickerOpacity = Convert.ToDouble(cc.Metadata7); UserControlContent.TickerBackgroundOpacity = TickerOpacity; TickerMeta += " " + cc.Metadata2; //Font TickerMeta += " " + cc.Metadata3; //Size //TickerMeta += " " + cc.Metadata5; //Speed TickerMeta += " 12"; if (lc.Order == 1) { tickerFound = true; UserControlContent.TickerBackgroundColour = TickerBackgroundColour; TickerMetaToUse = TickerMeta; tickerInCount = count; si.sii("TICKER METADATA = " + TickerMeta); } } } } catch (Exception ex) { } #endregion //Do the rest si.sii("Looping through ContentCollection...Medianame="+lc.Medianame+" / LoopName="+lc.Loopname); foreach (var cc in contentCollection) { if (cc.Contenttype != "Ticker" && lc.Mediaid == cc.Id) { //selectedn = @"c:\content\_media\" + System.IO.Path.GetFileName(selectedn); if (cc.Contenttype == "Background") backGroundCount = count; if (count == 1) { contentQ2.Add(cc); si.sii("ADDING CONTENT TO Q2:"+cc.Filelocation); } if (count == 2) { contentQ3.Add(cc); si.sii("ADDING CONTENT TO Q3:" + cc.Filelocation); } if (count == 3) { contentQ4.Add(cc); } if (count == 4) contentQ5.Add(cc); si.sii(@"c:\content\_media\" + System.IO.Path.GetFileName(cc.Filelocation)); } } } try { WriteTickerFile(allTickerText); } catch (Exception) { } uccTwo = new UserControlContent(); uccThree = new UserControlContent(); uccFour = new UserControlContent(); uccFive = new UserControlContent(); Grid currentGrid = null; #region PopulateGridWithContent if (count == 1) { if (tickerInCount == 1) { uccTwo.IsTickerBackground = true; } gridTwo.Children.Clear(); gridTwo.Children.Add(uccTwo); currentGrid = gridTwo; if (contentQ.Count == 0) currentGrid = gridHiddenGrid; uccTwo.SetContentQ(contentQ2); KeepAliveTicker++; si.sii("Firing Grid 2"); } else if (count == 2) { if (tickerInCount == 2) { uccThree.IsTickerBackground = true; } gridThree.Children.Clear(); gridThree.Children.Add(uccThree); currentGrid = gridThree; uccThree.SetContentQ(contentQ3); KeepAliveTicker++; si.sii("Firing Grid 3"); } else if (count == 3) { if (tickerInCount == 3) { uccFour.IsTickerBackground = true; } gridFour.Children.Clear(); gridFour.Children.Add(uccFour); currentGrid = gridFour; uccFour.SetContentQ(contentQ4); KeepAliveTicker++; si.sii("Firing Grid 4"); } else if (count == 4) { if (tickerInCount == 4) { uccFive.IsTickerBackground = true; } gridFive.Children.Clear(); gridFive.Children.Add(uccFive); currentGrid = gridFive; uccFive.SetContentQ(contentQ5); KeepAliveTicker++; si.sii("Firing Grid 5"); }; #endregion //gridTwo.Children.Add(ucc); //ucc.SetContentQ(contentQ); double x = Convert.ToDouble(item.X); //sim("targetx=" + target.x); double y = Convert.ToDouble(item.Y); //sim("targety=" + target.y); double width = Convert.ToDouble(item.Width); double height = Convert.ToDouble(item.Height); currentGrid.Width = width; currentGrid.Height = height; currentGrid.Opacity = Convert.ToDouble(item.Opacity); Canvas.SetTop(currentGrid, y); Canvas.SetLeft(currentGrid, x); //Canvas.SetZIndex(currentGrid, Convert.ToInt16(target.layer)); //sim(gridIndex + "|" + currentGrid + "x=" + x + " y=" + y); currentGrid.Visibility = Visibility.Visible; count++; if (backGroundCount == 1) gridTwo.Visibility = Visibility.Collapsed; if (backGroundCount == 2) gridThree.Visibility = Visibility.Collapsed; if (backGroundCount == 3) gridFour.Visibility = Visibility.Collapsed; if (backGroundCount == 4) gridFive.Visibility = Visibility.Collapsed; } } catch { } try { tickerTimer.Start(); } catch (Exception ex) { } si.sil("ConfigureAndTriggerSchedule"); //this.Topmost = true; //this.Activate(); //this.Focus(); }
private static void DrawGridPatch( Vector3Collection positions, IntCollection indices, Color4Collection colors, int startX, int startY) { var c1 = (System.Windows.Media.Color)ColorConverter.ConvertFromString("#c5d1d8"); c1.Clamp(); var c2 = (System.Windows.Media.Color)ColorConverter.ConvertFromString("#ddeaf2"); c2.Clamp(); var darkGridColor = new Color4(new Vector4(c1.ScR, c1.ScG, c1.ScB, 1)); var lightGridColor = new Color4(new Vector4(c2.ScR, c2.ScG, c2.ScB, 1)); const int size = 10; for (var x = startX; x <= startX + size; x++) { if (x == 0 && startY < 0) { continue; } var v = new Vector3(x, -.001f, startY); positions.Add(v); indices.Add(positions.Count - 1); positions.Add(new Vector3(x, -.001f, startY + size)); indices.Add(positions.Count - 1); if (x % 5 == 0) { colors.Add(darkGridColor); colors.Add(darkGridColor); } else { colors.Add(lightGridColor); colors.Add(lightGridColor); } } for (var y = startY; y <= startY + size; y++) { if (y == 0 && startX >= 0) { continue; } positions.Add(new Vector3(startX, -.001f, y)); indices.Add(positions.Count - 1); positions.Add(new Vector3(startX + size, -.001f, y)); indices.Add(positions.Count - 1); if (y % 5 == 0) { colors.Add(darkGridColor); colors.Add(darkGridColor); } else { colors.Add(lightGridColor); colors.Add(lightGridColor); } } }
private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { RichTextBox richTextBox = d as RichTextBox; if (richTextBox == null) { return; } string content = (string)e.NewValue; if (string.IsNullOrEmpty(content)) { return; } var dd = richTextBox.Margin.Right + SystemInformation.HorizontalResizeBorderThickness + SystemInformation.HorizontalScrollBarThumbWidth + content.Length + 80; richTextBox.Width = dd; StringWriter myWriter = new StringWriter(); HttpUtility.HtmlDecode(content, myWriter); content = myWriter.ToString(); var Replacer = content.Replace("<br> <br>", "\r\n"); content = Replacer; richTextBox.Document.Blocks.Clear(); richTextBox.IsDocumentEnabled = true; Paragraph block = new Paragraph(); var para = new Paragraph { LineHeight = 1 }; var r = new Run(content); string emoticonText = GetEmoticonText(r.Text); para.Inlines.Add(r); if (!string.IsNullOrEmpty(emoticonText)) { while (!string.IsNullOrEmpty(emoticonText)) { TextPointer tp = r.ContentStart; while (!tp.GetTextInRun(LogicalDirection.Forward).StartsWith(emoticonText)) { tp = tp.GetNextInsertionPosition(LogicalDirection.Forward); } var tr = new TextRange(tp, tp.GetPositionAtOffset(emoticonText.Length)) { Text = string.Empty }; string path = _dict[emoticonText]; BitmapImage Emogi = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)); Image smiley = new Image(); smiley.Source = Emogi; smiley.Width = 19; smiley.Height = 19; new InlineUIContainer(smiley, tp); if (para != null) { var endRun = para.Inlines.LastInline as Run; if (endRun == null) { break; } else { emoticonText = GetEmoticonText(endRun.Text); } } } richTextBox.Document.Blocks.Add(para); } else { string sample = content; var f = sample.Split(new char[] { ' ' }); var para2 = new Paragraph(); Color Btn_Background_Color = (Color)ColorConverter.ConvertFromString("#3297ac"); foreach (var item in f) { if (item.StartsWith("http") || item.StartsWith("www.") || item.StartsWith("ftp:") || item.StartsWith("Smtp:")) { var link = new Hyperlink(); link.Inlines.Add(item); link.TargetName = "_blank"; link.TextDecorations = null; link.Foreground = new SolidColorBrush(Btn_Background_Color); link.NavigateUri = new Uri(item); para2.Inlines.Add(link); link.Click += OnUrlClick; } else if (item.StartsWith("#")) { var link = new Hyperlink(); item.TrimStart(new char[] { '#' }); link.Inlines.Add(item); link.TargetName = "_blank"; link.Foreground = new SolidColorBrush(Btn_Background_Color); link.TextDecorations = null;; string Hashtag = item.Replace("#", ""); link.NavigateUri = new Uri(WoWonderClient.Client.WebsiteUrl + "/hashtag/" + Hashtag); para2.Inlines.Add(link); link.Click += OnUrlClick; } else if (item.StartsWith("DownloadUrlFrom>>>")) { var link = new Hyperlink(); string Url = item.Replace("DownloadUrlFrom>>>", ""); link.Inlines.Add("Download"); link.TargetName = "_blank"; link.Foreground = new SolidColorBrush(Btn_Background_Color); link.TextDecorations = null; link.NavigateUri = new Uri(Url); para2.Inlines.Add(link); link.Click += OnUrlClick; } else { para2.Inlines.Add(item); } para2.Inlines.Add(" "); } richTextBox.Document.Blocks.Add(para2); } } catch { } }
/// <summary> /// Converts an ARGB hex colour code into a Color object. /// </summary> /// <param name="str">A hexadecimal colour code string (such as #AAFF00FF)</param> /// <returns>A colour object created from the colour code.</returns> private static Color ColourFromString(string str) { return((Color)ColorConverter.ConvertFromString(str)); }
private void ConfigurationButtons() { SolidColorBrush color = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Settings.Theme.ButtonBackgroundColor)) { Opacity = Settings.Theme.ButtonTransparency / 100.0 }; var buttonStyle = Resources["btnStyle"] as Style; buttonStyle?.Setters.Add(new Setter(ForegroundProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString(Settings.Theme.ButtonTextColor)))); buttonStyle?.Setters.Add(new Setter(FontFamilyProperty, new FontFamily(Settings.Theme.ButtonFontFamily))); buttonStyle?.Setters.Add(new Setter(BackgroundProperty, color)); foreach (var button in Grid_Buttons.Children.OfType <Button>()) { button.Content = Settings.Game.CategoriesList[Convert.ToInt32(button.Tag) - 1]; button.Style = buttonStyle; button.Click += Buttons_Click; button.MouseEnter += Buttons_MouseEnter; button.MouseLeave += Buttons_MouseLeave; } }
internal static void InsertNewGroup(PNGroup group) { try { var c = new ColorConverter(); var drcc = new System.Drawing.ColorConverter(); var wfc = new WPFFontConverter(); var lfc = new LogFontConverter(); var sb = new StringBuilder(); sb.Append("INSERT INTO GROUPS (GROUP_ID, PARENT_ID, GROUP_NAME, ICON, BACK_COLOR, CAPTION_FONT_COLOR, CAPTION_FONT, SKIN_NAME, PASSWORD_STRING, FONT, FONT_COLOR, IS_DEFAULT_IMAGE) VALUES("); sb.Append(group.ID); sb.Append(","); sb.Append(group.ParentID); sb.Append(",'"); sb.Append(group.Name.Replace("'", "''")); sb.Append("','"); if (!group.IsDefaultImage) { var base64String = Convert.ToBase64String(group.Image.ToBytes()); sb.Append(base64String); } else { sb.Append(group.ImageName); sb.Append(".png"); } //using (var ms = new MemoryStream(1)) //{ // group.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // ms.Position = 0; // string base64String = Convert.ToBase64String(ms.ToArray()); // sb.Append(base64String); //} sb.Append("','"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, group.Skinless.BackColor)); sb.Append("','"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, group.Skinless.CaptionColor)); sb.Append("','"); sb.Append(wfc.ConvertToString(group.Skinless.CaptionFont)); sb.Append("','"); sb.Append(group.Skin.SkinName); sb.Append("','"); sb.Append(group.PasswordString); sb.Append("','"); sb.Append(lfc.ConvertToString(group.Font)); sb.Append("','"); sb.Append(drcc.ConvertToString(null, PNStatic.CultureInvariant, group.FontColor)); sb.Append("', "); sb.Append(Convert.ToInt32(group.IsDefaultImage)); sb.Append("); "); if (ExecuteTransactionForStringBuilder(sb, ConnectionString)) { sb = new StringBuilder(); var id = HK_START; using (var oData = new SQLiteDataObject(ConnectionString)) { var o = oData.GetScalar("SELECT MAX(ID) FROM HOT_KEYS"); if (o != null && !DBNull.Value.Equals(o)) { id = (int)(long)o + 1; } } var prefix = group.ID + "_show"; sb.Append("INSERT INTO HOT_KEYS (HK_TYPE, MENU_NAME, ID, SHORTCUT) VALUES("); sb.Append(((int)HotkeyType.Group).ToString(PNStatic.CultureInvariant)); sb.Append(",'"); sb.Append(prefix); sb.Append("',"); sb.Append(id.ToString(PNStatic.CultureInvariant)); sb.Append(",'');"); if (ExecuteTransactionForStringBuilder(sb, ConnectionString)) { PNStatic.HotKeysGroups.Add(new PNHotKey { MenuName = prefix, ID = id, Type = HotkeyType.Group }); } sb = new StringBuilder(); id++; prefix = group.ID + "_hide"; sb.Append("INSERT INTO HOT_KEYS (HK_TYPE, MENU_NAME, ID, SHORTCUT) VALUES("); sb.Append(((int)HotkeyType.Group).ToString(PNStatic.CultureInvariant)); sb.Append(",'"); sb.Append(prefix); sb.Append("',"); sb.Append(id.ToString(PNStatic.CultureInvariant)); sb.Append(",'');"); if (ExecuteTransactionForStringBuilder(sb, ConnectionString)) { PNStatic.HotKeysGroups.Add(new PNHotKey { MenuName = prefix, ID = id, Type = HotkeyType.Group }); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static void SaveNoteSkinless(PNote note) { try { var cr = new ColorConverter(); var lfc = new WPFFontConverter(); var sb = new StringBuilder(); using (var oData = new SQLiteDataObject(PNData.ConnectionString)) { if (isNotePresentedInCustomSettings(note)) { sb.Append("UPDATE CUSTOM_NOTES_SETTINGS SET BACK_COLOR = "); if (note.Skinless != null) { sb.Append("'"); sb.Append(cr.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.BackColor)); sb.Append("'"); } else { sb.Append("NULL"); } sb.Append(", CAPTION_FONT_COLOR = "); if (note.Skinless != null) { sb.Append("'"); sb.Append(cr.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.CaptionColor)); sb.Append("'"); } else { sb.Append("NULL"); } sb.Append(", CAPTION_FONT = "); if (note.Skinless != null) { sb.Append("'"); sb.Append(lfc.ConvertToString(note.Skinless.CaptionFont)); sb.Append("'"); } else { sb.Append("NULL"); } sb.Append(" WHERE NOTE_ID = '"); sb.Append(note.ID); sb.Append("'"); } else { sb.Append("INSERT INTO CUSTOM_NOTES_SETTINGS (NOTE_ID, BACK_COLOR, CAPTION_FONT_COLOR, CAPTION_FONT) VALUES("); if (note.Skinless != null) { sb.Append("'"); sb.Append(note.ID); sb.Append("', '"); sb.Append(cr.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.BackColor)); sb.Append("', '"); sb.Append(cr.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.CaptionColor)); sb.Append("', '"); sb.Append(lfc.ConvertToString(note.Skinless.CaptionFont)); sb.Append("')"); } else { sb.Append("'"); sb.Append(note.ID); sb.Append("', NULL, NULL, NULL)"); } } oData.Execute(sb.ToString()); } } catch (Exception ex) { PNStatic.LogException(ex); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string color = (string)value; try { TypeConverter colorConverter = new ColorConverter(); Color c = (Color)colorConverter.ConvertFromString(color); return new SolidColorBrush(c); } catch { return Brushes.White; } }
/// <summary> /// Converts a hexidecimal string to a WPF Color object. /// </summary> /// <param name="hex"></param> /// <returns></returns> public static Color ToColor(this string hex) { ColorConverter converter = new ColorConverter(); return (Color)converter.ConvertFrom(hex); }
private Color MakeColorFromHex(object sender) { try { ColorConverter cc = new ColorConverter(); return (Color)cc.ConvertFrom(((TextBox)sender).Text); } catch { string alphaHex = CustomColor.A.ToString("X").PadLeft(2, '0'); string redHex = CustomColor.R.ToString("X").PadLeft(2, '0'); string greenHex = CustomColor.G.ToString("X").PadLeft(2, '0'); string blueHex = CustomColor.B.ToString("X").PadLeft(2, '0'); txtAll.Text = String.Format("#{0}{1}{2}{3}", alphaHex, redHex, greenHex, blueHex); } return _customColor; }
internal static void InsertDefaultGroup(int id, int parentID, string name, BitmapImage image, ImageFormat imageFormat) { try { var c = new ColorConverter(); var wpfFontConverter = new WPFFontConverter(); var sb = new StringBuilder(); sb.Append("INSERT INTO GROUPS (GROUP_ID, PARENT_ID, GROUP_NAME, ICON, BACK_COLOR, CAPTION_FONT_COLOR, CAPTION_FONT, SKIN_NAME, PASSWORD_STRING, IS_DEFAULT_IMAGE) VALUES("); sb.Append(id); sb.Append(","); sb.Append(parentID); sb.Append(",'"); sb.Append(name.Replace("'", "''")); sb.Append("','"); var base64String = Convert.ToBase64String(image.ToBytes()); sb.Append(base64String); //using (var ms = new MemoryStream(1)) //{ // image.Save(ms, imageFormat); // ms.Position = 0; // string base64String = Convert.ToBase64String(ms.ToArray()); // sb.Append(base64String); //} sb.Append("','"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, PNSkinlessDetails.DefColor)); sb.Append("','"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, SystemColors.ControlTextColor)); sb.Append("','"); var f = new PNFont { FontWeight = FontWeights.Bold }; sb.Append(wpfFontConverter.ConvertToString(f)); sb.Append("','"); sb.Append(PNSkinDetails.NO_SKIN); sb.Append("','',1"); sb.Append("); "); ExecuteTransactionForStringBuilder(sb, ConnectionString); } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static void SaveCPProperties() { try { var crc = new ColorConverter(); var sb = new StringBuilder(); var sc = new SizeConverter(); var pc = new PointConverter(); var pcf = PNStatic.Settings.Config; sb.Append("UPDATE CONFIG SET CP_LAST_GROUP = "); sb.Append(pcf.CPLastGroup); sb.Append(",CP_PVW_COLOR = '"); sb.Append(crc.ConvertToString(null, PNStatic.CultureInvariant, pcf.CPPvwColor)); sb.Append("',CP_USE_CUST_PVW_COLOR = "); sb.Append(Convert.ToInt32(pcf.CPUseCustPvwColor)); sb.Append(",CP_SIZE = '"); sb.Append(sc.ConvertToString(null, PNStatic.CultureInvariant, pcf.CPSize)); sb.Append("',CP_LOCATION = '"); sb.Append(pc.ConvertToString(null, PNStatic.CultureInvariant, pcf.CPLocation)); sb.Append("',CP_PVW_RIGHT = "); sb.Append(Convert.ToInt32(pcf.CPPvwRight)); sb.Append(",CP_PVW_SHOW = "); sb.Append(Convert.ToInt32(pcf.CPPvwShow)); sb.Append(",CP_GROUPS_SHOW = "); sb.Append(Convert.ToInt32(pcf.CPGroupsShow)); ExecuteTransactionForStringBuilder(sb, SettingsConnectionString); } catch (Exception ex) { PNStatic.LogException(ex); } }
/// <summary> /// PopulateDropDown /// </summary> private void PopulateDropDown(ComboBox comboBox) { try { Type t = typeof(System.Windows.Media.Colors); comboBox.Items.Clear(); foreach (PropertyInfo p1 in t.GetProperties()) { System.Windows.Media.ColorConverter d = new System.Windows.Media.ColorConverter(); try { ComboBoxItem item = new ComboBoxItem(); SolidColorBrush brush = new SolidColorBrush((System.Windows.Media.Color)d.ConvertFromInvariantString(p1.Name)); item.Background = brush; item.Content = p1.Name; if (brush.Color == Colors.Black || brush.Color == Colors.White) comboBox.Items.Add(item); } catch { // Catch exceptions here } } comboBox.SelectedIndex = 0; } catch (Exception ex) { throw ex; } }
public static string[] GetColorNames() { Type colorsType = typeof (Colors); PropertyInfo[] colorsProperties = colorsType.GetProperties(); var convertor = new ColorConverter(); var colorNames = new List<String>(); foreach (PropertyInfo colorProperty in colorsProperties) { string colorName = colorProperty.Name; colorNames.Add(colorName); var color = (Color) ColorConverter.ConvertFromString(colorName); } //String[] colorNamesArray = new(string[colorNames.Count]; return colorNames.ToArray(); }
/// <summary> /// Creates a highlight annotation with the specified color and author /// </summary> /// <param name="service">the AnnotationService</param> /// <param name="textRange">highlight anchor</param> /// <param name="author">highlight author</param> /// <param name="color">highlight brush</param> /// <returns>created annotation</returns> private static Annotation CreateHighlight(AnnotationService service, ITextRange textRange, string author, Nullable<Color> color) { Invariant.Assert(textRange != null, "textRange is null"); Annotation annotation = CreateAnnotationForSelection(service, textRange, HighlightComponent.TypeName, author); // Set the cargo with highlight color if (color != null) { ColorConverter converter = new ColorConverter(); XmlDocument doc = new XmlDocument(); XmlElement colorsElement = doc.CreateElement(HighlightComponent.ColorsContentName, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); colorsElement.SetAttribute(HighlightComponent.BackgroundAttributeName, converter.ConvertToInvariantString(color.Value)); AnnotationResource cargo = new AnnotationResource(HighlightComponent.HighlightResourceName); cargo.Contents.Add(colorsElement); annotation.Cargos.Add(cargo); } return annotation; }
internal static void LoadNoteCustomProperties(PNote note, DataRow r) { try { if (!PNData.IsDBNull(r["BACK_COLOR"]) || !PNData.IsDBNull(r["CAPTION_FONT_COLOR"]) || !PNData.IsDBNull(r["CAPTION_FONT"])) { var drawingColorConverter = new System.Drawing.ColorConverter(); var wfc = new WPFFontConverter(); var mediaColorConverter = new ColorConverter(); note.Skinless = new PNSkinlessDetails(); if (!PNData.IsDBNull(r["BACK_COLOR"])) { try { var clr = mediaColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["BACK_COLOR"]); if (clr != null) { note.Skinless.BackColor = (Color)clr; } } catch (FormatException) { //possible FormatException after synchronization with old database var clr = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["BACK_COLOR"]); if (clr != null) { var drawingColor = (System.Drawing.Color)clr; note.Skinless.BackColor = Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET BACK_COLOR = '"); sb.Append(mediaColorConverter.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.BackColor)); sb.Append("' WHERE NOTE_ID = '"); sb.Append(r["NOTE_ID"]); sb.Append("'"); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } } } if (!PNData.IsDBNull(r["CAPTION_FONT_COLOR"])) { try { var clr = mediaColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["CAPTION_FONT_COLOR"]); if (clr != null) { note.Skinless.CaptionColor = (Color)clr; } } catch (FormatException) { //possible FormatException after synchronization with old database var clr = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["CAPTION_FONT_COLOR"]); if (clr != null) { var drawingColor = (System.Drawing.Color)clr; note.Skinless.CaptionColor = Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET CAPTION_FONT_COLOR = '"); sb.Append(mediaColorConverter.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.CaptionColor)); sb.Append("' WHERE NOTE_ID = '"); sb.Append(r["NOTE_ID"]); sb.Append("'"); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } } } if (!PNData.IsDBNull(r["CAPTION_FONT"])) { var fontString = (string)r["CAPTION_FONT"]; //try //{ var fonts = new InstalledFontCollection(); var arr = fontString.Split(','); if (fontString.Any(ch => ch == '^')) { //old format font string var lfc = new PNStaticFonts.LogFontConverter(); var lf = lfc.ConvertFromString((string)r["CAPTION_FONT"]); note.Skinless.CaptionFont = PNStatic.FromLogFont(lf); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET CAPTION_FONT = '"); sb.Append(wfc.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.CaptionFont)); sb.Append("' WHERE NOTE_ID = '"); sb.Append(r["NOTE_ID"]); sb.Append("'"); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } else if (fonts.Families.Any(ff => ff.Name == arr[0])) { note.Skinless.CaptionFont = (PNFont)wfc.ConvertFromString((string)r["CAPTION_FONT"]); } else { //possible note existing font name arr[0] = PNStrings.DEF_CAPTION_FONT; fontString = string.Join(",", arr); note.Skinless.CaptionFont = (PNFont)wfc.ConvertFromString(fontString); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET CAPTION_FONT = '"); sb.Append(fontString); sb.Append("' WHERE NOTE_ID = '"); sb.Append(r["NOTE_ID"]); sb.Append("'"); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } //} //catch (IndexOutOfRangeException) //{ // //possible IndexOutOfRangeException after synchronization with old database // var lfc = new PNStaticFonts.LogFontConverter(); // var lf = lfc.ConvertFromString((string)r["CAPTION_FONT"]); // note.Skinless.CaptionFont = PNStatic.FromLogFont(lf); // var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET CAPTION_FONT = '"); // sb.Append(wfc.ConvertToString(null, PNStatic.CultureInvariant, note.Skinless.CaptionFont)); // sb.Append("' WHERE NOTE_ID = '"); // sb.Append(r["NOTE_ID"]); // sb.Append("'"); // PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); //} } } if (!PNData.IsDBNull(r["SKIN_NAME"])) { note.Skin = new PNSkinDetails { SkinName = (string)r["SKIN_NAME"] }; var path = Path.Combine(PNPaths.Instance.SkinsDir, note.Skin.SkinName); path += ".pnskn"; if (File.Exists(path)) { PNSkinsOperations.LoadSkin(path, note.Skin); } } if (!PNData.IsDBNull(r["CUSTOM_OPACITY"])) { note.CustomOpacity = (bool)r["CUSTOM_OPACITY"]; } } catch (Exception ex) { PNStatic.LogException(ex); } }
// Initialize known object types internal static TypeConverter CreateKnownTypeConverter(Int16 converterId) { TypeConverter o = null; switch (converterId) { case -42: o = new System.Windows.Media.Converters.BoolIListConverter(); break; case -46: o = new System.ComponentModel.BooleanConverter(); break; case -53: o = new System.Windows.Media.BrushConverter(); break; case -61: o = new System.ComponentModel.ByteConverter(); break; case -70: o = new System.ComponentModel.CharConverter(); break; case -71: o = new System.Windows.Media.Converters.CharIListConverter(); break; case -87: o = new System.Windows.Media.ColorConverter(); break; case -94: o = new System.Windows.Input.CommandConverter(); break; case -96: o = new System.Windows.Markup.ComponentResourceKeyConverter(); break; case -111: o = new System.Windows.CornerRadiusConverter(); break; case -114: o = new System.ComponentModel.CultureInfoConverter(); break; case -115: o = new System.Windows.CultureInfoIetfLanguageTagConverter(); break; case -117: o = new System.Windows.Input.CursorConverter(); break; case -124: o = new System.ComponentModel.DateTimeConverter(); break; case -125: o = new System.Windows.Markup.DateTimeConverter2(); break; case -130: o = new System.ComponentModel.DecimalConverter(); break; case -137: o = new System.Windows.Markup.DependencyPropertyConverter(); break; case -138: o = new System.Windows.DialogResultConverter(); break; case -174: o = new System.Windows.Media.DoubleCollectionConverter(); break; case -175: o = new System.ComponentModel.DoubleConverter(); break; case -176: o = new System.Windows.Media.Converters.DoubleIListConverter(); break; case -188: o = new System.Windows.DurationConverter(); break; case -190: o = new System.Windows.DynamicResourceExtensionConverter(); break; case -201: o = new System.Windows.ExpressionConverter(); break; case -204: o = new System.Windows.FigureLengthConverter(); break; case -215: o = new System.Windows.Media.FontFamilyConverter(); break; case -216: o = new System.Windows.FontSizeConverter(); break; case -218: o = new System.Windows.FontStretchConverter(); break; case -220: o = new System.Windows.FontStyleConverter(); break; case -222: o = new System.Windows.FontWeightConverter(); break; case -240: o = new System.Windows.Media.GeometryConverter(); break; case -256: o = new System.Windows.GridLengthConverter(); break; case -267: o = new System.ComponentModel.GuidConverter(); break; case -286: o = new System.Windows.Media.ImageSourceConverter(); break; case -299: o = new System.Windows.Input.InputScopeConverter(); break; case -301: o = new System.Windows.Input.InputScopeNameConverter(); break; case -306: o = new System.ComponentModel.Int16Converter(); break; case -314: o = new System.Windows.Media.Int32CollectionConverter(); break; case -315: o = new System.ComponentModel.Int32Converter(); break; case -319: o = new System.Windows.Int32RectConverter(); break; case -324: o = new System.ComponentModel.Int64Converter(); break; case -338: o = new System.Windows.Input.KeyConverter(); break; case -340: o = new System.Windows.Input.KeyGestureConverter(); break; case -342: o = new System.Windows.KeySplineConverter(); break; case -344: o = new System.Windows.KeyTimeConverter(); break; case -348: o = new System.Windows.LengthConverter(); break; case -387: o = new System.Windows.Media.Media3D.Matrix3DConverter(); break; case -392: o = new System.Windows.Media.MatrixConverter(); break; case -410: o = new System.Windows.Input.ModifierKeysConverter(); break; case -411: o = new System.Windows.Input.MouseActionConverter(); break; case -415: o = new System.Windows.Input.MouseGestureConverter(); break; case -423: o = new System.Windows.NullableBoolConverter(); break; case -445: o = new System.Windows.Media.PathFigureCollectionConverter(); break; case -453: o = new System.Windows.Media.PixelFormatConverter(); break; case -462: o = new System.Windows.Media.Media3D.Point3DCollectionConverter(); break; case -463: o = new System.Windows.Media.Media3D.Point3DConverter(); break; case -467: o = new System.Windows.Media.Media3D.Point4DConverter(); break; case -473: o = new System.Windows.Media.PointCollectionConverter(); break; case -474: o = new System.Windows.PointConverter(); break; case -475: o = new System.Windows.Media.Converters.PointIListConverter(); break; case -492: o = new System.Windows.PropertyPathConverter(); break; case -498: o = new System.Windows.Media.Media3D.QuaternionConverter(); break; case -507: o = new System.Windows.Media.Media3D.Rect3DConverter(); break; case -511: o = new System.Windows.RectConverter(); break; case -521: o = new System.Windows.Media.Animation.RepeatBehaviorConverter(); break; case -538: o = new System.Windows.Markup.RoutedEventConverter(); break; case -545: o = new System.ComponentModel.SByteConverter(); break; case -563: o = new System.ComponentModel.SingleConverter(); break; case -568: o = new System.Windows.Media.Media3D.Size3DConverter(); break; case -572: o = new System.Windows.SizeConverter(); break; case -615: o = new System.ComponentModel.StringConverter(); break; case -619: o = new System.Windows.StrokeCollectionConverter(); break; case -633: o = new System.Windows.TemplateBindingExpressionConverter(); break; case -635: o = new System.Windows.TemplateBindingExtensionConverter(); break; case -637: o = new System.Windows.Markup.TemplateKeyConverter(); break; case -645: o = new System.Windows.TextDecorationCollectionConverter(); break; case -655: o = new System.Windows.ThicknessConverter(); break; case -664: o = new System.ComponentModel.TimeSpanConverter(); break; case -681: o = new System.Windows.Media.TransformConverter(); break; case -692: o = new System.Windows.Markup.TypeTypeConverter(); break; case -696: o = new System.ComponentModel.UInt16Converter(); break; case -698: o = new System.ComponentModel.UInt32Converter(); break; case -700: o = new System.ComponentModel.UInt64Converter(); break; case -701: o = new System.Windows.Media.Converters.UShortIListConverter(); break; case -705: o = new System.UriTypeConverter(); break; case -714: o = new System.Windows.Media.Media3D.Vector3DCollectionConverter(); break; case -715: o = new System.Windows.Media.Media3D.Vector3DConverter(); break; case -722: o = new System.Windows.Media.VectorCollectionConverter(); break; case -723: o = new System.Windows.VectorConverter(); break; case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break; } return o; }
/// <summary> /// Creates the bitmap data for the models in the character category /// </summary> /// <remarks> /// Because the original textures use channel packing, this method gets the pixel data of each texture /// and then recombines them to create the unpacked textures to use in the 3D model. /// <see cref="http://wiki.polycount.com/wiki/ChannelPacking"/> /// </remarks> /// <param name="normalTexData">The texture data of the normal map</param> /// <param name="diffuseTexData">The texture data of the diffuse map</param> /// <param name="maskTexData">The texture data of the mask map</param> /// <param name="specularTexData">The texture data of the normal map</param> /// <returns>An array of bitmaps to be used on the model</returns> public static BitmapSource[] MakeCharacterMaps(TEXData normalTexData, TEXData diffuseTexData, TEXData maskTexData, TEXData specularTexData, string itemName, string path) { int height = normalTexData.Height; int width = normalTexData.Width; int tSize = height * width; var normalBitmap = normalTexData.BMPSouceAlpha; Color charaColor; if (path.Contains("/body/b")) { charaColor = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Skin_Color); } else if (path.Contains("/hair/h")) { charaColor = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Hair_Color); } else if (path.Contains("/face/f")) { if (path.Contains("_etc_")) { charaColor = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Etc_Color); } else if (path.Contains("_iri_")) { charaColor = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Iris_Color); } else { charaColor = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Skin_Color); } } else if (path.Contains("tail/t")) { if (!path.Contains("c1401") && !path.Contains("c1301")) { charaColor = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Hair_Color); } else { charaColor = Color.FromArgb(255, 255, 255, 255); } } else { charaColor = Color.FromArgb(255, 96, 57, 19); } if (diffuseTexData != null && (diffuseTexData.Height * diffuseTexData.Width) > tSize) { height = diffuseTexData.Height; width = diffuseTexData.Width; tSize = height * width; } if (maskTexData != null && (maskTexData.Height * maskTexData.Width) > tSize) { height = maskTexData.Height; width = maskTexData.Width; tSize = height * width; } if (specularTexData != null && (specularTexData.Height * specularTexData.Width) > tSize) { height = specularTexData.Height; width = specularTexData.Width; tSize = height * width; } byte[] maskPixels = null; byte[] specularPixels = null; byte[] normalPixels = null; byte[] diffusePixels = null; BitmapSource[] texBitmaps = new BitmapSource[4]; if (maskTexData != null) { if (tSize > (maskTexData.Height * maskTexData.Width)) { var resized = CreateResizedImage(maskTexData.BMPSouceAlpha, width, height); maskPixels = GetBytesFromBitmapSource((BitmapSource)resized); } else { maskPixels = GetBytesFromBitmapSource(maskTexData.BMPSouceAlpha); } } if (diffuseTexData != null) { try { if (tSize > (diffuseTexData.Height * diffuseTexData.Width)) { var resized = CreateResizedImage(diffuseTexData.BMPSouceAlpha, width, height); diffusePixels = GetBytesFromBitmapSource((BitmapSource)resized); } else { diffusePixels = GetBytesFromBitmapSource(diffuseTexData.BMPSouceAlpha); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } if (specularTexData != null) { try { if (tSize > (specularTexData.Height * specularTexData.Width)) { var resized = CreateResizedImage(specularTexData.BMPSouceAlpha, width, height); specularPixels = GetBytesFromBitmapSource((BitmapSource)resized); } else { specularPixels = GetBytesFromBitmapSource(specularTexData.BMPSouceAlpha); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } if (normalTexData != null) { if (tSize > (normalTexData.Height * normalTexData.Width)) { var resized = CreateResizedImage(normalTexData.BMPSouceAlpha, width, height); normalBitmap = (BitmapSource)resized; normalPixels = GetBytesFromBitmapSource((BitmapSource)resized); } else { normalPixels = GetBytesFromBitmapSource(normalTexData.BMPSouceAlpha); } } List <byte> diffuseMap = new List <byte>(); List <byte> specularMap = new List <byte>(); List <byte> alphaMap = new List <byte>(); BitmapSource bitmapSource; System.Drawing.Color diffuseColor; System.Drawing.Color specularColor; System.Drawing.Color alphaColor; int stride = (int)normalBitmap.Width * (32 / 8); var scale = 1; if (width >= 4096 || height >= 4096) { scale = 4; } else if (width >= 2048 || height >= 2048) { scale = 2; } var nWidth = width / scale; var nHeight = height / scale; if (diffuseTexData == null) { for (int i = 3; i < normalPixels.Length; i += 4) { int alpha = normalPixels[i]; diffuseColor = System.Drawing.Color.FromArgb(alpha, (int)((charaColor.R / 255f) * specularPixels[i - 1]), (int)((charaColor.G / 255f) * specularPixels[i - 1]), (int)((charaColor.B / 255f) * specularPixels[i - 1])); specularColor = System.Drawing.Color.FromArgb(255, (int)(specularPixels[i - 2] * 0.1), (int)(specularPixels[i - 2] * 0.1), (int)(specularPixels[i - 2] * 0.1)); alphaColor = System.Drawing.Color.FromArgb(255, alpha, alpha, alpha); diffuseMap.AddRange(BitConverter.GetBytes(diffuseColor.ToArgb())); specularMap.AddRange(BitConverter.GetBytes(specularColor.ToArgb())); alphaMap.AddRange(BitConverter.GetBytes(alphaColor.ToArgb())); } bitmapSource = BitmapSource.Create(width, height, normalBitmap.DpiX, normalBitmap.DpiY, PixelFormats.Bgra32, null, diffuseMap.ToArray(), stride); texBitmaps[0] = (BitmapSource)CreateResizedImage(bitmapSource, nWidth, nHeight); } else { for (int i = 3; i < normalPixels.Length; i += 4) { int alpha = normalPixels[i - 3]; diffuseColor = System.Drawing.Color.FromArgb(alpha, (int)((charaColor.R / 255f) * diffusePixels[i - 1]), (int)((charaColor.G / 255f) * diffusePixels[i - 2]), (int)((charaColor.B / 255f) * diffusePixels[i - 3])); diffuseMap.AddRange(BitConverter.GetBytes(diffuseColor.ToArgb())); specularColor = System.Drawing.Color.FromArgb(255, (int)(specularPixels[i - 2] * 0.1), (int)(specularPixels[i - 2] * 0.1), (int)(specularPixels[i - 2] * 0.1)); specularMap.AddRange(BitConverter.GetBytes(specularColor.ToArgb())); alphaColor = System.Drawing.Color.FromArgb(255, alpha, alpha, alpha); alphaMap.AddRange(BitConverter.GetBytes(alphaColor.ToArgb())); } bitmapSource = BitmapSource.Create(width, height, normalBitmap.DpiX, normalBitmap.DpiY, PixelFormats.Bgra32, null, diffuseMap.ToArray(), stride); texBitmaps[0] = (BitmapSource)CreateResizedImage(bitmapSource, nWidth, nHeight); } bitmapSource = BitmapSource.Create(width, height, normalBitmap.DpiX, normalBitmap.DpiY, PixelFormats.Bgra32, null, specularMap.ToArray(), stride); texBitmaps[1] = (BitmapSource)CreateResizedImage(bitmapSource, nWidth, nHeight); texBitmaps[2] = (BitmapSource)CreateResizedImage(normalTexData.BMPSouceNoAlpha, nWidth, nHeight); bitmapSource = BitmapSource.Create(width, height, normalBitmap.DpiX, normalBitmap.DpiY, PixelFormats.Bgra32, null, alphaMap.ToArray(), stride); texBitmaps[3] = (BitmapSource)CreateResizedImage(bitmapSource, nWidth, nHeight); foreach (var tb in texBitmaps) { tb.Freeze(); } return(texBitmaps); }