public static Gtk.Window Create()
        {
            HBox        options      = new HBox(false, 0);
            CheckButton check_button = null;

            window = new ColorSelectionDialog("Color selection dialog");
            window.ColorSelection.HasOpacityControl = true;
            window.ColorSelection.HasPalette        = true;

            window.SetDefaultSize(250, 200);
            window.ContentArea.PackStart(options, false, false, 0);
            window.ContentArea.BorderWidth = 10;

            check_button        = new CheckButton("Show Opacity");
            check_button.Active = true;
            options.PackStart(check_button, false, false, 0);
            check_button.Toggled += new EventHandler(Opacity_Callback);

            check_button        = new CheckButton("Show Palette");
            check_button.Active = true;
            options.PackEnd(check_button, false, false, 0);
            check_button.Toggled += new EventHandler(Palette_Callback);

            window.ColorSelection.ColorChanged += new EventHandler(Color_Changed);
            window.OkButton.Clicked            += new EventHandler(Color_Selection_OK);
            window.CancelButton.Clicked        += new EventHandler(Color_Selection_Cancel);

            options.ShowAll();

            return(window);
        }
Example #2
0
 private void ColorSelection_Click(object sender, System.EventArgs e)
 {
     using (var colorDialog = new ColorSelectionDialog(Relation)) {
         colorDialog.FormClosing += new FormClosingEventHandler(colorDialog_FormClosing);
         colorDialog.ShowDialog();
     }
 }
Example #3
0
        private void PickColor()
        {
            if (selectedEntry == null)
            {
                return;
            }

            var dlg = new ColorSelectionDialog("Pick a color");

            dlg.ColorSelection.HasOpacityControl = true;
            dlg.ColorSelection.CurrentColor      = new Gdk.Color(selectedEntry.Color.R, selectedEntry.Color.G, selectedEntry.Color.B);
            dlg.ColorSelection.CurrentAlpha      = ToGdkColor(selectedEntry.Color.A);
            dlg.Modal = true;

            dlg.Response += delegate(object o, ResponseArgs args)
            {
                if (args.ResponseId == ResponseType.Ok)
                {
                    var newColor = new Color(
                        FromGdkColor(dlg.ColorSelection.CurrentColor.Red),
                        FromGdkColor(dlg.ColorSelection.CurrentColor.Green),
                        FromGdkColor(dlg.ColorSelection.CurrentColor.Blue),
                        FromGdkColor(dlg.ColorSelection.CurrentAlpha));

                    selectedEntry = ReplaceEntry(selectedEntry, newColor);
                }
            };

            dlg.Run();
            dlg.Destroy();
        }
Example #4
0
    protected void On_ColorAction_Activated(object sender, EventArgs e)
    {
        ColorSelectionDialog colorDlg = new ColorSelectionDialog("Select Color");

        colorDlg.SetDefaultSize(300, 220);
        //if click ok
        if (colorDlg.Run() == (int)ResponseType.Ok)
        {
            //get color
            Gdk.Color selectColor = colorDlg.ColorSelection.CurrentColor;

            //set color_tag
            color_tag.ForegroundGdk = selectColor;

            //if user selected some text
            //change selected text color
            //else change all text color
            TextIter start, end;
            if (TextView.Buffer.GetSelectionBounds(out start, out end))
            {
                TextView.Buffer.ApplyTag(color_tag, start, end);
            }
            else
            {
                TextView.ModifyText(StateType.Normal, selectColor);
            }
        }
        //destory window
        colorDlg.Destroy();
    }
Example #5
0
        protected void OnButtonUndelineColorClicked(object sender, EventArgs e)
        {
            ColorSelectionDialog dlg_color = new ColorSelectionDialog("Select color");

            dlg_color.Response += delegate(object o, ResponseArgs resp)
            {
                if (resp.ResponseId == ResponseType.Ok)
                {
                    underline_color_selected = dlg_color.ColorSelection.CurrentColor;
                    string rgb = underline_color_selected.ToString();
                    ApplyTextTags(textviewDemoText.Buffer, "underlinecolor:" + rgb);
                }
                if (resp.ResponseId == ResponseType.Cancel)
                {
                }
                if (resp.ResponseId == ResponseType.Close)
                {
                }
            };

            dlg_color.Run();
            dlg_color.Destroy();

            return;
        }
