public void AdjustContents(Size size, ToolBoxOrientation layout) { if (size.Height < Minimum.Height) { return; } _panel.Size = size; _primary.Location = new Point(0, size.Height - PrimaryH); _primary.Size = new Size(size.Width, PrimaryH); if (_second != null) { _second.Size = new Size(size.Width, size.Height - (PrimaryH + DividerH)); _second.AdjustContents(layout); } _primary.AdjustContents(layout); _primary.Draw(); if (_second != null) { _second.Draw(); } }
public ColorPicker(MainForm main, int boxSize, IPalette refPal, int refPalIdx) { _main = main; _sample = new Bitmap(_sampleRect.Width, _sampleRect.Height); //_mode = ColorMode.RGB; _chn = new[] { 1f, 1f, 1f, 1f }; _order = new[] { (int)BGRA.Alpha, (int)BGRA.Red, (int)BGRA.Green, (int)BGRA.Blue }; _labels = new string[nChans]; _labels[(int)BGRA.Red] = "R"; _labels[(int)BGRA.Green] = "G"; _labels[(int)BGRA.Blue] = "B"; _labels[(int)BGRA.Alpha] = "A"; this.Name = "colorPicker"; this.Text = "Color Picker"; int width = boxSize + 200, height = boxSize + 50; bool createPalPanel = refPalIdx < 0; if (createPalPanel) { refPalIdx = 0; _paletteTable = new PalettePanel(this, refPal); _paletteTable.Location = new Point(0, height); _paletteTable.Size = new Size(width, tableH); height += tableH; } this.ClientSize = new Size(width, height); this.FormBorderStyle = FormBorderStyle.FixedSingle; var resources = new ComponentResourceManager(typeof(ColorPicker)); _slider = (Bitmap)(resources.GetObject("slider")); _dot = (Bitmap)(resources.GetObject("dot")); /* * _modeImg = new Bitmap[2]; * _modeImg[(int)ColorMode.RGB] = (Bitmap)(resources.GetObject("rgb")); * _modeImg[(int)ColorMode.HSV] = (Bitmap)(resources.GetObject("hsv")); */ _boxA = new ColorBox(); _boxA.Name = "alphaBox"; _boxA.Location = new Point(20, 20); _boxA.Size = new Size(20, boxSize); _boxA.Paint += this.paintLeftSlider; _boxA.MouseWheel += (s, e) => this.scrollLeftSlider(e.Delta / 120); SetColorBoxClick(_boxA, this.moveLeftSlider); _boxXY = new ColorBox(); _boxXY.Name = "xyBox"; _boxXY.Location = new Point(60, 20); _boxXY.Size = new Size(boxSize, boxSize); _boxXY.Paint += this.paintDot; SetColorBoxClick(_boxXY, this.moveDot); _boxZ = new ColorBox(); _boxZ.Name = "zBox"; _boxZ.Location = new Point(80 + boxSize, 20); _boxZ.Size = new Size(20, boxSize); _boxZ.Paint += this.paintRightSlider; _boxZ.MouseWheel += (s, e) => this.scrollRightSlider(e.Delta / 120); SetColorBoxClick(_boxZ, this.moveRightSlider); _boxSample = new ColorBox(); _boxSample.Name = "sampleBox"; _boxSample.Location = new Point(114 + boxSize, 20 + boxSize - 72); _boxSample.Size = new Size(72, 72); _cycle = new Button(); _cycle.Name = "cycleChans"; _cycle.Location = new Point(114 + boxSize, 20); _cycle.Size = new Size(32, 32); _cycle.Image = (Bitmap)resources.GetObject("cycle"); _cycle.Click += (s, e) => Cycle(); /* * _switchMode = new Button(); * _switchMode.Name = "switchMode"; * _switchMode.Location = new Point(152 + boxSize, 20); * _switchMode.Size = new Size(32, 32); * _switchMode.Image = _modeImg[(int)ColorMode.HSV]; * _switchMode.Click += (s, e) => SwitchMode(); */ _axisLabel = new Label[nChans]; for (int i = 0; i < nChans; i++) { _axisLabel[i] = new Label(); _axisLabel[i].Name = "axisLabel" + i; _axisLabel[i].Font = new Font(Control.DefaultFont, FontStyle.Bold); _axisLabel[i].Size = new Size(15, 20); this.Controls.Add(_axisLabel[i]); } int midY = 13 + (boxSize / 2); _axisLabel[0].Location = new Point(4, midY); _axisLabel[1].Location = new Point(52 + (boxSize / 2), 24 + boxSize); _axisLabel[2].Location = new Point(44, midY); _axisLabel[3].Location = new Point(64 + boxSize, midY); _chnLabel = new Label[nChans]; for (int i = 0; i < nChans; i++) { _chnLabel[i] = new Label(); _chnLabel[i].Name = "chnLabel" + i; _chnLabel[i].Font = new Font(Control.DefaultFont, FontStyle.Bold); _chnLabel[i].Location = new Point(114 + boxSize, 67 + i * 32); _chnLabel[i].Size = new Size(15, 20); this.Controls.Add(_chnLabel[i]); } _chnBox = new TextBox[nChans]; for (int i = 0; i < nChans; i++) { _chnBox[i] = new TextBox(); _chnBox[i].Name = "chnBox" + i; _chnBox[i].Location = new Point(138 + boxSize, 64 + i * 32); _chnBox[i].Size = new Size(45, 20); _chnBox[i].TextChanged += this.updateField; this.Controls.Add(_chnBox[i]); } RefreshInputFields(); this.Controls.Add(_boxA); this.Controls.Add(_boxXY); this.Controls.Add(_boxZ); this.Controls.Add(_boxSample); this.Controls.Add(_cycle); //this.Controls.Add(_switchMode); if (createPalPanel) { this.Controls.Add(_paletteTable); _paletteTable.AdjustContents(ToolBoxOrientation.None); } this.KeyPreview = true; this.KeyUp += (s, e) => ResetIcon(); this.KeyDown += (s, e) => { if (e.KeyCode == Keys.Escape && _paletteTable != null) { _paletteTable.CurrentCell = -1; _paletteTable.Draw(); } }; Utils.ControlFunc updateFormIcon = (ctrl, args) => { ctrl.MouseUp += (s, e) => ResetIcon(); return(null); }; Utils.ApplyRecursiveControlFunc(this, updateFormIcon); SelectColorFrom(refPal, refPalIdx); ResetIcon(); }