gambatte pal editor: use system color picker dialog

... but something about the customcolors isn't working right?
This commit is contained in:
goyuken 2012-09-13 22:20:05 +00:00
parent bf5625655d
commit c72ac19037
2 changed files with 82 additions and 209 deletions

View File

@ -43,22 +43,12 @@
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
this.label7 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.panel13 = new System.Windows.Forms.Panel();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
this.SuspendLayout();
//
// panel1
@ -68,7 +58,7 @@
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(40, 32);
this.panel1.TabIndex = 0;
this.panel1.Click += new System.EventHandler(this.panel12_Click);
this.panel1.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel2
//
@ -77,7 +67,7 @@
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(40, 32);
this.panel2.TabIndex = 1;
this.panel2.Click += new System.EventHandler(this.panel12_Click);
this.panel2.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel3
//
@ -86,7 +76,7 @@
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(40, 32);
this.panel3.TabIndex = 2;
this.panel3.Click += new System.EventHandler(this.panel12_Click);
this.panel3.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel4
//
@ -95,7 +85,7 @@
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(40, 32);
this.panel4.TabIndex = 3;
this.panel4.Click += new System.EventHandler(this.panel12_Click);
this.panel4.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel5
//
@ -104,7 +94,7 @@
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(40, 32);
this.panel5.TabIndex = 4;
this.panel5.Click += new System.EventHandler(this.panel12_Click);
this.panel5.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel6
//
@ -113,7 +103,7 @@
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(40, 32);
this.panel6.TabIndex = 5;
this.panel6.Click += new System.EventHandler(this.panel12_Click);
this.panel6.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel7
//
@ -122,7 +112,7 @@
this.panel7.Name = "panel7";
this.panel7.Size = new System.Drawing.Size(40, 32);
this.panel7.TabIndex = 6;
this.panel7.Click += new System.EventHandler(this.panel12_Click);
this.panel7.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel8
//
@ -131,7 +121,7 @@
this.panel8.Name = "panel8";
this.panel8.Size = new System.Drawing.Size(40, 32);
this.panel8.TabIndex = 7;
this.panel8.Click += new System.EventHandler(this.panel12_Click);
this.panel8.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel9
//
@ -140,7 +130,7 @@
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(40, 32);
this.panel9.TabIndex = 8;
this.panel9.Click += new System.EventHandler(this.panel12_Click);
this.panel9.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel10
//
@ -149,7 +139,7 @@
this.panel10.Name = "panel10";
this.panel10.Size = new System.Drawing.Size(40, 32);
this.panel10.TabIndex = 9;
this.panel10.Click += new System.EventHandler(this.panel12_Click);
this.panel10.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel11
//
@ -158,7 +148,7 @@
this.panel11.Name = "panel11";
this.panel11.Size = new System.Drawing.Size(40, 32);
this.panel11.TabIndex = 10;
this.panel11.Click += new System.EventHandler(this.panel12_Click);
this.panel11.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// panel12
//
@ -167,7 +157,7 @@
this.panel12.Name = "panel12";
this.panel12.Size = new System.Drawing.Size(40, 32);
this.panel12.TabIndex = 11;
this.panel12.Click += new System.EventHandler(this.panel12_Click);
this.panel12.DoubleClick += new System.EventHandler(this.panel12_DoubleClick);
//
// label1
//
@ -196,72 +186,6 @@
this.label3.TabIndex = 14;
this.label3.Text = "SP2";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(21, 150);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(15, 13);
this.label4.TabIndex = 15;
this.label4.Text = "R";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(21, 176);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(15, 13);
this.label5.TabIndex = 16;
this.label5.Text = "G";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(22, 202);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(14, 13);
this.label6.TabIndex = 17;
this.label6.Text = "B";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(42, 148);
this.numericUpDown1.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(120, 20);
this.numericUpDown1.TabIndex = 18;
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(42, 174);
this.numericUpDown2.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(120, 20);
this.numericUpDown2.TabIndex = 19;
this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// numericUpDown3
//
this.numericUpDown3.Location = new System.Drawing.Point(42, 200);
this.numericUpDown3.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.numericUpDown3.Name = "numericUpDown3";
this.numericUpDown3.Size = new System.Drawing.Size(120, 20);
this.numericUpDown3.TabIndex = 20;
this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// label7
//
this.label7.AutoSize = true;
@ -291,13 +215,6 @@
this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true;
//
// panel13
//
this.panel13.Location = new System.Drawing.Point(168, 150);
this.panel13.Name = "panel13";
this.panel13.Size = new System.Drawing.Size(52, 70);
this.panel13.TabIndex = 24;
//
// button3
//
this.button3.Location = new System.Drawing.Point(226, 38);
@ -336,16 +253,9 @@
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.panel13);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label7);
this.Controls.Add(this.numericUpDown3);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
@ -363,9 +273,6 @@
this.Controls.Add(this.panel1);
this.Name = "ColorChooserForm";
this.Text = "ColorChooserForm";
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -388,16 +295,9 @@
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.NumericUpDown numericUpDown3;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Panel panel13;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;

View File

