protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Return) { this.ShowColorDialog(); e.Handled = true; } else if (e.KeyCode == Keys.C && e.Control) { DataObject data = new DataObject(); data.SetIColorData(new[] { this.value ?? (IColorData)ColorRgba.TransparentBlack }); Clipboard.SetDataObject(data); e.Handled = true; } else if (e.KeyCode == Keys.V && e.Control) { DataObject data = Clipboard.GetDataObject() as DataObject; IColorData[] colorData; if (data.TryGetIColorData(out colorData)) { this.value = colorData.FirstOrDefault(); this.PerformSetValue(); this.PerformGetValue(); this.OnEditingFinished(FinishReason.LeapValue); } else { System.Media.SystemSounds.Beep.Play(); } e.Handled = true; } base.OnKeyDown(e); }
public unsafe IColorData[] GetClutColors(byte clut) { if (!CLP || _texture.NumOfCluts == 0) { return(null); } if (clut >= _texture.NumOfCluts) { throw new Exception($"Desired palette is incorrect use -1 for default or use a smaller number: {clut} > {_texture.NumOfCluts}"); } var k = 0; var colors = new IColorData[_texture.NumOfColors]; fixed(byte *pd = _texture.PaletteData) { var rpd = (ColorBGRA8888 *)pd; for (var i = clut * _texture.NumOfColors; i < _texture.PaletteData.Length && k < colors.Length; i++) { colors[k++] = rpd[i]; } } return(colors); }
internal ColorData(IColorData colorData) { ColorDepth = colorData.ColorDepth; DynamicRange = colorData.DynamicRange; ColorFormat = colorData.ColorFormat; Colorimetry = colorData.Colorimetry; SelectionPolicy = colorData.SelectionPolicy; DesktopColorDepth = colorData.DesktopColorDepth; }
private void pickingOperation_OperationEnded(object sender, EventArgs e) { if (this.pickingOperation.IsCanceled) { this.value = this.valueBeforePicking; this.PerformSetValue(); this.PerformGetValue(); } this.pickingOperation.PickedColorChanged -= this.pickingOperation_PickedColorChanged; this.pickingOperation.OperationEnded -= this.pickingOperation_OperationEnded; }
public void ShowColorDialog() { this.dialog.OldColor = (this.value ?? ColorRgba.TransparentBlack).ToSysDrawColor(); this.dialog.SelectedColor = this.dialog.OldColor; DialogResult result = this.dialog.ShowDialog(this.ParentGrid); this.value = (result == DialogResult.OK) ? this.dialog.SelectedColor.ToDualityRgba() : this.dialog.OldColor.ToDualityRgba(); this.PerformSetValue(); this.PerformGetValue(); this.OnEditingFinished(result == DialogResult.OK ? FinishReason.UserAccept : FinishReason.LostFocus); }
private void ShowColorDialog() { this.dialog.OldColor = (this.value ?? ColorRgba.TransparentBlack).ToSysDrawColor(); this.dialog.SelectedColor = this.dialog.OldColor; DialogResult result = this.dialog.ShowDialog(this.ParentGrid); this.value = (result == DialogResult.OK) ? this.dialog.SelectedColor.ToDualityRgba() : this.dialog.OldColor.ToDualityRgba(); this.PerformSetValue(); this.PerformGetValue(); this.OnEditingFinished(result == DialogResult.OK ? FinishReason.UserAccept : FinishReason.LostFocus); }
private void StartColorPick() { this.valueBeforePicking = this.value; if (this.pickingOperation == null) { this.pickingOperation = new GlobalColorPickOperation(); } this.pickingOperation.PickedColorChanged += this.pickingOperation_PickedColorChanged; this.pickingOperation.OperationEnded += this.pickingOperation_OperationEnded; this.pickingOperation.Start(); }
protected override void OnDragDrop(DragEventArgs e) { base.OnDragDrop(e); DataObject data = e.Data as DataObject; if (data.ContainsIColorData()) { this.value = data.GetIColorData<IColorData>().FirstOrDefault(); this.PerformSetValue(); this.PerformGetValue(); this.OnEditingFinished(FinishReason.LeapValue); e.Effect = e.AllowedEffect; } }
protected override void OnDragDrop(DragEventArgs e) { base.OnDragDrop(e); DataObject data = e.Data as DataObject; if (data.ContainsIColorData()) { this.value = data.GetIColorData <IColorData>().FirstOrDefault(); this.PerformSetValue(); this.PerformGetValue(); this.OnEditingFinished(FinishReason.LeapValue); e.Effect = e.AllowedEffect; } }
public static T[] GetIColorData <T>(this IDataObject data) where T : IColorData { IColorData[] clrArray = null; if (data.GetWrappedDataPresent(typeof(IColorData[]))) { clrArray = data.GetWrappedData(typeof(IColorData[])) as IColorData[]; } else if (data.ContainsString()) { string valString = data.GetString(); string[] token = valString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); byte[] valToken = new byte[4]; valToken[3] = 255; bool success = true; for (int i = 0; i < token.Length; i++) { token[i] = token[i].Trim(); if (!byte.TryParse(token[i], out valToken[i])) { success = false; break; } } if (success) { clrArray = new IColorData[] { new ColorRgba(valToken[0], valToken[1], valToken[2], valToken[3]) } } ; } if (clrArray != null) { // Don't care which format? Great, just return the array as is if (typeof(T) == typeof(IColorData)) { return((T[])(object)clrArray); } // Convert to specific format return(clrArray.Select <IColorData, T>(ic => ic is T ? (T)ic : ic.ConvertTo <T>()).ToArray()); } else { return(null); } }
public static IEnumerable<LayerViewModel> PaintLayers(List<LayerViewModel> layers, IColorData parentColorData = null,LayerViewModel parent = null,int depth = 0) { var toPaintDistinct = new List<LayerViewModel>(); var toPaintSameColor = new List<LayerViewModel>(); if (parentColorData == null) parentColorData = _pallette.GetStartingColorData(); IColorData sameColor; if (parent != null && parent.Invisible) { //Parent is invisible, paint all layers with the parent color toPaintSameColor = layers; sameColor = parentColorData; } else { sameColor = _pallette.GetSubColor(parentColorData); if (depth == 0 && layers.Sum(x => x.Descendants) < 5) { toPaintDistinct = layers; } else { //TODO: Maybe not require children if the tree is shorter than 3? toPaintDistinct = layers.Where(l => l.Children.Any() && !l.Invisible).ToList(); toPaintSameColor = layers.Where(l => !l.Children.Any() || l.Invisible).ToList(); } } var distinctColors = new Stack<IColorData>(); if (toPaintDistinct.Count > 1) distinctColors = _pallette.GetDistinctColors(parentColorData,toPaintDistinct.Count); if(toPaintDistinct.Count == 1) distinctColors = new Stack<IColorData>(_pallette.GetDistinctColors(parentColorData,2).Take(1)); foreach (var layer in toPaintSameColor) { PaintLayer(layer, sameColor); } foreach (var layer in toPaintDistinct) { var colorData = distinctColors.Pop(); PaintLayer(layer, colorData); } return layers; }
/// <summary> /// Converts the color to a different color data format. If there is also a /// specific method doing the desired conversion, use that instead - it might be faster. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> public static T ConvertTo <T>(this IColorData source) where T : IColorData { T clr = default(T); if (clr == null) { if (typeof(T) == typeof(IColorData)) { return((T)source); } else { clr = (T)typeof(T).GetTypeInfo().CreateInstanceOf(); } } clr.SetIntArgb(source.ToIntArgb()); return(clr); }
protected override void OnGetValue() { base.OnGetValue(); IColorData[] values = this.GetValue().Cast<IColorData>().ToArray(); this.BeginUpdate(); int oldValue = this.value != null ? this.value.ToIntRgba() : -1; if (!values.Any()) { this.value = ColorRgba.TransparentBlack; } else { this.value = (IColorData)values.NotNull().FirstOrDefault(); // No visual appearance of "multiple values" yet - need one? } this.EndUpdate(); if (oldValue != (this.value != null ? this.value.ToIntRgba() : -1)) this.Invalidate(); }
/// <summary> /// Converts the color to a different color data format. If there is also a /// specific method doing the desired conversion, use that instead - it might be faster. /// </summary> /// <param name="source"></param> /// <param name="type"></param> /// <returns></returns> public static IColorData ConvertTo(this IColorData source, Type type) { if (!typeof(IColorData).IsAssignableFrom(type)) { throw new ArgumentException("Target type must implement IColorData.", "type"); } if (type == typeof(IColorData)) { return(source); } IColorData clr = type.GetDefaultInstanceOf() as IColorData; if (clr == null) { clr = type.CreateInstanceOf(true) as IColorData; } clr.SetIntArgb(source.ToIntArgb()); return(clr); }
/// <summary> /// Get clut color palette /// </summary> /// <param name="br">Binary reader pointing to memory stream of data.</param> /// <param name="clut">Active clut data</param> /// <returns>Color[]</returns> protected IColorData[] GetClutColors(BinaryReader br, ushort clut) { if (clut >= Texture.NumOfCluts) { throw new Exception($"TIM_v2::GetClutColors::given clut {clut} is >= texture number of cluts {Texture.NumOfCluts}"); } if (!CLP) { throw new Exception($"TIM that has {BPP} bpp mode and has no clut data!"); } var colorPixels = new IColorData[Texture.NumOfColors]; br.BaseStream.Seek(TIMOffset + 20 + (Texture.NumOfColors * 2 * clut), SeekOrigin.Begin); for (var i = 0; i < Texture.NumOfColors; i++) { colorPixels[i] = new ColorABGR1555(br.ReadUInt16(), IgnoreAlpha); } return(colorPixels); }
protected override void OnGetValue() { base.OnGetValue(); IColorData[] values = this.GetValue().Cast <IColorData>().ToArray(); this.BeginUpdate(); int oldValue = this.value != null?this.value.ToIntRgba() : -1; if (!values.Any()) { this.value = ColorRgba.TransparentBlack; } else { this.value = (IColorData)values.NotNull().FirstOrDefault(); // No visual appearance of "multiple values" yet - need one? } this.EndUpdate(); if (oldValue != (this.value != null ? this.value.ToIntRgba() : -1)) { this.Invalidate(); } }
private void StartColorPick() { this.valueBeforePicking = this.value; if (this.pickingOperation == null) this.pickingOperation = new GlobalColorPickOperation(); this.pickingOperation.PickedColorChanged += this.pickingOperation_PickedColorChanged; this.pickingOperation.OperationEnded += this.pickingOperation_OperationEnded; this.pickingOperation.Start(); }
private void pickingOperation_PickedColorChanged(object sender, EventArgs e) { this.value = this.pickingOperation.PickedColor.ToDualityRgba(); this.PerformSetValue(); this.PerformGetValue(); }
private void dialog_ColorEdited(object sender, EventArgs e) { this.value = this.dialog.SelectedColor.ToDualityRgba(); this.PerformSetValue(); this.PerformGetValue(); }
protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Return) { this.ShowColorDialog(); e.Handled = true; } else if (e.KeyCode == Keys.C && e.Control) { DataObject data = new DataObject(); data.SetIColorData(new[] { this.value ?? (IColorData)ColorRgba.TransparentBlack }); Clipboard.SetDataObject(data); e.Handled = true; } else if (e.KeyCode == Keys.V && e.Control) { DataObject data = Clipboard.GetDataObject() as DataObject; if (data.ContainsIColorData()) { this.value = data.GetIColorData<IColorData>().FirstOrDefault(); this.PerformSetValue(); this.PerformGetValue(); this.OnEditingFinished(FinishReason.LeapValue); } else System.Media.SystemSounds.Beep.Play(); e.Handled = true; } base.OnKeyDown(e); }
public SqlMaterialData(CalzadosLunghiDbContext db, IColorData colorData) { _db = db; _colorData = colorData; }
public IColorData Add(IColorData other) => new ColorABGR1555( Clamp(R + other.R), Clamp(G + other.G), Clamp(B + other.B), Clamp(A + other.A));
public CreateModel(IMaterialData materialData, IColorData colorData) { _materialData = materialData; _colorData = colorData; }
public static IColorData Add(this IColorData value, IColorData other) { return(value.Add(other)); }
public static IColorData Multiply(this IColorData value, float scale) { return(value.Multiply(scale)); }
public static IColorData Subtract(this IColorData value, IColorData other) { return(value.Subtract(other)); }
public static Color GetColor(this IColorData other) { return((other == null) ?Color.TransparentBlack :new Color(other.R, other.G, other.B, other.A)); }
private static void PaintLayer(LayerViewModel layer, IColorData colorData,int depth = 0) { layer.Color = colorData.GetColor(); PaintLayers(layer.Children.OfType<LayerViewModel>().ToList(), colorData, layer,depth + 1); }
public EditModel(IColorData colorData) { _colorData = colorData; }
public DeleteModel(IColorData colorData) { _colorData = colorData; }
public IndexModel(IMaterialData materialData, IColorData colorData) { _materialData = materialData; _colorData = colorData; }
public bool Equals(IColorData other) => other != null && (R, G, B, A) == (other.R, other.G, other.B, other.A);