Exemple #1
0
        protected override bool OnButtonReleaseEvent(Gdk.EventButton ev)
        {
            base.OnButtonReleaseEvent(ev);

            if (ev.Button == 1 && plots.Count > 0)
            {
                // User wants to zoom
                if (selection_started &&
                    sel_rect.Width >= 10 &&
                    sel_rect.Height >= 10)
                {
                    IAxis x_axis, y_axis;
                    GetXAndYAxes(out x_axis, out y_axis);

                    int x_min = Int32.MaxValue;
                    int x_max = Int32.MinValue;
                    int y_min = Int32.MaxValue;
                    int y_max = Int32.MinValue;

                    // translate sel_rect into grid coordinates
                    if (x_axis != null)
                    {
                        int x1 = sel_rect.X - plot_alloc.X;
                        int x2 = x1 + sel_rect.Width;

                        x_min = Convert.ToInt32((x1 / (double)plot_alloc.Width) * GRID_MAX);
                        x_max = Convert.ToInt32((x2 / (double)plot_alloc.Width) * GRID_MAX);

                        RemoveAxisListeners(y_axis);
                        x_axis.Zoom(x_min, x_max);
                        AddAxisListeners(y_axis);
                    }

                    if (y_axis != null)
                    {
                        int y1 = sel_rect.Y - plot_alloc.Y;
                        int y2 = y1 + sel_rect.Height;

                        y_min = Convert.ToInt32(-1 * GRID_MAX * ((y2 - plot_alloc.Height) / (double)plot_alloc.Height));
                        y_max = Convert.ToInt32(-1 * GRID_MAX * ((y1 - plot_alloc.Height) / (double)plot_alloc.Height));

                        RemoveAxisListeners(y_axis);
                        y_axis.Zoom(y_min, y_max);
                        AddAxisListeners(y_axis);
                    }

                    // now, do it for the rest of the axes
                    foreach (IAxis axis in axes)
                    {
                        if (axis == x_axis || axis == y_axis)
                        {
                            continue;
                        }

                        if (axis.Dimension == 0)
                        {
                            axis.Zoom(x_min, x_max);
                        }
                        else if (axis.Dimension == 1)
                        {
                            axis.Zoom(y_min, y_max);
                        }
                    }

                    sel_rect          = new Gdk.Rectangle();
                    selection_started = false;

                    QueueResize();
                    return(true);
                }

                sel_rect          = new Gdk.Rectangle();
                selection_started = false;

                // convert the clicked point to graph locations
                int x = ((int)ev.X - plot_alloc.X);
                int y = ((int)ev.Y - plot_alloc.Y);

                if ((x < 0 || x > plot_alloc.Width) ||
                    (y < 0 || y > plot_alloc.Height))
                {
                    return(true);
                }

                foreach (IPlot plot in plots)
                {
                    plot.UnselectAll();

                    if (plot.CanFocus)
                    {
                        plot.ReleaseFocus();
                    }
                }

                for (int i = 0; i < plots.Count; i++)
                {
                    IPlot plot = (IPlot)plots[i];

                    focused_plot_index = i;
                    if ((ev.State & Gdk.ModifierType.ControlMask)
                        == Gdk.ModifierType.ControlMask)
                    {
                        if (plot.UnselectPoint(x, y))
                        {
                            break;
                        }

                        continue;
                    }

                    if (plot.SelectPoint(x, y))
                    {
                        break;
                    }
                }

                QueueDraw();
            }

            return(true);
        }