@ -17,35 +17,59 @@ namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
}
Color[] colors = new Color[12];
int selectedcolor = -1;
Panel currentpanel = null;
bool refreshingcolors = false;
private void RefreshColors(bool changenumeric)
private void RefreshAllBackdrops()
{
refreshingcolors = true;
if (selectedcolor == -1)
{
panel13.BackColor = DefaultBackColor;
}
else
{
panel13.BackColor = colors[selectedcolor];
if (changenumeric)
{
numericUpDown1.Value = colors[selectedcolor].R;
numericUpDown2.Value = colors[selectedcolor].G;
numericUpDown3.Value = colors[selectedcolor].B;
}
if (currentpanel != null)
currentpanel.BackColor = colors[selectedcolor];
}
refreshingcolors = false;
panel1.BackColor = colors[0];
panel2.BackColor = colors[1];
panel3.BackColor = colors[2];
panel4.BackColor = colors[3];
panel5.BackColor = colors[4];
panel6.BackColor = colors[5];
panel7.BackColor = colors[6];
panel8.BackColor = colors[7];
panel9.BackColor = colors[8];
panel10.BackColor = colors[9];
panel11.BackColor = colors[10];
panel12.BackColor = colors[11];
}
private void panel12_Click(object _sender, EventArgs e)
Color betweencolor(Color left, Color right, double pos)
{
int R = (int)(right.R * pos + left.R * (1.0 - pos) + 0.5);
int G = (int)(right.G * pos + left.G * (1.0 - pos) + 0.5);
int B = (int)(right.B * pos + left.B * (1.0 - pos) + 0.5);
int A = (int)(right.A * pos + left.A * (1.0 - pos) + 0.5);
return Color.FromArgb(A, R, G, B);
}
void interpolate_colors(int firstindex, int lastindex)
{
for (int i = firstindex + 1; i < lastindex; i++)
{
double pos = (double)(i - firstindex) / (double)(lastindex - firstindex);
colors[i] = betweencolor(colors[firstindex], colors[lastindex], pos);
}
RefreshAllBackdrops();
}
private void button3_Click(object sender, EventArgs e)
{
interpolate_colors(0, 3);
}
private void button4_Click(object sender, EventArgs e)
{
interpolate_colors(4, 7);
}
private void button5_Click(object sender, EventArgs e)
{
interpolate_colors(8, 11);
}
private void panel12_DoubleClick(object _sender, EventArgs e)
{
Panel sender = (Panel)_sender;
@ -75,45 +99,30 @@ namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
else if (sender == panel12)
i = 11;
else
i = -1;
return; // i = -1;
selectedcolor = i;
currentpanel = sender;
RefreshColors(true);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if (refreshingcolors)
return;
if (selectedcolor != -1)
using (var dlg = new ColorDialog())
{
colors[selectedcolor] = Color.FromArgb(
(int)numericUpDown1.Value,
(int)numericUpDown2.Value,
(int)numericUpDown3.Value
);
dlg.AllowFullOpen = true;
dlg.AnyColor = true;
dlg.Color = colors[i];
RefreshColors(false);
// custom colors are ints, not Color structs?
int[] customs = new int[12];
for (int j = 0; j < customs.Length; j++)
customs[j] = colors[j].ToArgb();
dlg.CustomColors = customs;
dlg.FullOpen = true;
var result = dlg.ShowDialog(this);
if (result == System.Windows.Forms.DialogResult.OK)
{
colors[i] = dlg.Color;
sender.BackColor = colors[i];
}
}
}
private void SetColorsOnce()
{
panel1.BackColor = colors[0];
panel2.BackColor = colors[1];
panel3.BackColor = colors[2];
panel4.BackColor = colors[3];
panel5.BackColor = colors[4];
panel6.BackColor = colors[5];
panel7.BackColor = colors[6];
panel8.BackColor = colors[7];
panel9.BackColor = colors[8];
panel10.BackColor = colors[9];
panel11.BackColor = colors[10];
panel12.BackColor = colors[11];
}
public static bool DoColorChooserFormDialog(int[] colors)
@ -122,7 +131,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
{
for (int i = 0; i < dlg.colors.Length; i++)
dlg.colors[i] = Color.FromArgb(255, Color.FromArgb(colors[i]));
dlg.SetColorsOnce();
dlg.RefreshAllBackdrops();
var result = dlg.ShowDialog();
if (result != DialogResult.OK)
@ -137,41 +146,5 @@ namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
}
}
}
Color betweencolor(Color left, Color right, double pos)
{
int R = (int)(right.R * pos + left.R * (1.0 - pos) + 0.5);
int G = (int)(right.G * pos + left.G * (1.0 - pos) + 0.5);
int B = (int)(right.B * pos + left.B * (1.0 - pos) + 0.5);
int A = (int)(right.A * pos + left.A * (1.0 - pos) + 0.5);
return Color.FromArgb(A, R, G, B);
}
void interpolate_colors(int firstindex, int lastindex)
{
for (int i = firstindex + 1; i < lastindex; i++)
{
double pos = (double)(i - firstindex) / (double)(lastindex - firstindex);
colors[i] = betweencolor(colors[firstindex], colors[lastindex], pos);
}
SetColorsOnce();
RefreshColors(true);
}
private void button3_Click(object sender, EventArgs e)
{
interpolate_colors(0, 3);
}
private void button4_Click(object sender, EventArgs e)
{
interpolate_colors(4, 7);
}
private void button5_Click(object sender, EventArgs e)
{
interpolate_colors(8, 11);
}
}
}