private void HandleXPAL(Chunk chunk, byte[] buffer) { BinReader reader = chunk.GetReader(); reader.Position = 8; if (chunk.Size == 2316) // 2 * 768 words + 3 * 256 bytes + header { ushort unknown = reader.ReadU16LE(); ushort unknown2 = reader.ReadU16LE(); reader.Read(transitionBuffer, 0, 768 * 2); for (int i = 0; i < 768 * 2; i += 2) { transitionPalette[i >> 1] = (ushort)(transitionBuffer[i] | (transitionBuffer[i + 1] << 8)); } ReadPalette(reader); } else if (chunk.Size == 14) { // Three unknown words here int transitionIndex = 0; for (int i = 0; i < 256; i++) { byte r = GetTransitionColor(currentPalette[i].R, transitionPalette[transitionIndex++]); byte g = GetTransitionColor(currentPalette[i].G, transitionPalette[transitionIndex++]); byte b = GetTransitionColor(currentPalette[i].B, transitionPalette[transitionIndex++]); currentPalette[i] = new PaletteColor(r, g, b); } } }
public override bool Equals(object obj) { PaletteColor other = (PaletteColor)obj; return(palette.getId() == other.palette.getId() && color.Equals(other.color)); }
// Use this for initialization void Start() { if (ColorFromParent) { Color = GetComponentInParent <CharacterColor>().Color; } //get tunic Transform torso = transform.FindChild("Body"); if (torso != null) { meshRenderer = torso.GetComponent <SkinnedMeshRenderer>(); for (int i = 0; i < meshRenderer.materials.Length; i++) { if (meshRenderer.materials[i].name.Contains("Tunic")) { tunicMat = meshRenderer.materials[i]; tunicIndex = i; } } if (tunicMat == null) { Debug.LogError("Could not find tunic material!"); } tunicColor = Palette.GetColor(Color); if (tunicMat.color != tunicColor) { tunicMat.color = tunicColor; } } }
private PaletteColor FindClosestColor() { var colors = ColorPaletteManager.GetPaletteColors(); PaletteColor closestColor = null; float closestDistance = 1000; foreach (var color in colors) { if (closestColor == null) { closestColor = color; continue; } float distance = Mathf.Sqrt(Mathf.Pow(color.r - currentRed, 2) + Mathf.Pow(color.g - currentGreen, 2) + Mathf.Pow(color.b - currentBlue, 2)); if (distance <= closestDistance) { closestColor = color; closestDistance = distance; } } return(closestColor); }
public PaletteColor AddColor(int parentId, string description) { var c = new PaletteColor(); var cnt = (from u in ColorList where u.Pid == parentId select u.Pid).Count(); if (cnt != 0) { c.Color = (from u in ColorList where u.Pid == parentId select u.Color).First(); } else { c.Color = (Color)_colorArr.GetValue(_curInd); _curInd++; if (_curInd >= _colorArr.Length) { _curInd = 0; } ColorList.Add(new PaletteColor { Pid = parentId, Color = c.Color, Label = description }); } return c; }
private void SetPointEvents( ColorPinpoint e ) { var drag = false; PaletteColor selected = null; Point? prev = null; e.MouseLeftButtonDown += (s, ev) => { drag = true; prev = null; SelectColor(s as ColorPinpoint); selected = Palette.Colors[(int)(s as FrameworkElement).Tag]; e.CaptureMouse(); }; e.MouseLeftButtonUp += (s, ev) => { drag = false; e.ReleaseMouseCapture(); }; e.MouseMove += (s, ev) => { if (drag) { double width = brisat.Width; double height = brisat.Height; double diam = (s as ColorPinpoint).ActualWidth; Point p = ev.GetPosition(canvasBriSat); AHSB hsb = selected.Color; hsb.Saturation = p.X / width; hsb.Brightness = 1 - p.Y / height; if (prev != null) { selected.Color = hsb; double x = (hsb.Saturation * width) - diam / 2; double y = (height - (hsb.Brightness * height)) - diam / 2; (s as FrameworkElement).SetValue(Canvas.LeftProperty, x); (s as FrameworkElement).SetValue(Canvas.TopProperty, y); DrawPointers(); if (ColorsUpdated != null) { ColorsUpdated(this, EventArgs.Empty); } } prev = p; } }; }
/// <summary> /// Create a new palette with default color data. /// </summary> /// <param name="use6BitRGBColor">If set to true, use 6 bits per color channel instead of the usual 8 bits.</param> public PaletteFile(bool use6BitRGBColor) { Is6BitRGBPalette = use6BitRGBColor; PaletteColor defaultcolor = new PaletteColor(); colors = Enumerable.Repeat(defaultcolor, 256).ToArray(); Initialized = true; }
private void PaletteColor_MouseEnter(object sender, EventArgs e) { PaletteColor item = sender as PaletteColor; int index = (int)item.Tag; lblColorIndex.Text = "Index: " + (index + 1); lblColorRGB.Text = "Farbe: " + string.Format("{0}, {1}, {2}", mPal[index].R, mPal[index].G, mPal[index].B); }
private void SetPointEvents( ColorPinpoint e ) { var drag = false; PaletteColor selected = null; Point? prev = null; Point shift = new Point(); e.MouseLeftButtonDown += (s, ev) => { drag = true; prev = null; shift = ev.GetPosition(s as FrameworkElement); SelectColor(s as ColorPinpoint); selected = Palette.Colors[(int)(s as FrameworkElement).Tag]; e.CaptureMouse(); }; e.MouseLeftButtonUp += (s, ev) => { drag = false; e.ReleaseMouseCapture(); }; e.MouseMove += (s, ev) => { if (drag) { double width = spectrum.Width; double height = spectrum.Height; double diam = (s as ColorPinpoint).ActualWidth; Point p = ev.GetPosition(canvasSpectrum); p.X = p.X - shift.X + diam / 2; p.Y = p.Y - shift.Y + diam / 2; AHSL hsl = selected.DoubleColor.ToAHSL(); double x = Math.Min(Math.Max(p.X, 0), width); double y = Math.Min(Math.Max(p.Y, 0), height); hsl.Luminance = 1 - (y / height); hsl.HueDegree = 360 * (x / width); hsl.Saturation = Saturation; if (prev != null) { selected.DoubleColor = hsl.Double(); if (ColorsUpdated != null) { ColorsUpdated(this, EventArgs.Empty); } } prev = p; } }; }
public MappedPixel(char c, int indexCh, PaletteColor color, int index) { Char = c; IndexCh = indexCh; ColorF = color.ColorF; ColorB = color.ColorB; IndexF = color.IndexF; IndexB = color.IndexB; Index = index; }
/// <summary> /// Gets a concatenated string of the individual color component values for a palette color. /// </summary> /// <param name="color">Palette color.</param> /// <param name="useAlpha">If true, alpha value is included in the concatenated string.</param> /// <returns>Concatenated string of the individual color component values of given palette color.</returns> private string GetColorString(PaletteColor color, bool useAlpha = true) { string alpha = ""; if (useAlpha && color.Alpha >= 0) { alpha = " " + color.Alpha; } return(color.Red + " " + color.Green + " " + color.Blue + alpha); }
IEnumerator WinDelay() { yield return(new WaitForSeconds(WinConfirmationDelay)); //set win text Text uiText = GameObject.Find("Canvas/WinText").GetComponent <Text>(); string winText = "Tie!"; //get VO player GameObject voObj = GameObject.FindGameObjectWithTag("NarrationPlayer"); int playerCount = playersContainer.transform.childCount; if (playerCount == 1 && !singlePlayerMode) { Transform winner = playersContainer.transform.GetChild(0); PaletteColor c = winner.GetComponentInChildren <CharacterColor>().Color; string hexColor = Palette.GetHex(c); winText = "<color='#" + hexColor + "'>" + winner.name + "</color> wins!"; //increment winner's score int playerNum = winner.GetComponent <PlayerInfo>().PlayerNum; gPlayerInfo.IncrementPlayerScore(playerNum); //play win VO if (voObj != null) { voObj.GetComponent <VOWinAnnoucement>().PlayWinner(playerNum); } } else { //increment winners' scores for (int i = 0; i < playerCount; i++) { Transform player = playersContainer.transform.GetChild(i); gPlayerInfo.IncrementPlayerScore(player.GetComponent <PlayerInfo>().PlayerNum); } //play tie VO if (voObj != null) { voObj.GetComponent <VOWinAnnoucement>().PlayTie(); } } uiText.text = winText; yield return(new WaitForSeconds(NextSceneDelay)); GetComponent <NextScene>().GoToScene(); }
/// <summary> /// Creates tables from a color in a palette, including the /// various string-based forms. /// </summary> /// <param name="pc">The color.</param> /// <returns>The HTML tables.</returns> public static string GenerateTable(PaletteColor pc) { // TODO: This could also use ToString in a general manner return(String.Format("<h1>{0}</h1>{1}", pc.Name, String.Format(table, pc.Color.ToRgb().ToHtml(), pc.Color.ToRgb().ToHslString(), pc.Color.ToRgb().ToHsv().ToCssString() ) )); }
/// <summary> /// Changes the associated metadata of a color. /// </summary> /// <param name="pc">The color.</param> /// <param name="newText">The new metadata of the color.</param> /// <param name="keepHistory">If undo should have been added.</param> /// <param name="fireEvent">If the event should fire.</param> /// <param name="action">If the undo is added, the action it is described as.</param> public void ChangeMetadata(PaletteColor pc, string newText, bool keepHistory = true, bool fireEvent = true, string action = null) { if (Palette.Colors.Contains(pc)) { ChangeMetadata(Palette.Colors.IndexOf(pc), newText, keepHistory, fireEvent, action); } else { throw new ArgumentException("The colour is not in the palette."); } }
private void InitializePalette() { for( int i = 0; i < mPal.Length; i++ ) { PaletteColor item = new PaletteColor( mPal[ i ] ); int x = ( ( pnlColors.Controls.Count % 16 ) * item.Width ) + ( ( pnlColors.Controls.Count % 16 ) * 3 ); int y = ( ( pnlColors.Controls.Count / 16 ) * item.Height ) + ( ( pnlColors.Controls.Count / 16 ) * 3 ); item.Location = new Point( x, y ); item.Tag = i; item.Click += new EventHandler( PaletteColor_Click ); item.MouseEnter += new EventHandler( PaletteColor_MouseEnter ); pnlColors.Controls.Add( item ); } }
private void PaletteColor_MouseClick(object sender, MouseEventArgs e) { var item = sender as PaletteColor; if (item == null) { return; } var index = (int)item.Tag; // first click on color if (mSelectedPaletteColor != item.Color) { mSelectedPaletteColor = item.Color; mWndSprite.SelectedColor = mSprite.Palette[index]; if (mOldPaletteColor != null && mOldPaletteColor.Selected) { mOldPaletteColor.Selected = false; } mOldPaletteColor = item; item.Selected = true; if (e.Button != MouseButtons.Right) { return; } } // second click, deselect if (e.Button == MouseButtons.Left) { mWndSprite.SelectedColor = mSelectedPaletteColor = Color.Transparent; item.Selected = false; return; } // only right = change color if (e.Button == MouseButtons.Right) { using (var dlg = new ColorDialog()) { if (dlg.ShowDialog(this) != DialogResult.OK || item.Color == dlg.Color) { return; } item.Color = dlg.Color; mSprite.Palette[index] = dlg.Color; mSprite.ResetImages(); SetImage(mSelectedImage); // set again to force redraw } } }
protected Palette ReadPalette(BinReader reader) { reader.Read(buffer, 0, 768); Palette pal = new Palette(256); int bufferPos = 0; for (int i = 0; i < 256; i++) { pal[i] = new PaletteColor(buffer[bufferPos], buffer[bufferPos + 1], buffer[bufferPos + 2]); bufferPos += 3; } return(pal); }
/// <summary> /// Adds a color to the palette. /// </summary> /// <param name="pc">The color to append.</param> /// <param name="keepHistory">If undo should have been added.</param> /// <param name="fireEvent">If the event should fire.</param> /// <param name="action">If the undo is added, the action it is described as.</param> public void AppendColor(PaletteColor pc, bool keepHistory = true, bool fireEvent = true, string action = null) { if (keepHistory) { PushUndo(action ?? "Add Colour"); // TODO: should we announce the colour we're acting on? same for other funcs } Palette = Palette.Clone(); Palette.Colors.Add(pc); Dirty = true; if (fireEvent) { OnPaletteChanged(new EventArgs()); } }
private static int GetColorSaturation(PaletteColor color) { int cMax = Math.Max(Math.Max(color.R, color.G), color.B); if (cMax == 0) { return(0); } int cMin = Math.Min(Math.Min(color.R, color.G), color.B); int delta = cMax - cMin; return((delta << 8) / cMax); }
/// <summary> /// Deletes a color from the palette. /// </summary> /// <param name="pc">The color to remove.</param> /// <param name="keepHistory">If undo should have been added.</param> /// <param name="fireEvent">If the event should fire.</param> /// <param name="action">If the undo is added, the action it is described as.</param> public void DeleteColor(PaletteColor pc, bool keepHistory = true, bool fireEvent = true, string action = null) { if (keepHistory) { PushUndo(action ?? "Delete Colour"); } Palette = Palette.Clone(); Palette.Colors.Remove(pc); Dirty = true; if (fireEvent) { OnPaletteChanged(new EventArgs()); } }
public void UpdateDefaults() { var newDefaults = PaletteColor.GetDefaults(DefaultStyles.defaultStrings, true); foreach (PaletteColor p in defaults) { var newP = newDefaults.Find(x => x.colorType == p.colorType); if (newP != null) { newP.color = p.color; } } defaults = newDefaults; }
public Palette(int pc = 0) { int palColumns = PALETTE_COLUMNS = pc; Colors = new PaletteColor[palColumns][]; for (int i = 0; i < palColumns; i++) { Colors[i] = new PaletteColor[COLORS_PER_COLUMN]; for (int j = 0; j < COLORS_PER_COLUMN; ++j) { Colors[i][j] = new PaletteColor(); } } }
public static bool GetPaletteColor(Color c, out PaletteColor color) { for (int i = 0; i < Colors.Length; i++) { if (Colors[i] == c) { color = (PaletteColor)i; return(true); } } color = PaletteColor.InvalidColor; return(false); }
private void InitializePalette() { for (int i = 0; i < mPal.Length; i++) { PaletteColor item = new PaletteColor(mPal[i]); int x = ((pnlColors.Controls.Count % 16) * item.Width) + ((pnlColors.Controls.Count % 16) * 3); int y = ((pnlColors.Controls.Count / 16) * item.Height) + ((pnlColors.Controls.Count / 16) * 3); item.Location = new Point(x, y); item.Tag = i; item.Click += new EventHandler(PaletteColor_Click); item.MouseEnter += new EventHandler(PaletteColor_MouseEnter); pnlColors.Controls.Add(item); } }
private Color[] ShadeColor(PaletteColor color) { var shadedColors = new Color[width]; for (var i = 0; i < color.shadeCount; i++) { shadedColors[i] = Color.Lerp(color.colorFrom, color.colorTo, (float)i / (color.shadeCount - 1)); } for (var i = color.shadeCount; i < width; i++) { shadedColors[i] = Color.clear; } return(shadedColors); }
public Palette(Reader reader) { ushort columns_bitmap = reader.ReadUInt16(); for (int i = 0; i < PALETTE_COLUMNS; ++i) { if ((columns_bitmap & (1 << i)) != 0) { Colors[i] = new PaletteColor[COLORS_PER_COLUMN]; for (int j = 0; j < COLORS_PER_COLUMN; ++j) { Colors[i][j] = new PaletteColor(reader); } } } }
private void ReadPalette(BinReader reader) { reader.Read(paletteBuffer, 0, 768); // 3 * 256 as usual int i = 0; int paletteIndex = 0; while (i < 768) { byte r = paletteBuffer[i++]; byte g = paletteBuffer[i++]; byte b = paletteBuffer[i++]; PaletteColor color = new PaletteColor(r, g, b); currentPalette[paletteIndex++] = color; } }
private void setWinText(PlayerScore[] winners) { string winText = "Tie!"; if (winners.Length == 1) { PaletteColor c = winners[0].GetComponent <CharacterColor>().Color; string hexColor = Palette.GetHex(c); winText = "<color='#" + hexColor + "'>" + winners[0].name + "</color> wins!"; } Text uiText = GameObject.Find("Canvas/WinText").GetComponent <Text>(); uiText.text = winText; }
/// <summary> /// Saves the palette as a generic 256-color palette to a file. /// </summary> /// <param name="filename">Filename to save to. If not set, current filename is used.</param> /// <returns>True if saved successfully, false otherwise.</returns> public bool SaveGenericPalette(string filename = null) { if (string.IsNullOrEmpty(filename) || !Initialized) { return(false); } FileStream fs = null; try { fs = new FileStream(filename, FileMode.Create); for (int i = 0; i < ColorCount; i++) { PaletteColor c = colors[i]; if (c == null) { return(false); } if (Is6BitRGBPalette) { fs.WriteByte((byte)(c.Red / 4)); fs.WriteByte((byte)(c.Green / 4)); fs.WriteByte((byte)(c.Blue / 4)); } else { fs.WriteByte(c.Red); fs.WriteByte(c.Green); fs.WriteByte(c.Blue); } } } catch (Exception) { return(false); } finally { if (fs != null) { fs.Close(); } } return(true); }
private void PaletteColor_Click(object sender, EventArgs e) { PaletteColor item = sender as PaletteColor; int index = (int)item.Tag; using (ColorDialog dlg = new ColorDialog()) { if (dlg.ShowDialog(this) != DialogResult.OK || item.Color == dlg.Color) { return; } item.Color = dlg.Color; if (OnColorChanged != null) { OnColorChanged(new PaletteColorChangedEventArgs(index, dlg.Color)); } } }
private Color?GetColor() { PaletteColor pc = _styleManager.ActivePalette.customs.Find(x => x.colorType != "" && x.colorType == customUIType); if (pc == null) { string type = DefaultStyles.defaultStrings[selected]; pc = _styleManager.ActivePalette.defaults.Find(x => x.colorType == type); if (pc == null) { return(null); } } return(pc.color); }
/// <summary> /// Load a generic 256-color palette from file. /// </summary> private void LoadGenericPalette() { FileStream fs = null; try { fs = new FileStream(Filename, FileMode.Open); if (fs.Length != 768) { return; } byte[] values = new byte[768]; fs.Read(values, 0, values.Length); int j = 0; colors = new PaletteColor[256]; for (int i = 0; i < ColorCount; i++) { if (Is6BitRGBPalette) { colors[i] = new PaletteColor((byte)(values[j++] * 4), (byte)(values[j++] * 4), (byte)(values[j++] * 4)); } else { colors[i] = new PaletteColor(values[j++], values[j++], values[j++]); } } } catch (Exception) { return; } finally { if (fs != null) { fs.Close(); } } Initialized = true; }
private void PaletteColor_MouseClick(object sender, MouseEventArgs e) { var item = sender as PaletteColor; if (item == null) { return; } var index = (int)item.Tag; // first click on color if (mSelectedPaletteColor != item.Color) { mSelectedPaletteColor = item.Color; mWndSprite.SelectedColor = mSprite.Palette[index]; if (mOldPaletteColor != null && mOldPaletteColor.Selected) mOldPaletteColor.Selected = false; mOldPaletteColor = item; item.Selected = true; if (e.Button != MouseButtons.Right) return; } // second click, deselect if (e.Button == MouseButtons.Left) { mWndSprite.SelectedColor = mSelectedPaletteColor = Color.Transparent; item.Selected = false; return; } // only right = change color if (e.Button == MouseButtons.Right) { using (var dlg = new ColorDialog()) { if (dlg.ShowDialog(this) != DialogResult.OK || item.Color == dlg.Color) return; item.Color = dlg.Color; mSprite.Palette[index] = dlg.Color; mSprite.ResetImages(); SetImage(mSelectedImage); // set again to force redraw } } }
/// <summary> /// Draws at the specified position using Far palette colors (in the internal buffer). /// </summary> /// <include file='doc.xml' path='doc/LT/*'/> /// <param name="paletteColor">Palette color.</param> /// <param name="text">Text.</param> /// <remarks> /// When all drawing operations are done call the <see cref="Draw"/>. /// </remarks> public abstract void DrawPalette(int left, int top, PaletteColor paletteColor, string text);
/// <summary> /// Returns background color of Far palette. /// </summary> /// <param name="paletteColor">Palette color.</param> public abstract ConsoleColor GetPaletteBackground(PaletteColor paletteColor);
/// <summary> /// Returns foreground color of Far palette. /// </summary> /// <param name="paletteColor">Palette color.</param> public abstract ConsoleColor GetPaletteForeground(PaletteColor paletteColor);
private void InitializePalette() { mWndPalette.SuspendLayout(); mWndPalette.Controls["pnlPalette"].Controls.Clear(); mSelectedPaletteColor = Color.Transparent; for (int i = 0; i < mSprite.Palette.Count; i++) { var item = new PaletteColor(mSprite.Palette[i]); // 5 padding from border, 3 per item var x = 5 + ((mWndPalette.Controls["pnlPalette"].Controls.Count % 16) * item.Width) + ((mWndPalette.Controls["pnlPalette"].Controls.Count % 16) * 3); var y = 5 + ((mWndPalette.Controls["pnlPalette"].Controls.Count / 16) * item.Height) + ((mWndPalette.Controls["pnlPalette"].Controls.Count / 16) * 3); item.Location = new Point(x, y); item.Tag = i; item.MouseClick += new MouseEventHandler(PaletteColor_MouseClick); item.ColorHovered += new EventHandler(PaletteColor_ColorHovered); mWndPalette.Controls["pnlPalette"].Controls.Add(item); } mWndPalette.ResumeLayout(false); mWndPalette.PerformLayout(); }