Beispiel #1
0
        public static void ShowWindow(string title, System.Action <int, int> action)
        {
            DateInputWindow dateInputWindow = new DateInputWindow(title, "Set the year", "Set the month");

            dateInputWindow.okButton.Clicked += (object sender, System.EventArgs e) =>
            {
                action(dateInputWindow.spinButton.ValueAsInt, dateInputWindow.spinButtonMonth.ValueAsInt);
                dateInputWindow.Destroy();
            };
            dateInputWindow.cancelButton.Clicked += (object sender, System.EventArgs e) =>
            {
                dateInputWindow.Destroy();
            };
            dateInputWindow.ShowAll();
        }
        public GardenDrawingArea(Garden.Garden garden, SpinButton zoomButton, int width = 800, int height = 600)
        {
            this.Garden = garden;
            this.SetSizeRequest(width, height);
            this.AddEvents((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask
                                 | Gdk.EventMask.KeyPressMask | Gdk.EventMask.KeyReleaseMask | Gdk.EventMask.AllEventsMask));


            this.ButtonPressEvent += delegate(object o, ButtonPressEventArgs args)
            {
                if (args.Event.Button == 1)
                {
                    if (MainWindow.GetInstance().AreaNewButton.Active)
                    {
                        UndoSelection();
                        GardenPoint gridPoint = SnapToGrid((int)(args.Event.X), (int)(args.Event.Y));
                        NewPoints.Add(gridPoint);
                        Draw();
                    }
                    else if (CheckAreaClick((int)args.Event.X, (int)args.Event.Y))
                    {
                        MakeSelection();
                    }
                    else
                    {
                        UndoSelection();
                    }
                }
                else if (args.Event.Button == 3 || args.Event.Button == 2)
                {
                    if (CheckAreaClick((int)args.Event.X, (int)args.Event.Y) && SelectedArea != null)
                    {
                        MakeSelection();

                        MenuItem item1 = new MenuItem("Set created date");
                        item1.Activated += (sender, e) => DateInputWindow.ShowWindow("Set created date", (int y, int m) => { SelectedArea.SetCreated(y, m); });
                        MenuItem item2 = new MenuItem("Set removed date");
                        item2.Activated += (sender, e) => DateInputWindow.ShowWindow("Set removed date", (int y, int m) => { SelectedArea.SetRemoved(y, m); });
                        MenuItem item3 = new MenuItem("Edit area");
                        item3.Activated += (sender, e) => MainWindow.GetInstance().AreaEditButton.Activate();
                        MenuItem item4 = new MenuItem("Remove area");
                        item4.Activated += (sender, e) => MainWindow.GetInstance().AreaDeleteButton.Activate();
                        MenuItem item5 = new MenuItem("Edit point");
                        item5.Sensitive  = SelectedPoint != null;
                        item5.Activated += (sender, e) => PointInputWindow.ShowWindow("Set new point", Math.Min(SelectedPoint.X, SelectedPoint.Y) - 100, Math.Max(SelectedPoint.X, SelectedPoint.Y) + 100, SelectedPoint.X, SelectedPoint.Y,
                                                                                      (int x, int y) => { SelectedArea.Shape.ModPoint(SelectedPoint, new GardenPoint(x, y), true); SelectedPoint = null; Draw(); });

                        Menu menu = new Menu()
                        {
                            item1, item2, item3, item4, item5
                        };

                        menu.AttachToWidget(this, null);
                        menu.ShowAll();
                        menu.Popup();
                    }
                }
            };

            zoomButton.ValueChanged += (object sender, System.EventArgs e) =>
            {
                Zoom = zoomButton.Value;
                if (IsDrawable)
                {
                    Draw();
                }
            };

            this.QueryTooltip += (object o, QueryTooltipArgs args) =>
            {
                System.Console.WriteLine("tooltip drawing area");
            };
            zoomButton.QueryTooltip += (object o, QueryTooltipArgs args) =>
            {
                System.Console.WriteLine("tooltip zoom button");
            };
        }