Example #6
0
    public static OSMP.Color GetColor()
    {
        ColorSelectionDialog colorselectiondialog = new ColorSelectionDialog("Choose color:");
        ResponseType         response             = (ResponseType)colorselectiondialog.Run();

        //colorselectiondialog.

        OSMP.Color newcolor = null;
        if (response == ResponseType.Ok)
        {
            LogFile.WriteLine(colorselectiondialog);
            LogFile.WriteLine(colorselectiondialog.ColorSelection);
            LogFile.WriteLine(colorselectiondialog.ColorSelection.CurrentColor.Red.ToString() + " " +
                              colorselectiondialog.ColorSelection.CurrentColor.Green.ToString() + " " +
                              colorselectiondialog.ColorSelection.CurrentColor.Blue.ToString());
            Gdk.Color newgtkcolor = colorselectiondialog.ColorSelection.CurrentColor;
            newcolor = new OSMP.Color(newgtkcolor.Red / (double)65536,
                                      newgtkcolor.Green / (double)65536,
                                      newgtkcolor.Blue / (double)65536);
        }
        else
        {
            LogFile.WriteLine("cancel pressed");
        }

        colorselectiondialog.Hide();
        return(newcolor);
    }
        //Get colorSetting from color selected
        private void ColorElementExecuted(object param)
        {
            //Model.ColorSettings();
            ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog();

            colorSelectionDialog.Show();
            RvtColorElement             = colorSelectionDialog.SelectedColor;
            _ColorSettings.ColorElement = RvtColorElement;
        }
Example #8
0
    public void OnFontColorActivate(object o, EventArgs args)
    {
        ColorSelectionDialog fontColorDialog = new ColorSelectionDialog("RSVP Color");

        fontColorDialog.ColorSelection.CurrentColor = fontColor;
        fontColorDialog.ColorSelection.HasPalette   = true;
        fontColorDialog.Run();
        fontColor = fontColorDialog.ColorSelection.CurrentColor;
        ShowWord(curWord);
        fontColorDialog.Destroy();
    }
Example #9
0
    public void OnBackgroundColorActivate(object o, EventArgs args)
    {
        ColorSelectionDialog backgroundColorDialog = new ColorSelectionDialog("RSVP Background Color");

        backgroundColorDialog.ColorSelection.CurrentColor = backgroundColor;
        backgroundColorDialog.ColorSelection.HasPalette   = true;
        backgroundColorDialog.Run();
        backgroundColor = backgroundColorDialog.ColorSelection.CurrentColor;
        ShowWord(curWord);
        backgroundColorDialog.Destroy();
    }
 public void CustomColorResponded(object o, ResponseArgs response)
 {
     if (o is ColorSelectionDialog)
     {
         ColorSelectionDialog d = o as ColorSelectionDialog;
         if (response.ResponseId == ResponseType.Ok)
         {
             ImageMenuItem item =
                 AddCustomColor(d.ColorSelection.CurrentColor);
             item.Activate();
         }
         d.Destroy();
     }
 }
    public void MoreColorsActivated(object o, EventArgs ev)
    {
        ColorSelectionDialog colorSel =
            new ColorSelectionDialog("Select Color");

        if (IconWidget is ColorBlockWidget)
        {
            colorSel.ColorSelection.CurrentColor =
                (IconWidget as ColorBlockWidget).Color;
        }

        // TODO: Add support for opacity as Handwriting supports this
        colorSel.ColorSelection.HasOpacityControl = false;
        colorSel.Response += CustomColorResponded;
        colorSel.Run();
    }
