private void ProcessKeyLeftEvent() { if (m_HoveredBox == null) { m_HoveredBox = m_ColorBoxs[0]; } else { //Anything before if ((m_HoveredBox.Index - 1) > -1) { m_HoveredBox = m_ColorBoxs[m_HoveredBox.Index - 1]; } else //Start from End { m_HoveredBox = m_ColorBoxs[m_ColorBoxs.Count - 1]; } } Invalidate(); }
private void ProcessKeyUpEvent() { if (m_HoveredBox == null) { m_HoveredBox = m_ColorBoxs[0]; } else { if ((m_HoveredBox.Index - MAX_COLS) > -1) { m_HoveredBox = m_ColorBoxs[m_HoveredBox.Index - MAX_COLS]; } } Invalidate(); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); m_HoveredBox = null; m_overdefaultcolor = false; if (m_rectboxs.Contains(e.Location)) { foreach (ColorBox box in m_ColorBoxs) { if (box.BoxRectangle.Contains(e.Location)) { m_HoveredBox = box; break; } } } else if (m_rectdefaultcolor.Contains(e.Location)) { m_overdefaultcolor = true; } this.Invalidate(); }
private void LoadColorBoxs() { int x = m_Spacing; int y = m_Spacing; int movewpos = m_ColorBoxDimensions + m_Spacing; Array knownColors = Enum.GetValues(typeof(System.Drawing.KnownColor)); int curcol = 1; int index = 0; bool gotit = false; List<Color> mycolors = new List<Color>(); foreach (KnownColor k in knownColors) { Color c = Color.FromKnownColor(k); if (!c.IsSystemColor && (c.A > 0)) { gotit = false; for (index = 0; index < mycolors.Count; index++) { //Sort by brightness if (c.GetBrightness() > mycolors[index].GetBrightness()) { gotit = true; break; } } if (gotit) mycolors.Insert(index, c); else mycolors.Add(c); } } foreach (Color item in mycolors) { Rectangle rect = new Rectangle( x, y, m_ColorBoxDimensions, m_ColorBoxDimensions); ColorBox box = new ColorBox(item, rect, m_ColorBoxs.Count); m_ColorBoxs.Add(box); curcol++; //New row if (curcol > MAX_COLS) { curcol = 1; x = m_Spacing; y += movewpos; } else { x += movewpos; } } //Adjust height, account for status and reset default text this.Height = y + (movewpos * 2); }
private void LoadColorBoxs() { int x = m_Spacing; int y = m_Spacing; int movewpos = m_ColorBoxDimensions + m_Spacing; Array knownColors = Enum.GetValues(typeof(System.Drawing.KnownColor)); int curcol = 1; int index = 0; bool gotit = false; List <Color> mycolors = new List <Color>(); foreach (KnownColor k in knownColors) { Color c = Color.FromKnownColor(k); if (!c.IsSystemColor && (c.A > 0)) { gotit = false; for (index = 0; index < mycolors.Count; index++) { //Sort by brightness if (c.GetBrightness() > mycolors[index].GetBrightness()) { gotit = true; break; } } if (gotit) { mycolors.Insert(index, c); } else { mycolors.Add(c); } } } foreach (Color item in mycolors) { Rectangle rect = new Rectangle( x, y, m_ColorBoxDimensions, m_ColorBoxDimensions); ColorBox box = new ColorBox(item, rect, m_ColorBoxs.Count); m_ColorBoxs.Add(box); curcol++; //New row if (curcol > MAX_COLS) { curcol = 1; x = m_Spacing; y += movewpos; } else { x += movewpos; } } //Adjust height, account for status and reset default text this.Height = y + (movewpos * 2); }
public override bool PreProcessMessage(ref Message msg) { if (msg.Msg == WM_KEYDOWN) { m_msgkey = (int)msg.WParam; if (((Keys)m_msgkey) == Keys.Up) { ProcessKeyUpEvent(); return true; } else if (((Keys)m_msgkey) == Keys.Down) { ProcessKeyDownEvent(); return true; } else if (((Keys)m_msgkey) == Keys.Left) { ProcessKeyLeftEvent(); return true; } else if (((Keys)m_msgkey) == Keys.Right) { ProcessKeyRightEvent(); return true; } else if (((Keys)m_msgkey) == Keys.Cancel) { m_SelectedBox = null; if (SelectionCancelled != null) SelectionCancelled(this, EventArgs.Empty); return true; } else if (((Keys)m_msgkey) == Keys.Enter) { if ((m_HoveredBox != null) && (SelectionChanged != null)) { m_SelectedBox = m_HoveredBox; m_eventArgs.SelectedColor = m_SelectedBox.BoxColor; SelectionChanged(this, m_eventArgs); } return true; } else return base.PreProcessMessage(ref msg); } else return base.PreProcessMessage(ref msg); }
private void AttachThis(ColorBox myBox, ColorMix myMix) { myBox.Attach(myMix); }
private Panel BuildSettingPanel() { var muPanel = new Panel(); var lblMouseHighlight = new Label() { Parent = muPanel, Location = new Point(15, 25), Text = "Mouse Highlight", AutoSizeHeight = true, AutoSizeWidth = true, TextColor = Color.White, Font = GameService.Content.GetFont(ContentService.FontFace.Menomonia, ContentService.FontSize.Size18, ContentService.FontStyle.Regular), }; var colorPicker = new ColorPicker() { Width = 384 + 57, Height = 128, Location = new Point(lblMouseHighlight.Left + 10, lblMouseHighlight.Bottom + 5), Parent = muPanel }; // TODO: Why is this here? Map.IndexEndpoint(); AllColors.Reverse(); AllColors.ForEach(clr => colorPicker.Colors.Add(clr)); var cpScroller = new Scrollbar(colorPicker) { Parent = muPanel, Left = colorPicker.Right, Top = colorPicker.Top, Height = colorPicker.Height }; var lblHighlightColor = new Label() { Parent = muPanel, Top = colorPicker.Bottom + 10, Left = colorPicker.Left, Text = "Highlight Color", Height = 32, VerticalAlignment = Utils.DrawUtil.VerticalAlignment.Middle, AutoSizeWidth = true, TextColor = Color.White, Font = GameService.Content.DefaultFont14, }; var highlightColor = new ColorBox() { Parent = muPanel, Top = colorPicker.Bottom + 10, Left = lblHighlightColor.Right + 5, ColorId = setting_hl_highlightColorId.Value }; //GameServices.GetService<DataBindingService>().AddBinding( // setting_hl_highlightColorId, "Value", // highlightColor, "ColorId" //); //Binding.Create(() => setting_hl_highlightColorId.Value == highlightColor.ColorId); Adhesive.Binding.CreateTwoWayBinding(() => setting_hl_highlightColorId.Value, () => highlightColor.ColorId); var lblOutlineColor = new Label() { Parent = muPanel, Top = colorPicker.Bottom + 10, Left = highlightColor.Right + 25, Text = "Outline Color", Height = 32, VerticalAlignment = Utils.DrawUtil.VerticalAlignment.Middle, AutoSizeWidth = true, TextColor = Color.White, Font = GameService.Content.DefaultFont14, }; var outlineColor = new ColorBox() { Parent = muPanel, Left = lblOutlineColor.Right + 5, Top = colorPicker.Bottom + 10, ColorId = setting_hl_outlineColorId.Value }; var cbMouseHighlight = new Checkbox() { Parent = muPanel, Top = highlightColor.Bottom + 10, Left = colorPicker.Left, Text = "Enable Mouse Highlight", Checked = setting_hl_showHighlight.Value, }; var cbShowOverUI = new Checkbox() { Parent = muPanel, Top = cbMouseHighlight.Bottom + 5, Left = cbMouseHighlight.Left, Text = "Show Mouse Highlight Over Blish HUD UI", Checked = setting_hl_showOverBlishHud.Value, }; var lblOpacity = new Label() { Parent = muPanel, Top = cbShowOverUI.Bottom + 6, Left = cbShowOverUI.Left, Text = "Opacity", AutoSizeHeight = true, AutoSizeWidth = true, TextColor = Color.White, Font = GameService.Content.DefaultFont14, }; var tbOpacity = new TrackBar() { Parent = muPanel, Top = lblOpacity.Top + lblOpacity.Height / 2 - 8, Left = cpScroller.Right - 256, MinValue = 0, MaxValue = 1, Value = 1.0f, }; var lblHighlightThickness = new Label() { Parent = muPanel, Top = lblOpacity.Bottom + 6, Left = colorPicker.Left, Text = "Highlight Thickness", AutoSizeHeight = true, AutoSizeWidth = true, TextColor = Color.White, }; var tbHighlightThickness = new TrackBar() { Parent = muPanel, Top = lblHighlightThickness.Top + lblHighlightThickness.Height / 2 - 8, Left = cpScroller.Right - 256, Value = 2, MinValue = 1, MaxValue = 15, }; // Wire settings to control so they stay in sync //GameServices.GetService<DataBindingService>().AddBinding( // setting_hl_hightlightThickness, "Value", // tbHighlightThickness, "Value", new OneWayBinding[] { // new OneWayBinding(HorizontalHighlight, "HighlightThickness"), // new OneWayBinding(VerticalHighlight, "HighlightThickness"), // } //); var lblOutlineThickness = new Label() { Parent = muPanel, Top = tbHighlightThickness.Bottom + 6, Left = colorPicker.Left, Text = "Outline Thickness", AutoSizeHeight = true, AutoSizeWidth = true, TextColor = Color.White, Font = GameService.Content.DefaultFont14, }; var tbOutlineThickness = new TrackBar() { Parent = muPanel, Top = lblOutlineThickness.Top + lblOutlineThickness.Height / 2 - 8, Left = cpScroller.Right - 256, Value = 2, MinValue = 0, MaxValue = 5, }; //GameServices.GetService<DataBindingService>().AddBinding( // setting_hl_outlineThickness, "Value", // tbOutlineThickness, "Value", new OneWayBinding[] { // new OneWayBinding(HorizontalHighlight, "OutlineThickness"), // new OneWayBinding(VerticalHighlight, "OutlineThickness"), // } //); // Bind opacity to slider and settings value //GameServices.GetService<DataBindingService>().AddBinding( // setting_hl_highlightOpacity, "Value", // tbOpacity, "Value", new OneWayBinding[] { // new OneWayBinding(HorizontalHighlight, "Opacity"), // new OneWayBinding(VerticalHighlight, "Opacity"), // } //); cbMouseHighlight.CheckedChanged += delegate { HorizontalHighlight.Visible = cbMouseHighlight.Checked; VerticalHighlight.Visible = cbMouseHighlight.Checked; setting_hl_showHighlight.Value = cbMouseHighlight.Checked; }; cbShowOverUI.CheckedChanged += delegate { HorizontalHighlight.ZIndex = cbShowOverUI.Checked ? int.MaxValue : 0; VerticalHighlight.ZIndex = cbShowOverUI.Checked ? int.MaxValue : 0; setting_hl_showOverBlishHud.Value = cbShowOverUI.Checked; }; //tbOpacity.ValueChanged += delegate { HorizontalHighlight.Opacity = tbOpacity.Value / 100; VerticalHighlight.Opacity = tbOpacity.Value / 100; }; //tbHighlightThickness.ValueChanged += delegate { HorizontalHighlight.HighlightThickness = tbHighlightThickness.IntValue + 1; VerticalHighlight.HighlightThickness = tbHighlightThickness.IntValue + 1; }; //tbOutlineThickness.ValueChanged += delegate { HorizontalHighlight.OutlineThickness = tbOutlineThickness.IntValue; VerticalHighlight.OutlineThickness = tbOutlineThickness.IntValue; }; highlightColor.LeftMouseButtonPressed += delegate { colorPicker.AssociatedColorBox = highlightColor; }; outlineColor.LeftMouseButtonPressed += delegate { colorPicker.AssociatedColorBox = outlineColor; }; highlightColor.OnColorChanged += delegate { HorizontalHighlight.HighlightColor = highlightColor.Color.Leather.Rgb.ToXnaColor(); VerticalHighlight.HighlightColor = highlightColor.Color.Leather.Rgb.ToXnaColor(); }; outlineColor.OnColorChanged += delegate { HorizontalHighlight.OutlineColor = outlineColor.Color.Leather.Rgb.ToXnaColor(); VerticalHighlight.OutlineColor = outlineColor.Color.Leather.Rgb.ToXnaColor(); }; colorPicker.AssociatedColorBox = highlightColor; return(muPanel); }
// 代表色の選択 private ArgbPalette generatePalette(Size size, ColorEntry[] colors, ColorBox[] boxes, ArgbColor[] importantColors, int paletteSize) { #if DEBUG var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); #endif int totalPixelCount = size.Width * size.Height; ArgbColor center = ArgbColor.FromArgb(128, 128, 128); ArgbPalette palette = new ArgbPalette(paletteSize); for (int i = 0; i < paletteSize; i++) { uint sumR = 0; uint sumG = 0; uint sumB = 0; uint sumCount = 0; int indexMin = boxes[i].ColorIndexMin; int indexMax = boxes[i].ColorIndexMax; int length = (indexMax - indexMin + 1); int maxDist = 0; ColorEntry maxE = colors[indexMin]; for (int j = indexMin; j <= indexMax; j++) { ArgbColor thisColor = colors[j].Color; int penalty = 0; foreach (var c in importantColors) { int dist2 = (int)thisColor.GetEuclidDistanceTo(c); if (dist2 > 64) dist2 = 0; penalty += dist2 *10; } if (importantColors.Length > 0) { penalty /= importantColors.Length; } sumR += thisColor.R * colors[j].Count; sumG += thisColor.G * colors[j].Count; sumB += thisColor.B * colors[j].Count; int dist = (int)center.GetEuclidDistanceTo(thisColor) + (1000 * (int)colors[j].Count / totalPixelCount) - penalty; if (dist > maxDist) { maxDist = dist; maxE = colors[j]; } sumCount += colors[j].Count; } byte r = (byte)Math.Round((float)sumR / (float)sumCount); byte g = (byte)Math.Round((float)sumG / (float)sumCount); byte b = (byte)Math.Round((float)sumB / (float)sumCount); palette.Set(i, r, g, b, 1); } #if DEBUG Console.WriteLine("palette generation ({0} msec).", stopWatch.ElapsedMilliseconds); #endif return palette; }
private void AddColorControl(Color color) { ColorBox box = new ColorBox(); box.SelectedColor = color; box.Size = new Size(32, 32); box.ColorChanging += new System.EventHandler(box_ColorChanging); box.ColorChanged += new System.EventHandler(box_ColorChanged); Controls.Add(box); }
// メディアンカット private unsafe ColorBox[] medianCut(ColorEntry[] colors, ArgbColor[] importantColors, int paletteSize) { #if DEBUG var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); #endif ColorBox[] boxes = new ColorBox[paletteSize]; int boxCount = 0; boxes[boxCount++] = new ColorBox(0, colors.Length - 1) ; boxes[0].CalcWeight(colors, importantColors); fixed (ColorEntry* table = colors) while (boxCount < paletteSize) { // 分散が最も大きなBoxを探す int divIndex = -1; int maxWeight = int.MinValue; for (int i = 0; i < boxCount; i++) { if (boxes[i].DivWeight >= maxWeight) { maxWeight = boxes[i].DivWeight; divIndex = i; } } int minIdx = boxes[divIndex].ColorIndexMin; int maxIdx = boxes[divIndex].ColorIndexMax; int ch = boxes[divIndex].DivChannel; // 中央値を決めて分割 int median = boxes[divIndex].MedianValue; int l = minIdx; int r = maxIdx; do { while (l + 1 < r && table[l].Color.Channels[ch] <= median) l++; while (l < r - 1 && table[r].Color.Channels[ch] >= median) r--; if (table[l].Color.Channels[ch] > table[r].Color.Channels[ch]) { ColorEntry temp = table[l]; table[l] = table[r]; table[r] = temp; } } while (l + 1 < r); ColorBox leftBox = new ColorBox( minIdx, l); leftBox.CalcWeight(colors, importantColors); boxes[divIndex] = leftBox; ColorBox rightBox = new ColorBox( r, maxIdx); rightBox.CalcWeight(colors, importantColors); boxes[boxCount++] = rightBox; } #if DEBUG Console.WriteLine("median cut ({0} msec).", stopWatch.ElapsedMilliseconds); #endif return boxes; }
public PaletteEditor(Editor owner, String entry, Pointer address, byte amount) { InitializeComponent(); Status.Text = entry + address; Owner = owner; Entry = entry; Address = address; IsCompressed = (amount == 0); Current = Core.ReadPalette(address, amount * Palette.LENGTH); if (IsCompressed) { amount = (byte)(Current.Count / Palette.MAX); } PaletteAmount = amount; this.Size = new System.Drawing.Size(390, 250 + 22 * amount); this.MinimumSize = this.Size; this.MaximumSize = this.Size; SwapButton.Location = new System.Drawing.Point(13, 170 + 22 * amount); LoadButton.Location = new System.Drawing.Point(131, 170 + 22 * amount); SaveButton.Location = new System.Drawing.Point(248, 170 + 22 * amount); ColorBoxes = new ColorBox[GBA.Palette.MAX * amount]; for (int i = 0; i < ColorBoxes.Length; i++) { ColorBoxes[i] = new ColorBox(); ColorBoxes[i].Gradient = false; ColorBoxes[i].Selected = false; ColorBoxes[i].Location = new System.Drawing.Point( 13 + 22 * (i % GBA.Palette.MAX), 169 + 22 * (i / GBA.Palette.MAX)); ColorBoxes[i].Size = new System.Drawing.Size(16, 16); ColorBoxes[i].Name = "ColorBox" + i; ColorBoxes[i].TabIndex = 8; ColorBoxes[i].TabStop = false; int index = i; ColorBoxes[i].Click += delegate(object sender, EventArgs e) { if (CurrentIndex == index) { ColorDialog colorWindow = new ColorDialog(); colorWindow.FullOpen = true; colorWindow.Color = (System.Drawing.Color)Current[CurrentIndex]; if (colorWindow.ShowDialog(this) == DialogResult.OK) { Core_WriteColor((GBA.Color)colorWindow.Color); } } else { CurrentIndex = index; } }; this.Controls.Add(ColorBoxes[i]); } ColorBoxes[0].Selected = true; }
public TestTube() { Type = new TypeOfMagic(); AttackType = new TypeOfAttack(); crBox = new ColorBox(); }
static ColorBox[] MedianCutApply(int[] histogram, ColorBox box) { if (box.GetCount() == 0) { return(null); } if (box.GetCount() == 1) { return new ColorBox[2] { box.Copy(), null } } ; int rw = box.R2 - box.R1 + 1, gw = box.G2 - box.G1 + 1, bw = box.B2 - box.B1 + 1, maxw = Math.Max(rw, Math.Max(gw, bw)), total = 0, sum, index; var partialSum = new int[0]; if (maxw == rw) { partialSum = new int[box.R2 + 1]; for (int r = box.R1; r <= box.R2; r++) { sum = 0; for (int g = box.G1; g <= box.G2; g++) { for (int b = box.B1; b <= box.B2; b++) { index = MMCQ.GetColorIndex(r, g, b); sum += histogram[index]; } } total += sum; partialSum[r] = total; } } else if (maxw == gw) { partialSum = new int[box.G2 + 1]; for (int g = box.G1; g <= box.G2; g++) { sum = 0; for (int r = box.R1; r <= box.R2; r++) { for (int b = box.B1; b <= box.B2; b++) { index = MMCQ.GetColorIndex(r, g, b); sum += histogram[index]; } } total += sum; partialSum[g] = total; } } else if (maxw == bw) { partialSum = new int[box.B2 + 1]; for (int b = box.B1; b <= box.B2; b++) { sum = 0; for (int r = box.R1; r <= box.R2; r++) { for (int g = box.G1; g <= box.G2; g++) { index = MMCQ.GetColorIndex(r, g, b); sum += histogram[index]; } } total += sum; partialSum[b] = total; } } var lookAheadSum = new int[partialSum.Length]; for (int i = 0; i < partialSum.Length; i++) { lookAheadSum[i] = total - partialSum[i]; } if (maxw == rw) { return(DoCut(box, partialSum, lookAheadSum, total, 'r')); } if (maxw == gw) { return(DoCut(box, partialSum, lookAheadSum, total, 'g')); } if (maxw == bw) { return(DoCut(box, partialSum, lookAheadSum, total, 'b')); } return(null); }
private void DetachThis(ColorBox myBox, ColorMix myMix) { myBox.Detach(myMix); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { ColorManager.HSL hsl3 = new ColorManager.HSL(); ColorManager.HSL hsl4 = new ColorManager.HSL(); colorBox = new ColorBox(); lblOriginalColor = new System.Windows.Forms.Label(); colorSlider = new global::Creek.UI.Unity3.Controls.VerticalColorSlider(); rbBlue = new System.Windows.Forms.RadioButton(); rbGreen = new System.Windows.Forms.RadioButton(); rbRed = new System.Windows.Forms.RadioButton(); rbBrightness = new System.Windows.Forms.RadioButton(); rbSat = new System.Windows.Forms.RadioButton(); rbHue = new System.Windows.Forms.RadioButton(); txtBlue = new System.Windows.Forms.TextBox(); txtGreen = new System.Windows.Forms.TextBox(); txtRed = new System.Windows.Forms.TextBox(); txtBrightness = new System.Windows.Forms.TextBox(); txtSat = new System.Windows.Forms.TextBox(); txtHue = new System.Windows.Forms.TextBox(); tbAlpha = new System.Windows.Forms.TrackBar(); lblAlpha = new System.Windows.Forms.Label(); colorPanelPending = new ColorPanel(); ((System.ComponentModel.ISupportInitialize)(this.tbAlpha)).BeginInit(); SuspendLayout(); // // colorBox // colorBox.DrawStyle = ColorBox.eDrawStyle.Hue; hsl3.H = 0; hsl3.L = 1; hsl3.S = 1; colorBox.HSL = hsl3; colorBox.Location = new System.Drawing.Point(0, 0); colorBox.Name = "colorBox"; colorBox.RGB = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); colorBox.Size = new System.Drawing.Size(212, 181); colorBox.TabIndex = 0; colorBox.Scroll += new System.EventHandler(this.colorBox_Scroll); // // lblOriginalColor // lblOriginalColor.BackColor = System.Drawing.SystemColors.Control; lblOriginalColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; lblOriginalColor.Location = new System.Drawing.Point(274, 82); lblOriginalColor.Name = "lblOriginalColor"; lblOriginalColor.Size = new System.Drawing.Size(60, 34); lblOriginalColor.TabIndex = 39; // // colorSlider // colorSlider.DrawStyle = global::Creek.UI.Unity3.Controls.VerticalColorSlider.eDrawStyle.Hue; hsl4.H = 0; hsl4.L = 1; hsl4.S = 1; colorSlider.HSL = hsl4; colorSlider.Location = new System.Drawing.Point(218, 0); colorSlider.Name = "colorSlider"; colorSlider.RGB = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); colorSlider.Size = new System.Drawing.Size(40, 181); colorSlider.TabIndex = 40; colorSlider.Scroll += new System.EventHandler(this.colorSlider_Scroll); // // rbBlue // rbBlue.Location = new System.Drawing.Point(108, 239); rbBlue.Name = "rbBlue"; rbBlue.Size = new System.Drawing.Size(35, 24); rbBlue.TabIndex = 53; rbBlue.Text = "B:"; rbBlue.CheckedChanged += new System.EventHandler(this.rbBlue_CheckedChanged); // // rbGreen // rbGreen.Location = new System.Drawing.Point(108, 214); rbGreen.Name = "rbGreen"; rbGreen.Size = new System.Drawing.Size(35, 24); rbGreen.TabIndex = 52; rbGreen.Text = "G:"; rbGreen.CheckedChanged += new System.EventHandler(this.rbGreen_CheckedChanged); // // rbRed // rbRed.Location = new System.Drawing.Point(108, 189); rbRed.Name = "rbRed"; rbRed.Size = new System.Drawing.Size(35, 24); rbRed.TabIndex = 51; rbRed.Text = "R:"; rbRed.CheckedChanged += new System.EventHandler(this.rbRed_CheckedChanged); // // rbBrightness // rbBrightness.Location = new System.Drawing.Point(12, 239); rbBrightness.Name = "rbBrightness"; rbBrightness.Size = new System.Drawing.Size(35, 24); rbBrightness.TabIndex = 50; rbBrightness.Text = "B:"; rbBrightness.CheckedChanged += new System.EventHandler(this.rbBrightness_CheckedChanged); // // rbSat // rbSat.Location = new System.Drawing.Point(12, 214); rbSat.Name = "rbSat"; rbSat.Size = new System.Drawing.Size(35, 24); rbSat.TabIndex = 49; rbSat.Text = "S:"; rbSat.CheckedChanged += new System.EventHandler(this.rbSat_CheckedChanged); // // rbHue // rbHue.Location = new System.Drawing.Point(12, 189); rbHue.Name = "rbHue"; rbHue.Size = new System.Drawing.Size(35, 24); rbHue.TabIndex = 48; rbHue.Text = "H:"; rbHue.CheckedChanged += new System.EventHandler(this.rbHue_CheckedChanged); // // txtBlue // txtBlue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtBlue.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtBlue.Location = new System.Drawing.Point(145, 239); txtBlue.Name = "txtBlue"; txtBlue.Size = new System.Drawing.Size(35, 21); txtBlue.TabIndex = 46; txtBlue.Leave += new System.EventHandler(this.txtBlue_Leave); // // txtGreen // txtGreen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtGreen.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtGreen.Location = new System.Drawing.Point(145, 214); txtGreen.Name = "txtGreen"; txtGreen.Size = new System.Drawing.Size(35, 21); txtGreen.TabIndex = 45; txtGreen.Leave += new System.EventHandler(this.txtGreen_Leave); // // txtRed // txtRed.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtRed.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtRed.Location = new System.Drawing.Point(145, 189); txtRed.Name = "txtRed"; txtRed.Size = new System.Drawing.Size(35, 21); txtRed.TabIndex = 44; txtRed.Leave += new System.EventHandler(this.txtRed_Leave); // // txtBrightness // txtBrightness.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtBrightness.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtBrightness.Location = new System.Drawing.Point(49, 239); txtBrightness.Name = "txtBrightness"; txtBrightness.Size = new System.Drawing.Size(35, 21); txtBrightness.TabIndex = 43; txtBrightness.Leave += new System.EventHandler(this.txtBrightness_Leave); // // txtSat // txtSat.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtSat.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtSat.Location = new System.Drawing.Point(49, 214); txtSat.Name = "txtSat"; txtSat.Size = new System.Drawing.Size(35, 21); txtSat.TabIndex = 42; txtSat.Leave += new System.EventHandler(this.txtSat_Leave); // // txtHue // txtHue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtHue.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtHue.Location = new System.Drawing.Point(49, 189); txtHue.Name = "txtHue"; txtHue.Size = new System.Drawing.Size(35, 21); txtHue.TabIndex = 41; txtHue.Leave += new System.EventHandler(this.txtHue_Leave); // // tbAlpha // tbAlpha.Location = new System.Drawing.Point(198, 200); tbAlpha.Maximum = 255; tbAlpha.Name = "tbAlpha"; tbAlpha.Size = new System.Drawing.Size(136, 45); tbAlpha.TabIndex = 54; tbAlpha.TickFrequency = 20; tbAlpha.Value = 255; tbAlpha.ValueChanged += new System.EventHandler(this.tbAlpha_ValueChanged); // // lblAlpha // lblAlpha.AutoSize = true; lblAlpha.Location = new System.Drawing.Point(229, 232); lblAlpha.Name = "lblAlpha"; lblAlpha.Size = new System.Drawing.Size(72, 13); lblAlpha.TabIndex = 55; lblAlpha.Text = "Transparency"; // // colorPanelPending // colorPanelPending.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; colorPanelPending.Color = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); colorPanelPending.Location = new System.Drawing.Point(274, 48); colorPanelPending.Name = "colorPanelPending"; colorPanelPending.PaintColor = true; colorPanelPending.Size = new System.Drawing.Size(60, 34); colorPanelPending.TabIndex = 56; colorPanelPending.Text = "colorPanel1"; // // CustomColorPicker // AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; Controls.Add(this.colorPanelPending); Controls.Add(this.lblAlpha); Controls.Add(this.tbAlpha); Controls.Add(this.rbBlue); Controls.Add(this.rbGreen); Controls.Add(this.rbRed); Controls.Add(this.rbBrightness); Controls.Add(this.rbSat); Controls.Add(this.rbHue); Controls.Add(this.txtBlue); Controls.Add(this.txtGreen); Controls.Add(this.txtRed); Controls.Add(this.txtBrightness); Controls.Add(this.txtSat); Controls.Add(this.txtHue); Controls.Add(this.colorSlider); Controls.Add(this.lblOriginalColor); Controls.Add(this.colorBox); Name = "CustomColorPicker"; Size = new System.Drawing.Size(350, 270); ((System.ComponentModel.ISupportInitialize)(this.tbAlpha)).EndInit(); ResumeLayout(false); PerformLayout(); }
ShowDamage() { colorBox = new ColorBox(); }
public BarController() { CrBox = new ColorBox(); }
public Color[] GetPalette(int paletteSize) { Color[] colors = new Color[paletteSize]; ColorBox[] boxes = new ColorBox[paletteSize]; int boxIndex = 0; ColorBox box; int startIndex = 0; if (_transparentColors.Count > 0) { box = new ColorBox(0); foreach (Color color in _transparentColors) box.Colors.Add(color); box.ShrinkToFit(); boxes[boxIndex] = box; boxIndex++; startIndex++; } //Handle the rest of the boxes box = new ColorBox(0); foreach (Color color in _opaqueColors) box.Colors.Add(color); box.ShrinkToFit(); boxes[boxIndex] = box; boxIndex++; while (boxIndex < paletteSize) { int longestEdge = -1; int longestIndex = startIndex; for (int i = startIndex; i < boxIndex; i++) { if (boxes[i].LongestSide > longestEdge) { longestEdge = boxes[i].LongestSide; longestIndex = i; } } Tuple<ColorBox, ColorBox> newBoxes = boxes[longestIndex].SplitBox(); boxes[longestIndex] = newBoxes.Item1; boxes[boxIndex] = newBoxes.Item2; boxIndex++; } for (int i = 0; i < boxes.Length; i++) colors[i] = boxes[i].GetCentroidColor(); return colors; }
public Material() { crBox = new ColorBox(); }
public Tuple<ColorBox, ColorBox> SplitBox() { byte redLength = (byte)(MaxRed - MinRed); byte blueLength = (byte)(MaxBlue - MinBlue); byte greenLength = (byte)(MaxGreen - MinGreen); ColorBox cb1, cb2; if (redLength >= blueLength && redLength >= greenLength) { cb1 = new ColorBox(MinRed, (byte)(MinRed + (redLength / 2)), MinBlue, MaxBlue, MinGreen, MaxGreen); cb2 = new ColorBox((byte)(MinRed + (redLength / 2)), MaxRed, MinBlue, MaxBlue, MinGreen, MaxGreen); } else if (blueLength >= redLength && blueLength >= greenLength) { cb1 = new ColorBox(MinRed, MaxRed, MinBlue, (byte)(MinBlue + (blueLength / 2)), MinGreen, MaxGreen); cb2 = new ColorBox(MinRed, MaxRed, (byte)(MinBlue + (blueLength / 2)), MaxBlue, MinGreen, MaxGreen); } else { cb1 = new ColorBox(MinRed, MaxRed, MinBlue, MaxBlue, MinGreen, (byte)(MinGreen + (greenLength / 2))); cb2 = new ColorBox(MinRed, MaxRed, MinBlue, MaxBlue, (byte)(MinGreen + (greenLength / 2)), MaxGreen); } foreach (Color color in Colors) { if (cb1.CanContainColor(color)) cb1.Colors.Add(color); else cb2.Colors.Add(color); } cb1.ShrinkToFit(); cb2.ShrinkToFit(); return new Tuple<ColorBox, ColorBox>(cb1, cb2); }
protected override void OnMouseLeave(EventArgs e) { m_HoveredBox = null; m_overdefaultcolor = false; base.OnMouseLeave(e); this.Invalidate(); }
public static ColorBox* FindSplit(ColorBox* boxes, int boxCount, int maxColors, out int axis) { ColorBox* outBox = null; double lBias = 1.0, maxC = 0.0; double val; double rpe, gpe, bpe, ape; //int index = -1; byte* pMin, pMax; ulong* pErr; axis = -1; if ((maxColors <= 16) && (boxCount <= 2)) lBias = (3.0 - boxCount) / (2.0 / 2.66); for (int i = 0; i < boxCount; i++, boxes++) { if (boxes->_volume <= 1) continue; pMin = (byte*)&boxes->_min; pMax = (byte*)&boxes->_max; pErr = &boxes->bError; rpe = boxes->rError * R_SCALE * R_SCALE; gpe = boxes->gError * G_SCALE * G_SCALE; bpe = boxes->bError * B_SCALE * B_SCALE; ape = boxes->aError * A_SCALE * A_SCALE; //for (int x = 0; x < 4; x++) //{ // if (((val = pErr[i]) > maxC) && (pMin[x] < pMax[x])) // { // //index = i; // outBox = boxes; // maxC = val; // axis = x; // } //} if (((lBias * rpe) > maxC) && (pMin[2] < pMax[2])) { outBox = boxes; maxC = lBias * rpe; axis = 2; } if ((gpe > maxC) && (pMin[1] < pMax[1])) { outBox = boxes; maxC = gpe; axis = 1; } if ((bpe > maxC) && (pMin[0] < pMax[0])) { outBox = boxes; maxC = bpe; axis = 0; } if ((ape > maxC) && (pMin[3] < pMax[3])) { outBox = boxes; maxC = ape; axis = 3; } } return outBox; }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button == MouseButtons.Left) { if (m_rectboxs.Contains(e.Location)) { m_SelectedBox = null; foreach (ColorBox box in m_ColorBoxs) { if (box.BoxRectangle.Contains(e.Location)) { m_SelectedBox = box; break; } } //this.Invalidate(); if ((m_SelectedBox != null) && (SelectionChanged != null)) { m_eventArgs.SelectedColor = m_SelectedBox.BoxColor; SelectionChanged(this, m_eventArgs); } } else if (m_rectdefaultcolor.Contains(e.Location)) { m_SelectedBox = null; //this.Invalidate(); if (SelectionChanged != null) { m_eventArgs.SelectedColor = m_DefaultColor; SelectionChanged(this, m_eventArgs); } } } }
public void Split(ColorBox* newBox, int axis) { ColorBox* box = _rootEntry->_box; ColorEntry* current, next; //Get limit from halfError int limit = ((byte*)&box->_halfError)[axis]; for (current = _rootEntry->_next; current != _rootEntry; current = next) { next = current->_next; if (((byte*)¤t->_color)[axis] > limit) { //Remove from current box current->Remove(); //Add to end of new box newBox->_rootEntry->InsertPrev(current); } } }
private void ProcessKeyDownEvent() { if (m_HoveredBox == null) { m_HoveredBox = m_ColorBoxs[0]; } else { if ((m_HoveredBox.Index + MAX_COLS) < m_ColorBoxs.Count) { m_HoveredBox = m_ColorBoxs[m_HoveredBox.Index + MAX_COLS]; } } Invalidate(); }
void findRepresentativeColors(int K, ColorHistogram colorHist) { imageColors = new ColorNode[K]; for (int i = 0; i < K; i++) { int rgb = colorHist.getColor(i); int cnt = colorHist.getCount(i); imageColors[i] = new ColorNode(rgb, cnt); } //if (K <= qnum_list[0]) // image has fewer colors than Kmax // rCols = imageColors; //else { ColorBox initialBox = new ColorBox(0, K - 1, 0, imageColors); List<ColorBox> colorSet = new List<ColorBox>(); colorSet.Add(initialBox); int k = 1; for (int i = 0; i < qnum_list.Count; i++) { int Kmax = qnum_list[i]; bool done = false; while (k < Kmax && !done) { ColorBox nextBox = findBoxToSplit(colorSet); if (nextBox != null) { ColorBox newBox = nextBox.splitBox(); colorSet.Add(newBox); k = k + 1; } else { done = true; } } quantColors_list.Add(averageColors(colorSet,i)); } } colorHist = null; GC.Collect(); }
private void ProcessKeyRightEvent() { if (m_HoveredBox == null) { m_HoveredBox = m_ColorBoxs[0]; } else { //ColorBox index is zero based //Anything after if ((m_HoveredBox.Index + 1) < m_ColorBoxs.Count) { m_HoveredBox = m_ColorBoxs[m_HoveredBox.Index + 1]; } else //Start from beginning { m_HoveredBox = m_ColorBoxs[0]; } } Invalidate(); }
// Split this color box at the median point along its // longest color dimension public ColorBox splitBox() { if (this.colorCount() < 2) // this box cannot be split return null; else { // find longest dimension of this box: int dim = getLongestColorDimension(); // find median along dim int med = findMedian(dim); // now split this box at the median return the resulting new // box. int nextLevel = level + 1; ColorBox newBox = new ColorBox(med + 1, upper, nextLevel, imageColors); this.upper = med; this.level = nextLevel; this.trim(); return newBox; } }
/// <summary> /// Initializes a new instance of the <see cref="LightColorPicker" /> class. /// </summary> /// <param name="component"> /// The component. /// </param> public LightColorPicker2(MenuColor component) : base(component) { Hsl tempHsl; this.colorBox = new ColorBox(new Size(200, 200)) { Hsl = Utilities.RgbToHsl(this.Component.Color.ToSystemColor()) }; this.verticalColorSlider = new VerticalColorSlider(new Size(40, 200)) { CbHsl = Utilities.RgbToHsl(this.Component.Color.ToSystemColor()) }; this.verticalColorSlider.ColorSliderScroll += () => { tempHsl = this.colorBox.Hsl; tempHsl.H = this.verticalColorSlider.CbHsl.H; this.colorBox.Hsl = tempHsl; }; this.verticalAlphaSlider = new VerticalAlphaSlider(new Size(40, 200)); tempHsl = this.verticalAlphaSlider.CbHsl; tempHsl.L = this.colorBox.Hsl.L; this.verticalAlphaSlider.CbHsl = tempHsl; this.verticalAlphaSlider.AlphaSliderScroll += () => { tempHsl = this.colorBox.Hsl; tempHsl.L = this.verticalAlphaSlider.CbHsl.L; this.colorBox.Hsl = tempHsl; }; }
// Start is called before the first frame update void Start() { ColorBox crBox = new ColorBox(); GetComponent <Renderer>().material.color = crBox.SetColorWithRGB(red, green, blue); }
static ColorBox[] DoCut(ColorBox box, int[] partialSum, int[] lookAheadSum, int total, char color) { int dim1 = 0, dim2 = 0; switch (color) { case 'r': dim1 = box.R1; dim2 = box.R2; break; case 'g': dim1 = box.G1; dim2 = box.G2; break; case 'b': dim1 = box.B1; dim2 = box.B2; break; } for (int i = dim1; i <= dim2; i++) { if (partialSum[i] > (total / 2)) { ColorBox box1 = box.Copy(), box2 = box.Copy(); int left = i - dim1, right = dim2 - i, d2; if (left <= right) { d2 = Math.Min(dim2 - 1, ~~(i + right / 2)); } else { d2 = Math.Max(dim1, ~~(i - 1 - left / 2)); } while (partialSum[d2] == 0) { d2++; } int count2 = lookAheadSum[d2]; while (count2 == 0 && partialSum[d2 - 1] > 0) { count2 = lookAheadSum[--d2]; } switch (color) { case 'r': box1.R2 = d2; box2.R1 = d2 + 1; break; case 'g': box1.G2 = d2; box2.G1 = d2 + 1; break; case 'b': box1.B2 = d2; box2.B1 = d2 + 1; break; } //Console.WriteLine("cbox counts: " + (box.GetCount()) + ", " + (box1.GetCount()) + ", " + (box2.GetCount())); return(new ColorBox[2] { box1, box2 }); } } return(null); }
internal void SetDefaultBackgroundColorBox(ColorBox colorBox) { _selectedBackgroundColor = colorBox; PclsMainWindowController.PclsMainWindowView.SelectedColorViewBox.Children.Clear(); PclsMainWindowController.PclsMainWindowView.SelectedColorViewBox.Children.Add(new ColorBox(_selectedBackgroundColor.GetColor())); }