public void MakeSolid(ARGBPixel color) { _numEntries = 0; _flags |= CLR0EntryFlags.IsSolid; _solidColor = color; SignalPropertyChange(); }
protected override bool OnInitialize() { _flags = Header->Flags; _colorMask = (ARGBPixel)Header->_colorMask; _colors.Clear(); if ((_flags & CLR0EntryFlags.IsSolid) != 0) { _numEntries = 0; _solidColor = (ARGBPixel)Header->SolidColor; } else { _numEntries = ((CLR0Node)_parent)._numFrames + 1; ABGRPixel *data = Header->Data; for (int i = 0; i < _numEntries; i++) { _colors.Add((ARGBPixel)(*data++)); } } if ((_name == null) && (Header->_stringOffset != 0)) { _name = Header->ResourceString; } return(false); }
private void lstColors_DrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; Rectangle r = e.Bounds; int index = e.Index; g.FillRectangle(Brushes.White, r); if (index >= 0) { ARGBPixel p = (ARGBPixel)lstColors.Items[index]; if ((e.State & DrawItemState.Selected) != 0) { g.FillRectangle(Brushes.LightBlue, r.X, r.Y, 230, r.Height); } double n = Math.Floor(Math.Log10(_colorSource.ColorCount(_colorId)) + 1); g.DrawString(String.Format("[{0}] - {1}", index.ToString().PadLeft((int)n, ' '), p), _renderFont, Brushes.Black, 4.0f, e.Bounds.Y - 2); r.X += 250; r.Width = 40; using (Brush b = new SolidBrush((Color)p)) g.FillRectangle(b, r); g.DrawRectangle(Pens.Black, r); p.A = 255; r.X += 40; using (Brush b = new SolidBrush((Color)p)) g.FillRectangle(b, r); g.DrawRectangle(Pens.Black, r); } }
public void SetColor(int index, int id, ARGBPixel color) { if (Palette != null) { Palette.Entries[index] = (Color)color; SignalPropertyChange(); } }
public void Decode(ARGBPixel *block, int width) { uint * pixelData = stackalloc uint[4]; ARGBPixel *pixel = (ARGBPixel *)pixelData; pixel[0] = (ARGBPixel)_root0; pixel[1] = (ARGBPixel)_root1; if (_root0._data > _root1._data) { pixel[2] = new ARGBPixel(255, (byte)(((pixel[0].R << 1) + pixel[1].R) / 3), (byte)(((pixel[0].G << 1) + pixel[1].G) / 3), (byte)(((pixel[0].B << 1) + pixel[1].B) / 3)); pixel[3] = new ARGBPixel(255, (byte)(((pixel[1].R << 1) + pixel[0].R) / 3), (byte)(((pixel[1].G << 1) + pixel[0].G) / 3), (byte)(((pixel[1].B << 1) + pixel[0].B) / 3)); } else { pixel[2] = new ARGBPixel(255, (byte)((pixel[0].R + pixel[1].R) >> 1), (byte)((pixel[0].G + pixel[1].G) >> 1), (byte)((pixel[0].B + pixel[1].B) >> 1)); pixel[3] = new ARGBPixel(); } uint lookup = _lookup; for (int y = 0, shift = 30; y < 4; y++, block += width) { for (int x = 0; x < 4; shift -= 2) { block[x++] = pixel[(lookup >> shift) & 0x03]; } } }
protected virtual void OnColorChanged(bool hsvToRgb) { _updating = true; if (hsvToRgb) { _rgba = (ARGBPixel)_hsv; _rgba.A = (byte)numA.Value; } else { _hsv = (HSVPixel)_rgba; } numH.Value = _hsv.H; numS.Value = _hsv.S; numV.Value = _hsv.V; numR.Value = _rgba.R; numG.Value = _rgba.G; numB.Value = _rgba.B; numA.Value = _rgba.A; txtColorCode.Text = _rgba.ToRGBAColorCode(); _updating = false; pnlColorBox.Invalidate(); pnlColorBar.Invalidate(); if (ColorChanged != null) { ColorChanged(this, null); } }
public override bool OnInitialize() { base.OnInitialize(); _colors = new List <ARGBPixel>(); fixedFlags = Data->_fixedFlags; usageFlags = Data->_flags; if ((fixedFlags >> 7 & 1) == 1) { _constant = true; _numEntries = 0; _solidColor = (ARGBPixel)Data->_lighting; } else if (Name != "<null>") { _constant = false; _numEntries = FrameCount + 1; RGBAPixel *addr = Data->lightEntries; for (int i = 0; i < _numEntries; i++) { _colors.Add((ARGBPixel)(*addr++)); } } return(false); }
protected override void DecodeBlock(VoidPtr blockAddr, ARGBPixel *dPtr, int width) { byte *sPtr = (byte *)blockAddr; byte b; if (_workingPalette != null) { for (int y = 0; y < BlockHeight; y++, dPtr += width) { for (int x = 0; x < BlockWidth;) { b = *sPtr++; dPtr[x++] = (ARGBPixel)_workingPalette.Entries[b >> 4]; dPtr[x++] = (ARGBPixel)_workingPalette.Entries[b & 0xF]; } } } else { for (int y = 0; y < BlockHeight; y++, dPtr += width) { for (int x = 0; x < BlockWidth;) { b = *sPtr++; dPtr[x++] = new ARGBPixel((byte)(b & 0xF0)); dPtr[x++] = new ARGBPixel((byte)(b << 4)); } } } }
private void colorToolStripMenuItem_Click(object sender, EventArgs e) { var indices = SelectedIndices; if (indices.Count >= 0) { int v = 0; List <ARGBPixel> pixels = GetCopiedPixels(); foreach (int r in indices) { if (v >= pixels.Count) { break; } ARGBPixel copied = pixels[v++]; ARGBPixel temp = (ARGBPixel)lstColors.Items[r]; temp.R = copied.R; temp.G = copied.G; temp.B = copied.B; lstColors.Items[r] = temp; _colorSource.SetColor(r, _colorId, temp); } } }
public void MakeSolid(ARGBPixel color, int id) { _numEntries[id] = 0; _constants[id] = true; _solidColors[id] = (RGBAPixel)color; SignalPropertyChange(); }
private void copyToolStripMenuItem_Click(object sender, EventArgs e) { if (lstColors.SelectedIndex >= 0) { _copyColor = (ARGBPixel)lstColors.SelectedItem; } }
private void lstColors_DrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; Rectangle r = e.Bounds; int index = e.Index; g.FillRectangle(Brushes.White, r); if (index >= 0) { ARGBPixel p = (ARGBPixel)lstColors.Items[index]; if ((e.State & DrawItemState.Selected) != 0) { g.FillRectangle(Brushes.LightBlue, r.X, r.Y, 230, r.Height); } g.DrawString(String.Format("[{0:d2}] - {1}", index, p), _renderFont, Brushes.Black, 4.0f, e.Bounds.Y - 2); r.X += 230; r.Width = 40; using (Brush b = new SolidBrush((Color)p)) g.FillRectangle(b, r); g.DrawRectangle(Pens.Black, r); p.A = 255; r.X += 40; using (Brush b = new SolidBrush((Color)p)) g.FillRectangle(b, r); g.DrawRectangle(Pens.Black, r); } }
public void MakeSolid(ARGBPixel color) { _numEntries = 0; _constant = true; _solidColor = color; SignalPropertyChange(); }
protected override void DecodeBlock(VoidPtr blockAddr, ARGBPixel *dPtr, int width) { byte *sPtr = (byte *)blockAddr; if (_workingPalette != null) { for (int y = 0; y < BlockHeight; y++, dPtr += width) { for (int x = 0; x < BlockWidth; x++) { byte b = *sPtr++; if (b >= _workingPalette.Entries.Length) { dPtr[x] = new ARGBPixel(); } else { dPtr[x] = (ARGBPixel)_workingPalette.Entries[b]; } } } } else { for (int y = 0; y < BlockHeight; y++, dPtr += width) { for (int x = 0; x < BlockWidth; x++) { dPtr[x] = new ARGBPixel(*sPtr++); } } } }
public void SetColor(int index, int id, ARGBPixel color) { if (index >= 0 && index < Colors.Length) { Colors[index] = color; SignalPropertyChange(); } }
public void SetColor(int index, int id, ARGBPixel color) { if (_numEntries == 0) { _solidColor = color; } else { _colors[index] = color; } SignalPropertyChange(); }
public void SetColor(int index, int id, ARGBPixel color) { if (_numEntries[id] == 0) { _solidColors[id] = (RGBAPixel)color; } else { GetColors(id)[index] = (RGBAPixel)color; } SignalPropertyChange(); }
private void lstColors_DoubleClick(object sender, EventArgs e) { ListBox.SelectedIndexCollection indices = lstColors.SelectedIndices; if ((_colorSource == null) || (indices.Count <= 0)) { return; } int count = indices.Count; if (count == 1) { int index = indices[0]; _dlgColor.Color = (Color)(ARGBPixel)lstColors.Items[index]; if (_dlgColor.ShowDialog(this) == DialogResult.OK) { ARGBPixel p = (ARGBPixel)_dlgColor.Color; lstColors.Items[index] = p; _colorSource.SetColor(index, p); } } else { //Sort indices int[] sorted = new int[count]; indices.CopyTo(sorted, 0); Array.Sort(sorted); _dlgGradient.StartColor = (Color)(ARGBPixel)lstColors.Items[sorted[0]]; _dlgGradient.EndColor = (Color)(ARGBPixel)lstColors.Items[sorted[count - 1]]; if (_dlgGradient.ShowDialog(this) == DialogResult.OK) { //Interpolate and apply to each in succession. ARGBPixel start = (ARGBPixel)_dlgGradient.StartColor; ARGBPixel end = (ARGBPixel)_dlgGradient.EndColor; float stepA = (end.A - start.A) / (float)count; float stepR = (end.R - start.R) / (float)count; float stepG = (end.G - start.G) / (float)count; float stepB = (end.B - start.B) / (float)count; for (int i = 0; i < count; i++) { ARGBPixel p = new ARGBPixel( (byte)(start.A + (i * stepA)), (byte)(start.R + (i * stepR)), (byte)(start.G + (i * stepG)), (byte)(start.B + (i * stepB))); lstColors.Items[sorted[i]] = p; _colorSource.SetColor(sorted[i], p); } } } }
public override bool OnInitialize() { base.OnInitialize(); _colors = new List <ARGBPixel>(); _startKeys = new KeyframeArray(FrameCount + 1); _endKeys = new KeyframeArray(FrameCount + 1); flags = (SCN0FogFlags)Data->_flags; type = Data->_type; if (Name != "<null>") { if (flags.HasFlag(SCN0FogFlags.FixedStart)) { _startKeys[0] = Data->_start; } else if (!_replaced) { DecodeFrames(_startKeys, Data->startKeyframes); } if (flags.HasFlag(SCN0FogFlags.FixedEnd)) { _endKeys[0] = Data->_end; } else if (!_replaced) { DecodeFrames(_endKeys, Data->endKeyframes); } if (flags.HasFlag(SCN0FogFlags.FixedColor)) { _constant = true; _numEntries = 0; _solidColor = (ARGBPixel)Data->_color; } else { _constant = false; _numEntries = FrameCount + 1; RGBAPixel *addr = Data->colorEntries; for (int i = 0; i <= FrameCount; i++) { _colors.Add((ARGBPixel)(*addr++)); } } } return(false); }
void _dlgColor_OnColorChanged(Color selection) { if (tempIndex >= 0) { ARGBPixel p = (ARGBPixel)selection; lstColors.Items[tempIndex] = p; _colorSource.SetColor(tempIndex, _colorId, p); if (CurrentColorChanged != null) { CurrentColorChanged(this, EventArgs.Empty); } } }
private void lblBase_Click(object sender, EventArgs e) { if (_colorSource == null) { return; } _dlgColor.Color = (Color)_primaryColor; if (_dlgColor.ShowDialog(this) == DialogResult.OK) { _primaryColor = (ARGBPixel)_dlgColor.Color; _colorSource.SetPrimaryColor(_colorId, _primaryColor); UpdateBase(); } }
private void UpdateBoxes() { _updating = true; numH.Value = _hsv.H; numS.Value = _hsv.S; numV.Value = _hsv.V; _rgb = (ARGBPixel)_hsv; _rgb.A = (byte)numA.Value; numR.Value = _rgb.R; numG.Value = _rgb.G; numB.Value = _rgb.B; _updating = false; }
public override bool OnInitialize() { _colors.Clear(); _colorMask = (ARGBPixel)Header->_colorMask; if (_replaced && WorkingUncompressed.Length >= 16 && Header->_data == 8) { _numEntries = *((bint *)Header + 2); _constant = _numEntries == 0; RGBAPixel *data = Header->Data; if (_constant) { _solidColor = *data; } else { int frameCount = ((CLR0Node)Parent.Parent)._numFrames; for (int i = 0; i < frameCount; i++) { _colors.Add(i >= _numEntries ? new ARGBPixel() : (ARGBPixel)(*data++)); } _numEntries = frameCount; } } else { if (_constant) { _numEntries = 0; _solidColor = (ARGBPixel)Header->SolidColor; } else { _numEntries = ((CLR0Node)Parent.Parent)._numFrames; RGBAPixel *data = Header->Data; for (int i = 0; i < _numEntries; i++) { _colors.Add((ARGBPixel)(*data++)); } } } _name = _target.ToString(); return(false); }
public static int FindMatch(this ColorPalette pal, ARGBPixel pixel) { int bestDist = Int32.MaxValue, bestIndex = 0; for (int i = 0, c = pal.Entries.Length; i < c; i++) { int dist = pixel.DistanceTo(pal.Entries[i]); if (dist < bestDist) { bestIndex = i; if (dist == 0) { break; } bestDist = dist; } } return(bestIndex); }
internal void SetNumEntries(int id, int value) { //if (_numEntries[id] == 0) // return; if (value > _numEntries[id]) { ARGBPixel p = _numEntries[id] > 0 ? (ARGBPixel)GetColors(id)[_numEntries[id] - 1] : new ARGBPixel(255, 0, 0, 0); for (int i = value - _numEntries[id]; i-- > 0;) { GetColors(id).Add((RGBAPixel)p); } } else if (value < GetColors(id).Count) { GetColors(id).RemoveRange(value, GetColors(id).Count - value); } _numEntries[id] = value; }
private void allToolStripMenuItem_Click(object sender, EventArgs e) { var indices = SelectedIndices; if (indices.Count >= 0) { int v = 0; List <ARGBPixel> pixels = GetCopiedPixels(); foreach (int r in indices) { if (v >= pixels.Count) { break; } ARGBPixel copied = pixels[v++]; lstColors.Items[r] = copied; _colorSource.SetColor(r, _colorId, copied); } } }
private void pnlColorBar_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //Draw bar g.FillRectangle(_barBrush, pnlColorBar.ClientRectangle); //Draw indicator ARGBPixel p = ((ARGBPixel)(new HSVPixel(_hsv.H, 100, 100))).Inverse(); int y = (int)(_hsv.H / 360.0f * (pnlColorBar.Height - 1)); Rectangle r = new Rectangle(-1, y - 2, pnlColorBar.Width + 1, 4); using (Pen pen = new Pen((Color)p)) g.DrawRectangle(pen, r); r.Y += 1; r.Height -= 2; p = p.Lighten(64); using (Pen pen = new Pen((Color)p)) g.DrawRectangle(pen, r); }
private void SourceChanged() { lstColors.BeginUpdate(); lstColors.Items.Clear(); if (_colorSource != null) { int count = _colorSource.ColorCount(_colorId); for (int i = 0; i < count; i++) { lstColors.Items.Add(_colorSource.GetColor(i, _colorId)); } if (pnlPrimary.Visible = _colorSource.HasPrimary(_colorId)) { _primaryColor = _colorSource.GetPrimaryColor(_colorId); lblPrimary.Text = _colorSource.PrimaryColorName(_colorId); UpdateBase(); } } lstColors.EndUpdate(); }
private void pnlColorBox_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //Update brush if color changed if (_brushH != _hsv.H) { _boxColors[0] = _boxColors[4] = (Color)(new HSVPixel(_hsv.H, 100, 100)); _squareBrush.SurroundColors = _boxColors; _squareBrush.CenterColor = (Color)(new HSVPixel(_hsv.H, 50, 50)); _brushH = _hsv.H; } //Draw square //g.FillPath(_squareBrush, _squarePath); g.FillRectangle(_squareBrush, pnlColorBox.ClientRectangle); //Draw indicator int x = (int)(_hsv.V / 100.0f * pnlColorBox.Width); int y = (int)((100 - _hsv.S) / 100.0f * pnlColorBox.Height); Rectangle r = new Rectangle(x - 3, y - 3, 6, 6); ARGBPixel p = _rgb.Inverse(); p.A = 255; using (Pen pen = new Pen((Color)p)) g.DrawEllipse(pen, r); r.X -= 1; r.Y -= 1; r.Width += 2; r.Height += 2; p = p.Lighten(64); using (Pen pen = new Pen((Color)p)) g.DrawEllipse(pen, r); }
private void pnlAlpha_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //Draw bar g.FillRectangle(_alphaBrush, pnlAlpha.ClientRectangle); //Draw indicator byte col = (byte)(255 - _rgb.A); ARGBPixel p = new ARGBPixel(255, col, col, col); int y = (int)(col / 255.0f * (pnlAlpha.Height - 1)); Rectangle r = new Rectangle(-1, y - 2, pnlAlpha.Width + 1, 4); using (Pen pen = new Pen((Color)p)) g.DrawRectangle(pen, r); p.Lighten(64); r.Y += 1; r.Height -= 2; using (Pen pen = new Pen((Color)p)) g.DrawRectangle(pen, r); }