Example #12
0
        public void OpenPicker(object eventBox, ButtonPressEventArgs args)
        {
            ColorSelectionDialog dialog = new ColorSelectionDialog("Pick new color for faction.");

            dialog.ColorSelection.PreviousColor = dialog.ColorSelection.CurrentColor = (Gdk.Color)property.GetValue(obj);
            dialog.Response += delegate(object o, ResponseArgs response) {
                if (response.ResponseId == ResponseType.Ok)
                {
                    property.SetValue(obj, dialog.ColorSelection.CurrentColor);
                    DependencyManager.Flag((IDependable)obj);
                    DependencyManager.TriggerAllFlags();
                }
            };
            dialog.Run();
            dialog.Destroy();
        }
Example #13
0
        public void ShowColorChooser()
        {
            using (var chooser = new ColorSelectionDialog("change color"))
            {
                //chooser.TransientFor=this;
                chooser.Style = OriginalStyle;

                if (chooser.Run() == (int)ResponseType.Ok)
                {
                    AppConfig.JawColor = new Color(chooser.ColorSelection.CurrentColor);
                    AppConfig.Save();
                    SetContrastColor(AppConfig.JawColor);
                }
                chooser.Hide();
            }
        }
Example #14
0
        void colorDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            ColorSelectionDialog dialog = sender as ColorSelectionDialog;

            if (dialog == null)
            {
                return;
            }

            if (dialog.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            Relation = dialog.Relation;
        }
Example #15
0
        public override void LaunchDialogue()
        {
            ColorSelectionDialog dialog = new ColorSelectionDialog("Select a new color");

            dialog.ColorSelection.CurrentColor = GetColor();
            dialog.Run();
            dialog.Destroy();

            int red   = (int)(255 * (float)dialog.ColorSelection.CurrentColor.Red / ushort.MaxValue);
            int green = (int)(255 * (float)dialog.ColorSelection.CurrentColor.Green / ushort.MaxValue);
            int blue  = (int)(255 * (float)dialog.ColorSelection.CurrentColor.Blue / ushort.MaxValue);

            System.Drawing.Color color = System.Drawing.Color.FromArgb(red, green, blue);
            //TODO: Property.Converter.ConvertFrom() fails: why?
            parentRow.PropertyValue = color;
        }
        private void ChangeColorCallback(object o, EventArgs args)
        {
            using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog("Changing color")) {
                colorSelectionDialog.TransientFor = this;
                colorSelectionDialog.ColorSelection.SetPreviousRgba(color);
                colorSelectionDialog.ColorSelection.CurrentRgba = color;
                colorSelectionDialog.ColorSelection.HasPalette  = true;

                if (colorSelectionDialog.Run() == (int)ResponseType.Ok)
                {
                    color = colorSelectionDialog.ColorSelection.CurrentRgba;
                    drawingArea.OverrideBackgroundColor(StateFlags.Normal, color);
                }

                colorSelectionDialog.Hide();
            }
        }
Example #17
0
        private void ChangeColorCallback(object o, EventArgs args)
        {
            using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog("Changing color")) {
                colorSelectionDialog.TransientFor = this;
                colorSelectionDialog.ColorSelection.PreviousColor = color;
                colorSelectionDialog.ColorSelection.CurrentColor  = color;
                colorSelectionDialog.ColorSelection.HasPalette    = true;

                if (colorSelectionDialog.Run() == (int)ResponseType.Ok)
                {
                    Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
                    drawingArea.ModifyBg(StateType.Normal, selected);
                }

                colorSelectionDialog.Hide();
            }
        }
Example #18
0
        public static void Main(string[] args)
        {
            Application.Init();
            ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog("Colourizmus S+");

            colorSelectionDialog.Close       += CloseProgram;
            colorSelectionDialog.DeleteEvent += CloseProgram;

            colorSelectionDialog.OkButton.Clicked += CopyToClipboard;

            colorSelectionDialog.CancelButton.Hide();
            colorSelectionDialog.OkButton.Label = "Copy to clipboard";

            _colorSelection = colorSelectionDialog.ColorSelection;
            _colorSelection.ColorChanged += CopyToClipboard;

            colorSelectionDialog.Show();
            Application.Run();
        }
