Beispiel #1
0
        // New
        private void btnAddNewPoint_Click(object sender, EventArgs e)
        {
            Data.Gradient gradient = getCurrentGradient();

            float newPointsPosition = 0.5f;

            Data.Key rightestSelPoint = Utils.GetRightestKey(selection.Keys);
            if (rightestSelPoint != null)
            {
                // check if there is an unselected point to the right on the same color curve as the rightest point
                Data.Key rightNeighbour = gradient.FindFirstKeyRightOf(rightestSelPoint);

                if (rightNeighbour != null)
                {
                    newPointsPosition = (rightestSelPoint.Position.X + rightNeighbour.Position.X) * 0.5f;
                }
            }


            //create point
            Data.Key[] newKeys = gradient.AddKeysAtPositionX(newPointsPosition, Color.FromArgb(255, 50, 150, 250));

            // select new point
            selection.Clear();
            selection.AddKeys(newKeys);

            ShowGradientPoint(selection, false, true);
            graphViewHandler.RefreshPicture();
        }
        // Functions
        private void RefreshGradientCbo(Data.Gradient point)
        {
            Object entry = cboGradients.SelectedItem;

            cboGradients.Items.Remove(point);
            cboGradients.Items.Add(point);
            cboGradients.SelectedItem = entry;
        }
        // New
        private void btnNewGradient_Click(object sender, EventArgs e)
        {
            Data.Gradient newGradient = Data.Gradient.CreateDefaultGradient();
            gradients.Add(newGradient);
            cboGradients.Items.Add(newGradient); // TODO check if this triggers and event, it should not trigger an event

            ShowGradient(newGradient);
        }
        private void txtName_TextChanged(object sender, EventArgs e)
        {
            TextBox textBox = (TextBox)sender;

            Data.Gradient gradient = getCurrentGradient();

            gradient.name    = textBox.Text;
            updatingGradient = true;
            RefreshGradientCbo(getCurrentGradient());
            updatingGradient = false;
        }
        // Show gradient (move values into controls)
        private void FillGradientControls(Data.Gradient gradient)
        {
            if (gradient == null)
            {
                return;
            }

            // textbox
            txtName.Text = gradient.name;

            // Fill PointGrid
            updatingPoint = true;
            PointGridHandler.RefillGridPoints(grdPoints, gradient);
            PointGridHandler.SelectfirstGridRowsCells(grdPoints);
            PointGridHandler.SelectInformationFromCells(grdPoints, selection);
            updatingPoint = false;
            ShowGradientPoint(selection, false);
        }
Beispiel #6
0
        // Delete
        private void btnDeleteGradientPoint_Click(object sender, EventArgs e)
        {
            Data.Gradient gradient = getCurrentGradient();

            if (selection.Keys.Length == 0)
            {
                return;
            }

            foreach (Data.Key key in selection.Keys)
            {
                gradient.DeleteKey(key);
            }


            selection.Clear();
            ShowGradientPoint(selection, false, true);
            graphViewHandler.RefreshPicture();
        }
        // Show gradient (enable/disable controls)
        private void ShowGradient(Data.Gradient gradient)
        {
            if (gradient == null)
            {
                ForbitEditingGradient();
                return;
            }

            AllowEditingGradient();


            if (((Data.Gradient)cboGradients.SelectedItem) != gradient)
            {
                cboGradients.SelectedItem = gradient; // TODO shoult not trigger an event
            }


            FillGradientControls(gradient);

            colorBand.SetGradient(gradient); // colorBand is plugin of graphViewHandler
            graphViewHandler.SetGraph(gradient.graph);
            graphViewHandler.RefreshPicture();
        }
        // Delete
        private void btnDeleteGradient_Click(object sender, EventArgs e)
        {
            Data.Gradient currentGradient = getCurrentGradient();

            if (currentGradient == null)
            {
                return;
            }

            // remove from list
            gradients.Remove(currentGradient);

            // find combo entry
            int index = cboGradients.Items.IndexOf(currentGradient);


            // remove combo entry
            cboGradients.Items.Remove(currentGradient);

            // select next gradient
            if (index < cboGradients.Items.Count)
            {
                cboGradients.SelectedIndex = index;
            }
            else if (cboGradients.Items.Count > 0)
            {
                cboGradients.SelectedIndex = index - 1;
            }
            else
            {
                cboGradients.SelectedItem = null;// last cbo entry removed
            }


            // show next gradient
            ShowGradient((Data.Gradient)cboGradients.SelectedItem);
        }
Beispiel #9
0
        public static void RefillGridPoints(DataGridView grdPoints, Data.Gradient gradient)
        {
            // fill grid
            grdPoints.Rows.Clear();

            foreach (KeyValuePair <float, LBE.ComboKeyInfo> pos in gradient.getUniqueKeyPositions())
            {
                Data.Key[] r   = pos.Value.keys[Constants.RED];
                Data.Key[] g   = pos.Value.keys[Constants.GREEN];
                Data.Key[] b   = pos.Value.keys[Constants.BLUE];
                string[]   xxx = new string[3];

                xxx[0] = GetCellText(r);
                xxx[1] = GetCellText(g);
                xxx[2] = GetCellText(b);


                int insertPos = grdPoints.Rows.Add(xxx);
                grdPoints.Rows[insertPos].HeaderCell.Value = pos.Key.ToString();
                grdPoints.Rows[insertPos].Cells[0].Tag     = r;
                grdPoints.Rows[insertPos].Cells[1].Tag     = g;
                grdPoints.Rows[insertPos].Cells[2].Tag     = b;
            }
        }
 // Set
 void SetCurrentGradient(Data.Gradient palette)
 {
     ShowGradient(palette);
 }