public static void ChangeTheme(Theme theme, bool forceTheme = false) { // don't change to the same theme if (theme == CurrentTheme && !forceTheme) { return; } //// clear all the resources var applicationResourceDictionary = Application.Current.Resources; if (theme == Theme.Default) { theme = AppInfo.RequestedTheme == AppTheme.Dark ? Theme.Dark : Theme.Light; } #pragma warning disable IDE0007 // Use implicit type ResourceDictionary newTheme = theme switch #pragma warning restore IDE0007 // Use implicit type { Theme.Light => new LightTheme(), Theme.Dark => new DarkTheme(), _ => new LightTheme(), }; ManuallyCopyThemes(newTheme, applicationResourceDictionary); CurrentTheme = theme; var background = (Color)App.Current.Resources["PrimaryDarkColor"]; var environment = DependencyService.Get <IEnvironment>(); environment?.SetStatusBarColor(ColorConverters.FromHex(background.ToHex()), false); }
public SneakersViewModel() { sneakers = new ObservableCollection <Sneakers> { new Sneakers { Name = "NMD_R1 candy", Price = "162", Picture = "Sneakers1" }, new Sneakers { Name = "NMD_R1 pink white", Price = "142", Picture = "Sneakers2" }, new Sneakers { Name = "NMD_R1 mint pink", Price = "179", Picture = "Sneakers3" }, new Sneakers { Name = "NMD_R1 white mint", Price = "154", Picture = "Sneakers4" } }; sneakerColor = new ObservableCollection <SneakerColor> { //new SneakerColor { ColorOption = "#819e94" }, //new SneakerColor { ColorOption = "#dde5ed" }, //new SneakerColor { ColorOption = "#d6c2bf" } new SneakerColor { ColorOption = ColorConverters.FromHex("#819e94") }, new SneakerColor { ColorOption = ColorConverters.FromHex("#dde5ed") }, new SneakerColor { ColorOption = ColorConverters.FromHex("#d6c2bf") } }; }
/// <summary> /// Resets the controls color (both HSL and RGB variables) based on the current slider position /// </summary> private void ResetHSLRGB() { switch (m_eDrawStyle) { case eDrawStyle.Hue: m_hsl.H = 1.0 - (double)m_iMarker_Start_Y / (this.Height - 9); m_rgb = ColorConverters.HSL_to_RGB(m_hsl); break; case eDrawStyle.Saturation: m_hsl.S = 1.0 - (double)m_iMarker_Start_Y / (this.Height - 9); m_rgb = ColorConverters.HSL_to_RGB(m_hsl); break; case eDrawStyle.Brightness: m_hsl.L = 1.0 - (double)m_iMarker_Start_Y / (this.Height - 9); m_rgb = ColorConverters.HSL_to_RGB(m_hsl); break; case eDrawStyle.Red: m_rgb = Color.FromArgb(255 - Round(255 * (double)m_iMarker_Start_Y / (this.Height - 9)), m_rgb.G, m_rgb.B); m_hsl = ColorConverters.RGB_to_HSL(m_rgb); break; case eDrawStyle.Green: m_rgb = Color.FromArgb(m_rgb.R, 255 - Round(255 * (double)m_iMarker_Start_Y / (this.Height - 9)), m_rgb.B); m_hsl = ColorConverters.RGB_to_HSL(m_rgb); break; case eDrawStyle.Blue: m_rgb = Color.FromArgb(m_rgb.R, m_rgb.G, 255 - Round(255 * (double)m_iMarker_Start_Y / (this.Height - 9))); m_hsl = ColorConverters.RGB_to_HSL(m_rgb); break; } }
private void Copy(object sender, RoutedEventArgs e) { Button button = (Button)sender; ColorItem colorItem = ViewModel.SelectedItem; string textToCopy = ""; switch (button.Name) { case "buttonCopyHex": textToCopy = ColorConverters.ColorToHex(colorItem.Color); break; case "buttonCopyRGB": textToCopy = ColorConverters.ColorToRGB(colorItem.Color); break; case "buttonCopyHSL": textToCopy = ColorConverters.ColorToHSL(colorItem.Color); break; } DataPackage dataPackage = new DataPackage(); dataPackage.SetText(textToCopy); dataPackage.RequestedOperation = DataPackageOperation.Copy; Clipboard.SetContent(dataPackage); }
/// <summary> /// Method to add or remove a character to/from the party list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnCharacter_Clicked(object sender, EventArgs args) { List <Tuple <string, bool> > is_added = new List <Tuple <string, bool> >(); //Create charactermodel from the character selected var button = sender as ImageButton; String characterId = button.CommandParameter as String; CharacterModel data = ViewModel.Dataset.FirstOrDefault(itm => itm.Id == characterId); if (data == null) { return; } if (selectedCharacters.Contains(data)) { BattleEngineViewModel.Instance.PartyCharacterList.Remove(data); selectedCharacters.Remove(data); button.BackgroundColor = Color.Transparent; } //the selected characters list does not contain the character and max not reached else if (BattleEngineViewModel.Instance.PartyCharacterList.Count() < BattleEngineViewModel.Instance.Engine.EngineSettings.MaxNumberPartyCharacters) { //Add character to the instance partcharacterlist BattleEngineViewModel.Instance.PartyCharacterList.Add(data); selectedCharacters.Add(data); button.BackgroundColor = (Color)ColorConverters.FromHex("25a46d"); } UpdateNextButtonState(); }
private void OnLoaded(object sender, RoutedEventArgs e) { ViewModel.ColorWheelBrush = new ColorWheel().CreateWheelImage(ViewModel.ColorWheelSize / 2, IsColorTemperature); ViewModel.OutsideColorWheelBrush = new ColorWheel().CreateOutsideWheelImage(ViewModel.OutsideColorWheelSize / 2, ViewModel.ColorWheelSize / 2, IsColorTemperature); if (IsColorTemperature) { ViewModel.TemperatureSliderBrush = new ColorWheel().CreateTemperatureImage(ViewModel.SlidersHeight); } ViewModel.MovingPicker = true; if (IsColorTemperature) { ViewModel.ColorTemperature = ColorTemperature; } else { ViewModel.Hue = Math.Round(ColorConverters.GetHue(Color)); ViewModel.Saturation = Math.Round(ColorConverters.GetSaturation(Color) * 100); } ViewModel.Color = Color; ViewModel.IsColorTemperature = IsColorTemperature; ViewModel.MovingPicker = false; ViewModel.MousePosition = new Thickness( ViewModel.ColorWheelSize * Math.Sin(ViewModel.Hue / 360 * Math.PI * 2) * (ViewModel.Saturation / 100), 0, 0, ViewModel.ColorWheelSize * Math.Cos(ViewModel.Hue / 360 * Math.PI * 2) * (ViewModel.Saturation / 100)); }
[InlineData("#0AF56C", "#F50A93")] // Lime green & bright purple (but with no limit values) public void GetComplementary(string original, string expected) { var orig = ColorConverters.FromHex(original); var expectedComplement = ColorConverters.FromHex(expected); Assert.Equal(expectedComplement, orig.GetComplementary()); }
public SneakersViewModel() { sneakers = new ObservableCollection <Sneakers> { new Sneakers { Name = "NMD_R1 candy", Price = "162", Picture = "https://images.unsplash.com/photo-1595950653106-6c9ebd614d3a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80" }, new Sneakers { Name = "NMD_R1 pink white", Price = "142", Picture = "https://images.unsplash.com/photo-1552346154-21d32810aba3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80" }, new Sneakers { Name = "NMD_R1 mint pink", Price = "179", Picture = "https://images.unsplash.com/photo-1525966222134-fcfa99b8ae77?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=643&q=80" }, new Sneakers { Name = "NMD_R1 white mint", Price = "154", Picture = "https://images.unsplash.com/photo-1521093470119-a3acdc43374a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80" } }; sneakerColor = new ObservableCollection <SneakerColor> { //new SneakerColor { ColorOption = "#819e94" }, //new SneakerColor { ColorOption = "#dde5ed" }, //new SneakerColor { ColorOption = "#d6c2bf" } new SneakerColor { ColorOption = ColorConverters.FromHex("#819e94") }, new SneakerColor { ColorOption = ColorConverters.FromHex("#dde5ed") }, new SneakerColor { ColorOption = ColorConverters.FromHex("#d6c2bf") } }; }
/// <summary> /// Returns the RGB color from a specific position of the color temperature scale. /// </summary> /// <param name="y">The vertical position from up to bottom.</param> /// <param name="height">Total height of the scale.</param> /// <returns></returns> public Color PickTemperaturePixelColor(int y, int height) { if (y <= 6 || height - y <= 6) { return(Colors.Transparent); } return(ColorConverters.ColorTemperatue((int)Math.Round((1 - (double)y / height) * 4500 + 2000))); }
public void FromHsl() { var color = ColorConverters.FromHsl(h, s, l); Assert.Equal(255, color.A); Assert.Equal(r, color.R); Assert.Equal(g, color.G); Assert.Equal(b, color.B); }
public void FromUint() { var color = ColorConverters.FromUInt(4294933007); Assert.Equal(255, color.A); Assert.Equal(255, color.R); Assert.Equal(122, color.G); Assert.Equal(15, color.B); }
public void FromHex(string hex, int a, int r, int g, int b) { var color = ColorConverters.FromHex(hex); Assert.Equal(a, color.A); Assert.Equal(r, color.R); Assert.Equal(g, color.G); Assert.Equal(b, color.B); }
public MainPage() { InitializeComponent(); BarBackgroundColor = ColorConverters.FromHex("#ed8756"); BarTextColor = Color.White; SelectedTabColor = Color.White; UnselectedTabColor = Color.Gray; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(ColorConverters.FromHex("ff000000")); } return(ColorConverters.FromHex(value.ToString())); }
/// <summary> /// Returns the RGB color from a specific position of the HUE scale. /// </summary> /// <param name="y">The vertical position from up to bottom.</param> /// <param name="height">Total height of the scale.</param> /// <param name="sat">Current saturation of the hue scale.</param> /// <returns></returns> public Color PickHuePixelColor(int y, int height, double sat) { if (y <= 6 || height - y <= 6) { return(Colors.Transparent); } return(ColorConverters.HueSaturation(2 * Math.PI - ((double)y - 6) / (height - 12) * (2 * Math.PI), sat / 100)); }
public void ColorConvertTest() { Color a = Color.FromArgb(200, 102, 32); string hex = ColorConverters.ColorToHexStr(a); string rgb = ColorConverters.ColorToRGBStr(a); string cmyk = ColorConverters.ColorToCMYKStr(a); Assert.IsNotNull(rgb); }
private string GetColorAsRGB() { System.Drawing.Color hexColor = ColorConverters.FromHex(this.Color.ToHex()); return(String.Format ("rgb({0},{1},{2})", hexColor.R.ToString(), hexColor.G.ToString(), hexColor.B.ToString())); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var colors = System.Convert.ToString(parameter).Split('|'); if ((bool)value) { return(ColorConverters.FromHex(colors[0])); } return(ColorConverters.FromHex(colors[1])); }
/// <summary> /// Returns the RGB color from a specific position of the saturation scale. /// </summary> /// <param name="y">The vertical position from up to bottom.</param> /// <param name="height">Total height of the scale.</param> /// <param name="hue">Current HUE of the saturation scale.</param> /// <returns></returns> public Color PickSaturationPixelColor(int y, int height, double hue) { if (y <= 6 || height - y <= 6) { return(Colors.Transparent); } return(ColorConverters.HueSaturation(hue == 360 ? 0 : hue / 360 * (2 * Math.PI), 1 - ((double)y - 6) / (height - 12))); }
public void FromHsla() { var a = 186; var color = ColorConverters.FromHsla(h, s, l, 186); Assert.Equal(a, color.A); Assert.Equal(r, color.R); Assert.Equal(g, color.G); Assert.Equal(b, color.B); }
public TravelHomeViewModel() { obsanio = new ObservableCollection <int>(); for (int i = 1; i <= 29; i++) { obsanio.Add(i); } travelSchedule = new ObservableCollection <TravelSchedule> { new TravelSchedule { Time = "08:00 AM", Picture = "Place1", Name = "Walking Tour", Adress1 = "191 Sutter St.", Adress2 = "CA 91929", TransportType = "Car", TransportColor = ColorConverters.FromHex("#31bea6") }, new TravelSchedule { Time = "10:00 AM", Picture = "Place2", Name = "LightHouse", Adress1 = "192 Sutter St.", Adress2 = "CA 91929", TransportType = "Walking", TransportColor = ColorConverters.FromHex("#e0995e") }, new TravelSchedule { Time = "01:30 PM", Picture = "Place3", Name = "Beach Tour", Adress1 = "194 Sutter St.", Adress2 = "CA 91929", TransportType = "Motor", TransportColor = ColorConverters.FromHex("#76c2af") }, new TravelSchedule { Time = "04:30 PM", Picture = "Place4", Name = "Island", Adress1 = "200 Sutter St.", Adress2 = "CA 91929", TransportType = "Walking", TransportColor = ColorConverters.FromHex("#e0995e") } }; }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.NewElement != null) { var view = (CustomEntry)Element; if (view.IsCurvedCornersEnabled) { // creating gradient drawable for the curved background var _gradientBackground = new GradientDrawable(); _gradientBackground.SetShape(ShapeType.Line); _gradientBackground.SetColor(view.BackgroundColor.ToAndroid()); //Control.SetPadding(0, 0, 0, 0); // Thickness of the stroke line //_gradientBackground.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid()); var blueHex = ColorConverters.FromHex("#D4D5D9"); Xamarin.Forms.Color xfColour = blueHex; Android.Graphics.Color greyColor = xfColour.ToAndroid(); _gradientBackground.SetStroke(view.BorderWidth, greyColor); // Radius for the curves //_gradientBackground.SetCornerRadius( // DpToPixels(this.Context, Convert.ToSingle(view.CornerRadius))); // set the background of the //Control.SetBackground(_gradientBackground); } // Set padding for the internal text from border //Control.SetPadding( // (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingTop, // (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingBottom); } if (Control == null || e.NewElement == null) { return; } if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { Control.BackgroundTintList = ColorStateList.ValueOf(Android.Graphics.Color.White); } else { Control.Background.SetColorFilter(Android.Graphics.Color.White, PorterDuff.Mode.SrcAtop); } //IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); //IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); //JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor); }
public void GetStateCodeTest() { Color a = Color.FromArgb(255, 102, 0); double[] rgba = ColorConverters.ColorToDouble(a); double[] xyz = ColorConverters.ColorToXYZ(a); double[] lab = ColorConverters.ColorToLab(a); Assert.IsNotNull(lab); // XYZ = 45.9914, 30.7627, 3.5138 // LAB = 62.3068, 55.0094, 71.3368 }
public void DoubleByteConvertTest() { double[] lab = new double[] { 62.3068, 55.0094, 71.3368 }; byte[] b = ByteUtil.DoublesToBytes(lab); double[] results = ByteUtil.BytesToDoubles(b); lab = ColorConverters.ColorToLab(Color.White); b = ByteUtil.DoublesToBytes(lab); results = ByteUtil.BytesToDoubles(b); lab = ColorConverters.ColorToLab(Color.Black); b = ByteUtil.DoublesToBytes(lab); results = ByteUtil.BytesToDoubles(b); Assert.IsTrue(results[0] == 62.3068); }
public void SetStatusBarColor(Color color) { // The SetStatusBarcolor is new since API 21 if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(color.ToAndroid()); var brightness = ColorConverters.FromHex(color.ToHex()).GetBrightness(); Change(brightness >= 0.7); } else { // Here you will just have to set your // color in styles.xml file as shown below. } }
// The following functions do the real work of the control, drawing the primary content (the area between the slider) // /// <summary> /// Fills in the content of the control showing all values of Hue (from 0 to 360) /// </summary> private void Draw_Style_Hue(Graphics g) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; ColorConverters.HSL _hsl = new ColorConverters.HSL(); _hsl.S = 1.0; // S and L will both be at 100% for this DrawStyle _hsl.L = 1.0; for (int i = 0; i < this.Height - 8; i++) // i represents the current line of pixels we want to draw horizontally { _hsl.H = 1.0 - (double)i / (this.Height - 8); // H (hue) is based on the current vertical position Pen pen = new Pen(ColorConverters.HSL_to_RGB(_hsl)); // Get the Color for this line g.DrawLine(pen, 11, i + 4, this.Width - 11, i + 4); // Draw the line and loop back for next line } }
/// <summary> /// Fills in the content of the control showing all values of Luminance (0 to 100%) for the given /// Hue and Saturation. /// </summary> private void Draw_Style_Luminance(Graphics g) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; ColorConverters.HSL _hsl = new ColorConverters.HSL(); _hsl.H = m_hsl.H; // Use the H and S values of the current color (m_hsl) _hsl.S = m_hsl.S; for (int i = 0; i < this.Height - 8; i++) // i represents the current line of pixels we want to draw horizontally { _hsl.L = 1.0 - (double)i / (this.Height - 8); // L (Luminance) is based on the current vertical position Pen pen = new Pen(ColorConverters.HSL_to_RGB(_hsl)); // Get the Color for this line g.DrawLine(pen, 11, i + 4, this.Width - 11, i + 4); // Draw the line and loop back for next line } }
public ZeroitAdobeVerticalColorSlider() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor, true); // Initialize Colors m_hsl = new ColorConverters.HSL(); m_hsl.H = 1.0; m_hsl.S = 1.0; m_hsl.L = 1.0; m_rgb = ColorConverters.HSL_to_RGB(m_hsl); m_eDrawStyle = eDrawStyle.Hue; Invalidate(); mouseLocation = new Point(MousePosition.X, MousePosition.Y); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { int num = (int)value; if (num == 1) { return((Color)ColorConverters.FromHex("#F7C234")); } else if (num == 2) { return((Color)ColorConverters.FromHex("#04AD6C")); } else { return(Color.Transparent); } }
/// <summary> /// Resets the controls color (both HSL and RGB variables) based on the current marker position /// </summary> private void ResetHSLRGB() { int red, green, blue; switch (m_eDrawStyle) { case eDrawStyle.Hue: m_hsl.S = (double)m_iMarker_X / (this.Width - 4); m_hsl.L = 1.0 - (double)m_iMarker_Y / (this.Height - 4); m_rgb = ColorConverters.HSL_to_RGB(m_hsl); break; case eDrawStyle.Saturation: m_hsl.H = (double)m_iMarker_X / (this.Width - 4); m_hsl.L = 1.0 - (double)m_iMarker_Y / (this.Height - 4); m_rgb = ColorConverters.HSL_to_RGB(m_hsl); break; case eDrawStyle.Brightness: m_hsl.H = (double)m_iMarker_X / (this.Width - 4); m_hsl.S = 1.0 - (double)m_iMarker_Y / (this.Height - 4); m_rgb = ColorConverters.HSL_to_RGB(m_hsl); break; case eDrawStyle.Red: blue = Round(255 * (double)m_iMarker_X / (this.Width - 4)); green = Round(255 * (1.0 - (double)m_iMarker_Y / (this.Height - 4))); m_rgb = Color.FromArgb(m_rgb.R, green, blue); m_hsl = ColorConverters.RGB_to_HSL(m_rgb); break; case eDrawStyle.Green: blue = Round(255 * (double)m_iMarker_X / (this.Width - 4)); red = Round(255 * (1.0 - (double)m_iMarker_Y / (this.Height - 4))); m_rgb = Color.FromArgb(red, m_rgb.G, blue); m_hsl = ColorConverters.RGB_to_HSL(m_rgb); break; case eDrawStyle.Blue: red = Round(255 * (double)m_iMarker_X / (this.Width - 4)); green = Round(255 * (1.0 - (double)m_iMarker_Y / (this.Height - 4))); m_rgb = Color.FromArgb(red, green, m_rgb.B); m_hsl = ColorConverters.RGB_to_HSL(m_rgb); break; } }