Example #19
0
        /// <summary>

        /// Shows a dialog box to select a color

        /// </summary>

        /// <returns>The color.</returns>

        static public QuickGTKColor SelectColor()

        {
            ColorSelection ret = null;

            ColorSelectionDialog cdia = new ColorSelectionDialog("Select color");

            cdia.Response += delegate(object o, ResponseArgs resp)

            {
                if (resp.ResponseId == ResponseType.Ok)

                {
                    ret = cdia.ColorSelection; //.CurrentColor;
                }
            };

            cdia.Run();

            cdia.Destroy();

            return(new QuickGTKColor(ret));
        }
        public PropertyGridTable()
        {
            Build();

            items     = new List <TreeItem> ();
            pitems    = new List <TreeItem> ();
            eitems    = new List <EventItem> ();
            nulliter  = new TreeIter();
            sortgroup = true;

            var column1 = new TreeViewColumn();

            column1.Sizing     = TreeViewColumnSizing.Fixed;
            column1.FixedWidth = 100;
            column1.Resizable  = true;
            column1.Title      = "Name";

            var textCell1 = new CellRendererText();

            textCell1.Underline = Pango.Underline.Single;
            column1.PackStart(textCell1, false);

            var textCell2 = new CellRendererText();

            column1.PackStart(textCell2, false);

            var idCell = new CellRendererText();

            idCell.Visible = false;
            column1.PackStart(idCell, false);

            treeview1.AppendColumn(column1);

            var column2 = new TreeViewColumn();

            column2.Sizing    = TreeViewColumnSizing.Fixed;
            column2.Resizable = true;
            column2.Title     = "Value";

            var editTextCell = new CellRendererText();

            editTextCell.Edited += delegate(object o, EditedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected(out model, out iter))
                {
                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for (int i = 0; i < eitems.Count; i++)
                    {
                        if (eitems[i].id == id)
                        {
                            if (eitems[i].eventHandler != null)
                            {
                                var fwidget = new FalseWidget(args.NewText);
                                eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                model.SetValue(iter, 4, args.NewText);
                                break;
                            }
                        }
                    }
                }
            };

            column2.PackStart(editTextCell, false);

            var editTextCell2 = new CellRendererText();
            editTextCell2.Editable        = true;
            editTextCell2.EditingStarted += delegate {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected(out model, out iter))
                {
                    var dialog = new CollectionEditorDialog(window, model.GetValue(iter, 14).ToString());
                    if (dialog.Run() == (int)ResponseType.Ok)
                    {
                        int id = Convert.ToInt32(model.GetValue(iter, 11));

                        for (int i = 0; i < eitems.Count; i++)
                        {
                            if (eitems[i].id == id)
                            {
                                if (eitems[i].eventHandler != null)
                                {
                                    var fwidget = new FalseWidget(dialog.text);
                                    eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                    model.SetValue(iter, 14, dialog.text);
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            column2.PackStart(editTextCell2, false);

            var editTextCell4 = new CellRendererText();
            editTextCell4.Editable        = true;
            editTextCell4.EditingStarted += delegate {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected(out model, out iter))
                {
                    var col      = new Microsoft.Xna.Framework.Color();
                    int response = (int)ResponseType.Reject;

                    if (Global.GtkMajorVersion < 3 || (Global.GtkMajorVersion == 3 && Global.GtkMinorVersion < 3))
                    {
                        var dialog = new ColorSelectionDialog("Color Chooser");
                        dialog.TransientFor = window;
                        dialog.ColorSelection.HasPalette        = true;
                        dialog.ColorSelection.HasOpacityControl = true;

                        try
                        {
                            string[] cvalues = model.GetValue(iter, 15).ToString().Replace(":", " ").Replace("}", " ").Split(' ');

                            byte red   = (byte)Convert.ToInt16(cvalues [1]);
                            byte green = (byte)Convert.ToInt16(cvalues [3]);
                            byte blue  = (byte)Convert.ToInt16(cvalues [5]);
                            int  alpha = Convert.ToInt32(cvalues [7]);

                            dialog.ColorSelection.CurrentColor = new Gdk.Color(red, green, blue);
                            dialog.ColorSelection.CurrentAlpha = (ushort)(alpha * 257);
                        }
                        catch { }

                        response = dialog.Run();

                        col.R = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Red);
                        col.G = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Green);
                        col.B = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Blue);
                        col.A = (byte)(dialog.ColorSelection.CurrentAlpha / 257);

                        dialog.Destroy();
                    }
                    else
                    {
                        #if LINUX
                        Gdk.RGBA rgba = new Gdk.RGBA();

                        try
                        {
                            string[] cvalues = model.GetValue(iter, 15).ToString().Replace(":", " ").Replace("}", " ").Split(' ');
                            rgba.Parse("rgba(" + cvalues [1] + "," + cvalues [3] + "," + cvalues [5] + "," + cvalues [7] + ")");
                        }
                        catch { }

                        var dialog = new ColorChooserDialog(window, "Color Chooser");
                        dialog.ColorChooser.CurrentRgba = rgba;
                        response = (int)dialog.Run();

                        rgba = dialog.ColorChooser.CurrentRgba;
                        dialog.Destroy();

                        string[] split = rgba.ToString().Split('(', ')')[1].Split(',');

                        col.R = (byte)Convert.ToInt32(split[0]);
                        col.G = (byte)Convert.ToInt32(split[1]);
                        col.B = (byte)Convert.ToInt32(split[2]);

                        if (split.Length == 4)
                        {
                            col.A = (byte)Convert.ToInt32(double.Parse(split[3]) * 255);
                        }
                        else
                        {
                            col.A = 255;
                        }
                        #endif
                    }

                    if (response == (int)ResponseType.Ok)
                    {
                        int id = Convert.ToInt32(model.GetValue(iter, 11));

                        for (int i = 0; i < eitems.Count; i++)
                        {
                            if (eitems[i].id == id)
                            {
                                if (eitems[i].eventHandler != null)
                                {
                                    var fwidget = new FalseWidget(col.ToString());
                                    eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                    model.SetValue(iter, 15, col.ToString());
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            column2.PackStart(editTextCell4, false);

            var editTextCell3 = new CellRendererText();
            editTextCell3.Visible = false;
            column2.PackStart(editTextCell3, false);

            var comboCell = new CellRendererCombo();
            comboCell.TextColumn = 0;
            comboCell.IsExpanded = true;
            comboCell.Editable   = true;
            comboCell.HasEntry   = false;
            comboCell.Edited    += delegate(object o, EditedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected(out model, out iter))
                {
                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for (int i = 0; i < eitems.Count; i++)
                    {
                        if (eitems[i].id == id)
                        {
                            if (eitems[i].eventHandler != null && args.NewText != null && args.NewText != "")
                            {
                                var fwidget = new FalseWidget(args.NewText);
                                eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                model.SetValue(iter, 8, args.NewText);
                                break;
                            }
                        }
                    }
                }
            };

            column2.PackStart(comboCell, false);

            var editFilePathCell = new CellRendererText();
            editFilePathCell.Editable        = true;
            editFilePathCell.EditingStarted += delegate(object o, EditingStartedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected(out model, out iter))
                {
                    var dialog     = new CustomFolderDialog(window, model.GetValue(iter, 17).ToString());
                    var responseid = dialog.Run();
                    var fileName   = dialog.FileName;
                    dialog.Destroy();

                    if (responseid != (int)ResponseType.Ok)
                    {
                        return;
                    }

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for (int i = 0; i < eitems.Count; i++)
                    {
                        if (eitems[i].id != id || eitems[i].eventHandler == null)
                        {
                            continue;
                        }

                        var fwidget = new FalseWidget(fileName);
                        eitems[i].eventHandler(fwidget, EventArgs.Empty);
                        model.SetValue(iter, 17, fileName);

                        break;
                    }
                }
            };
            column2.PackStart(editFilePathCell, false);

            treeview1.AppendColumn(column2);

            column1.AddAttribute(textCell1, "text", 0);
            column1.AddAttribute(textCell1, "visible", 1);
            column1.AddAttribute(textCell2, "text", 2);
            column1.AddAttribute(textCell2, "visible", 3);
            column2.AddAttribute(editTextCell, "text", 4);
            column2.AddAttribute(editTextCell, "visible", 5);
            column2.AddAttribute(editTextCell, "editable", 6);
            column2.AddAttribute(comboCell, "model", 7);
            column2.AddAttribute(comboCell, "text", 8);
            column2.AddAttribute(comboCell, "editable", 9);
            column2.AddAttribute(comboCell, "visible", 10);
            column1.AddAttribute(idCell, "text", 11);
            column2.AddAttribute(editTextCell2, "text", 12);
            column2.AddAttribute(editTextCell2, "visible", 13);
            column2.AddAttribute(editTextCell3, "text", 14);
            column2.AddAttribute(editTextCell4, "text", 15);
            column2.AddAttribute(editTextCell4, "visible", 16);
            column2.AddAttribute(editFilePathCell, "text", 17);
            column2.AddAttribute(editFilePathCell, "visible", 18);

            listStore       = new TreeStore(typeof(string), typeof(bool), typeof(string), typeof(bool), typeof(string), typeof(bool), typeof(bool), typeof(TreeStore), typeof(string), typeof(bool), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(bool));
            treeview1.Model = listStore;
        }
Example #21
0
        /// <summary>
        /// Initialices window's controls and widgets
        /// </summary>
        private void InitializeComponents()
        {
            Padding     = 30;
            PaddingSets = 10;

            MinValue  = 0;
            ColorSets = new Dictionary <string, Cairo.Color>();

            data = new Dictionary <string, List <BarData> >();
            data.Add("Default", new List <BarData>());

            IconosLeyenda = new Dictionary <string, Cairo.Rectangle>();

            this.swScroll = new Gtk.ScrolledWindow();

            // Drawing area
            this.drawingArea = new Gtk.DrawingArea();
            this.drawingArea.ModifyBg(StateType.Normal, new Gdk.Color(255, 255, 255));
            this.drawingArea.ExposeEvent += (o, args) => this.OnExposeDrawingArea();

            //Create the system of events to control de drag and move chart,and other funcionalities
            this.drawingArea.AddEvents((int)Gdk.EventMask.ButtonPressMask);
            this.drawingArea.AddEvents((int)Gdk.EventMask.ButtonReleaseMask);
            this.drawingArea.AddEvents((int)Gdk.EventMask.PointerMotionMask);
            this.drawingArea.ButtonPressEvent += delegate(object o, ButtonPressEventArgs args)
            {
                String setPulsado = GetLegendIconPressed(args);
                if (setPulsado != null)
                {
                    ColorSelectionDialog cdia = new ColorSelectionDialog("Selecciona un Color");
                    cdia.Response += delegate(object ob, ResponseArgs resp)
                    {
                        if (resp.ResponseId == ResponseType.Ok)
                        {
                            Gdk.Color c = cdia.ColorSelection.CurrentColor;

                            ColorSets[setPulsado] = ToCairoColor(c);
                            drawingArea.QueueDraw();
                        }
                    };

                    cdia.Run();
                    cdia.Destroy();
                }
                else
                {
                    drawingArea.QueueDraw();
                }
            };
            this.drawingArea.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args)
            {
                drawingArea.QueueDraw();
            };

            //Control buttons for the resolution of the chart
            menosPadd          = new Button("<");
            menosPadd.Clicked += (sender, e) =>
            {
                if (PaddingSets >= 20)
                {
                    PaddingSets -= 20;
                    drawingArea.QueueDraw();
                }
            };

            masPadd          = new Button(">");
            masPadd.Clicked += (sender, e) =>
            {
                PaddingSets += 20;
                drawingArea.QueueDraw();
            };

            //Control buttons for the resolution of the chart
            menosRes          = new Button("-");
            menosRes.Clicked += (sender, e) =>
            {
                if (this.ValueResolution > 2)
                {
                    ValueResolution--;
                    drawingArea.QueueDraw();
                }
            };

            masRes          = new Button("+");
            masRes.Clicked += (sender, e) =>
            {
                ValueResolution++;
                drawingArea.QueueDraw();
            };

            showGrid          = new CheckButton("Grid");
            showGrid.Active   = ShowGridLines;
            showGrid.Clicked += (object sender, EventArgs e) =>
            {
                this.ShowGridLines = ((CheckButton)sender).Active;
                this.drawingArea.QueueDraw();
            };
            showLegend          = new CheckButton("Leyenda");
            showLegend.Active   = ShowLegend;
            showLegend.Clicked += (object sender, EventArgs e) =>
            {
                this.ShowLegend = ((CheckButton)sender).Active;
                this.drawingArea.QueueDraw();
            };
        }
Example #22
0
        /// <summary>
        /// Initialices window's controls and widgets
        /// </summary>
        private void InitializeComponents()
        {
            XLabel = "X Axis";
            YLabel = "Y Axis";

            Padding = 30;

            MinXValue = 0;
            MinYValue = 0;

            MaxXValue = 100;
            MaxYValue = 100;

            YResolution = 5;
            XResolution = 5;

            ColorSets = new Dictionary <string, Cairo.Color>();

            data = new Dictionary <string, List <LineData> >();

            data.Add("Default", new List <LineData>());

            IconosLeyenda = new Dictionary <string, Cairo.Rectangle>();

            this.swScroll = new Gtk.ScrolledWindow();

            // Drawing area
            this.drawingArea = new Gtk.DrawingArea();
            this.drawingArea.ModifyBg(StateType.Normal, new Gdk.Color(255, 255, 255));
            this.drawingArea.ExposeEvent += (o, args) => this.OnExposeDrawingArea();

            //Create the system of events to control de drag and move chart,and other funcionalities
            this.drawingArea.AddEvents((int)Gdk.EventMask.ButtonPressMask);
            this.drawingArea.AddEvents((int)Gdk.EventMask.ButtonReleaseMask);
            this.drawingArea.AddEvents((int)Gdk.EventMask.PointerMotionMask);
            this.drawingArea.ButtonPressEvent += delegate(object o, ButtonPressEventArgs args)
            {
                String setPulsado = GetLegendIconPressed(args);
                if (setPulsado != null)
                {
                    ColorSelectionDialog cdia = new ColorSelectionDialog("Selecciona un Color");
                    cdia.Response += delegate(object ob, ResponseArgs resp)
                    {
                        if (resp.ResponseId == ResponseType.Ok)
                        {
                            Gdk.Color c = cdia.ColorSelection.CurrentColor;

                            ColorSets[setPulsado] = ToCairoColor(c);
                            drawingArea.QueueDraw();
                        }
                    };

                    cdia.Run();
                    cdia.Destroy();
                }
                else
                {
                    pulsado = true;
                    drawingArea.QueueDraw();
                }
            };
            this.drawingArea.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args)
            {
                pulsado = false;
                drawingArea.QueueDraw();
            };

            // Modifing the Max and Min values When cursor moves, change the chart values showed
            this.drawingArea.MotionNotifyEvent += (object o, MotionNotifyEventArgs args) =>
            {
                if (pulsado)
                {
                    MinXValue -= (args.Event.X - xAnterior);
                    MaxXValue -= (args.Event.X - xAnterior);
                    xAnterior  = args.Event.X;

                    MinYValue += (args.Event.Y - yAnterior);
                    MaxYValue += (args.Event.Y - yAnterior);
                    yAnterior  = args.Event.Y;

                    drawingArea.QueueDraw();
                }
                else
                {
                    xAnterior = args.Event.X;
                    yAnterior = args.Event.Y;
                }
            };

            //Zoom in and Zoom out in chart, its made modifing the Min an Max values of the axis
            zoomIN          = new Button("-");
            zoomIN.Clicked += (sender, e) =>
            {
                int width  = 0;
                int height = 0;
                drawingArea.GdkWindow.GetSize(out width, out height);
                double Xdiference = (MaxXValue - MinXValue) * 0.25;
                double Ydiference = (MaxYValue - MinYValue) * 0.25;
                if (!FixedX)
                {
                    MaxXValue += Xdiference;
                    //MinXValue -= Xdiference;
                }
                MaxYValue += Ydiference;
                //MinYValue -= Ydiference;

                drawingArea.QueueDraw();
            };
            zoomIN.SetSizeRequest(20, 20);
            zoomOut          = new Button("+");
            zoomOut.Clicked += (sender, e) =>
            {
                int width  = 0;
                int height = 0;
                drawingArea.GdkWindow.GetSize(out width, out height);
                double Xdiference = (MaxXValue - MinXValue) * 0.25;
                double Ydiference = (MaxYValue - MinYValue) * 0.25;
                if (!FixedX)
                {
                    MaxXValue -= Xdiference;
                    //MinXValue += Xdiference;
                }
                MaxYValue -= Ydiference;
                //MinYValue += Ydiference;

                drawingArea.QueueDraw();
            };
            zoomOut.SetSizeRequest(20, 20);


            //Control buttons for the resolution of the chart
            menosRes          = new Button("<");
            menosRes.Clicked += (sender, e) =>
            {
                if (this.XResolution > 2)
                {
                    if (!FixedX)
                    {
                        XResolution--;
                    }

                    YResolution--;
                    drawingArea.QueueDraw();
                }
            };

            masRes          = new Button(">");
            masRes.Clicked += (sender, e) =>
            {
                if (!FixedX)
                {
                    XResolution++;
                }
                YResolution++;
                drawingArea.QueueDraw();
            };

            showGrid          = new CheckButton("Grid");
            showGrid.Active   = ShowGridLines;
            showGrid.Clicked += (object sender, EventArgs e) =>
            {
                this.ShowGridLines = ((CheckButton)sender).Active;
                this.drawingArea.QueueDraw();
            };
            showLegend          = new CheckButton("Leyenda");
            showLegend.Active   = ShowLegend;
            showLegend.Clicked += (object sender, EventArgs e) =>
            {
                this.ShowLegend = ((CheckButton)sender).Active;
                this.drawingArea.QueueDraw();
            };

            centerChart          = new Button("Centrar");
            centerChart.Clicked += (sender, e) =>
            {
                Boolean primero = true;
                foreach (String keys in data.Keys)
                {
                    foreach (LineData ld in data[keys])
                    {
                        if (primero)
                        {
                            if (!FixedX)
                            {
                                MinXValue = ld.X;
                                MaxXValue = ld.X;
                            }

                            MinYValue = ld.Y;
                            MaxYValue = ld.Y;
                            primero   = false;
                            continue;
                        }
                        if (ld.X < MinXValue)
                        {
                            MinXValue = ld.X;
                        }
                        if (ld.X > MaxXValue)
                        {
                            MaxXValue = ld.X;
                        }
                        if (ld.Y < MinYValue)
                        {
                            MinYValue = ld.Y;
                        }
                        if (ld.Y > MaxYValue)
                        {
                            MaxYValue = ld.Y;
                        }
                    }
                }
                drawingArea.QueueDraw();
            };
        }