コード例 #1
0
        public MainWindow(string title) : base(title)
        {
            // COMPOSITE MODEL
            _model = new CompositeModel();
            _model.AddCompositeChangedCallback(UpdateCanvas);
            _model.AddLayerChangedCallback(UpdateListView);

            // TRANSFORM TOOL
            _transformTool = new TransformTool();

            // MENUBAR
            // FILE
            MenuBar menuBar = new MenuBar();

            MenuItem file     = new MenuItem("File");
            Menu     fileMenu = new Menu();

            file.Submenu = fileMenu;

            MenuItem open = new MenuItem("Open");

            open.Activated += OpenImage;
            fileMenu.Append(open);

            MenuItem save = new MenuItem("Save");

            save.Activated += SaveImage;
            fileMenu.Append(save);

            MenuItem quit = new MenuItem("Quit");

            quit.Activated += delegate { Application.Quit(); };
            fileMenu.Append(quit);

            menuBar.Append(file);

            // FILTER
            MenuItem filter     = new MenuItem("Filter");
            Menu     filterMenu = new Menu();

            filter.Submenu = filterMenu;

            MenuItem none = new MenuItem("None");

            none.Activated += NoneF;
            filterMenu.Append(none);

            MenuItem grayscale = new MenuItem("Grayscale");

            grayscale.Activated += GrayscaleF;
            filterMenu.Append(grayscale);

            MenuItem lighten = new MenuItem("Lighten");

            lighten.Activated += LightenF;
            filterMenu.Append(lighten);

            MenuItem darken = new MenuItem("Darken");

            darken.Activated += DarkenF;
            filterMenu.Append(darken);

            MenuItem jitter = new MenuItem("Jitter");

            jitter.Activated += JitterF;
            filterMenu.Append(jitter);

            menuBar.Append(filter);


            // TOOLBAR
            Toolbar toolbar = new Toolbar();

            toolbar.ToolbarStyle = ToolbarStyle.Icons;

            // Transform Tool Buttons
            DirectoryInfo diOp = new DirectoryInfo(@"./ops");

            for (int i = 0; i < diOp.GetFiles().Length; i++)
            {
                var        fi    = diOp.GetFiles()[i];
                Image      op    = new Image("./ops/" + fi.Name);
                string     label = fi.Name.Substring(0, fi.Name.Length - 4);
                ToolButton addOp = new ToolButton(op, label);
                addOp.Clicked += ChangeTransformMode;
                toolbar.Insert(addOp, i);
            }

            // Accessory Buttons
            DirectoryInfo diAcc = new DirectoryInfo(@"./accessories");

            for (int i = 0; i < diAcc.GetFiles().Length; i++)
            {
                var   fi        = diAcc.GetFiles()[i];
                Image accessory = new Image("./accessories/" + fi.Name);
                accessory.Pixbuf = accessory.Pixbuf.ScaleSimple(40, 40, Gdk.InterpType.Bilinear);
                string     label        = fi.Name.Substring(0, fi.Name.Length - 4);
                ToolButton addAccessory = new ToolButton(accessory, label);
                addAccessory.Clicked += AddAccessory;
                toolbar.Insert(addAccessory, i + 2);
            }

            // LISTVIEW
            _listView = new ListView("Layer");

            // DELETE LAYER
            Button deleteLayer             = new Button("Delete Layer");
                      deleteLayer.Clicked += DeleteAccessory;

            // CANVAS
            _model.LoadBaseImage("./photos/kitty4.jpg");
            _canvas = new Canvas(_model.CompositeImage);
            _canvas.ButtonPressEvent   += ActivateTransformTool;
            _canvas.MotionNotifyEvent  += TransformLayer;
            _canvas.ButtonReleaseEvent += DeactivateTransformTool;

            // DISPLAY SETUP
            bool isUniform = false;
            int  margin    = 5;

            VBox listViewAndDeleteLayer = new VBox(isUniform, margin);

            listViewAndDeleteLayer.Add(Align(_listView, TOP, LEFT, FIXED, FIXED));
            listViewAndDeleteLayer.Add(Align(deleteLayer, BOTTOM, LEFT, FILL, FILL));


            HBox assortedThings = new HBox(isUniform, margin);

            assortedThings.Add(Align(listViewAndDeleteLayer, TOP, MIDDLE, FIXED, FIXED));
            assortedThings.Add(Align(_canvas, TOP, LEFT, FILL, FIXED));

            VBox vlayout = new VBox(isUniform, margin);

            vlayout.Add(Align(menuBar, TOP, LEFT, FILL, FILL));
            vlayout.Add(Align(toolbar, TOP, LEFT, FIXED, FIXED));
            vlayout.Add(Align(assortedThings, TOP, LEFT, FILL, FILL));

            Add(vlayout);
            BorderWidth = (uint)margin * 2;
            Resize(800, 600);
            ShowAll();
        }
コード例 #2
0
        public MainWindow(string title) : base(title)
        {
            //Create model
            _model = new CompositeModel();

            _model.AddCompositeChangedCallback(OnCompositeImageChangeCallback);
            _model.AddLayerChangedCallback(OnLayerChangeCallback);

            //Below is all setting up initial look
            SetDefaultSize(800, 600);
            SetPosition(WindowPosition.Center);

            VBox mainBox = new VBox(false, 5);

            // Create the Menubar, "File" and "Filter" menu
            _menuBar = new MenuBar();
            Menu     file_menu1 = new Menu();
            MenuItem open_item  = new MenuItem("Open");
            MenuItem save_item  = new MenuItem("Save As");
            MenuItem exit_item  = new MenuItem("Exit");

            file_menu1.Append(open_item);
            file_menu1.Append(save_item);
            file_menu1.Append(exit_item);

            MenuItem file_item1 = new MenuItem("File");

            file_item1.Submenu = file_menu1;
            _menuBar.Append(file_item1);

            Menu file_menu2 = new Menu();

            MenuItem[] filterItems = new MenuItem[_model.FilterNames.Count];
            for (int i = 0; i < _model.FilterNames.Count; i++)
            {
                filterItems[i]            = new MenuItem(_model.FilterNames[i]);
                filterItems[i].Activated += OnFilterClickCallback;
                file_menu2.Append(filterItems[i]);
            }

            /*
             * MenuItem none_item = new MenuItem("None");
             * MenuItem grayscale_item = new MenuItem("Grayscale");
             * MenuItem lighten_item = new MenuItem("Lighten");
             * MenuItem darken_item = new MenuItem("Darken");
             * MenuItem jitter_item = new MenuItem("Jitter");
             *
             * file_menu2.Append(none_item);
             * file_menu2.Append(grayscale_item);
             * file_menu2.Append(lighten_item);
             * file_menu2.Append(darken_item);
             * file_menu2.Append(jitter_item);
             */

            MenuItem file_item2 = new MenuItem("Filter");

            file_item2.Submenu = file_menu2;
            _menuBar.Append(file_item2);

            // Creates the Toolbar and everything inside
            _toolBar = new Toolbar();

            // Creates a Pixbuf Array
            Gdk.Pixbuf[] pixbufArray = new Gdk.Pixbuf[]
            {
                new Gdk.Pixbuf("ops/move.png"),
                new Gdk.Pixbuf("ops/scale.png"),
                new Gdk.Pixbuf("accessories/star.png"),
                new Gdk.Pixbuf("accessories/aviator.png"),
                new Gdk.Pixbuf("accessories/heart.png"),
                new Gdk.Pixbuf("accessories/nerd.png"),
                new Gdk.Pixbuf("accessories/horns.png"),
                new Gdk.Pixbuf("accessories/halo.png"),
                new Gdk.Pixbuf("accessories/tiara.png"),
                new Gdk.Pixbuf("accessories/moustache.png"),
                new Gdk.Pixbuf("accessories/librarian.png")
            };

            // Creates a toolNames Array
            string[] toolNames = new string[] { "move", "scale", "star", "aviator",
                                                "heart", "nerd", "horns", "halo",
                                                "tiara", "moustache", "librarian" };
            ToolButton[] buttons = new ToolButton[pixbufArray.Length];

            Widget widget;

            // Creates all the Toolbuttons
            for (int i = 0; i < pixbufArray.Length; i++)
            {
                widget     = new Image(new IconSet(pixbufArray[i]), IconSize.Button);
                buttons[i] = new ToolButton(widget, toolNames[i]);
                _toolBar.Insert(buttons[i], -1);
            }
            _toolBar.ToolbarStyle = ToolbarStyle.Icons;

            //Create a HBox containing canvas and a VBox of _listView and delete
            HBox viewCanvasBox = new HBox(false, 5);

            VBox viewAndDelete = new VBox(false, 5);

            _listView = new ListView("listview");
            Button delete = new Button();

            delete.Label = "Delete Layer";

            // Create Canvas and set a default image
            Gdk.Pixbuf image = new Gdk.Pixbuf("photos/kitty2.jpg"); //Default Image
            _canvas = new Canvas(image);
            _model.LoadBaseImage("photos/kitty2.jpg");

            // Create an EventBox containing canvas
            EventBox eventBox = new EventBox();

            //Add every box in Window

            //The 4th level: add _listView and delete to viewAndDelete
            viewAndDelete.PackStart(Align(_listView, 0, 0, 1, 1), true, true, 0);
            viewAndDelete.PackStart(Align(delete, 1, 0, 1, 0), false, false, 0);

            //The 4th level: add _canvas to EventBox
            eventBox.Add(_canvas);

            //The 3rd level: add viewAndDelete and eventBox to viewCanvasBox
            viewCanvasBox.PackStart(Align(viewAndDelete, 0, 0, 0.5f, 1), false,
                                    false, 0);
            viewCanvasBox.Add(Align(eventBox, 0.5f, 0.5f, 0, 0));

            //The 2nd level: add _menuBar, _toolBar, and viewCanvasBox to mainBox
            mainBox.PackStart(Align(_menuBar, 0, 0, 0, 0), false, false, 0);
            mainBox.PackStart(Align(_toolBar, 0, 0.5f, 1, 0), false, false, 0);
            mainBox.PackStart(Align(viewCanvasBox, 0, 0, 1, 1), true, true, 0);

            //The Surface level: add mainBox to MainWindow
            Add(mainBox);

            ShowAll();

            //Event-handling

            //MenuBar Event-handling
            exit_item.Activated += delegate { Application.Quit(); };
            open_item.Activated += delegate { OnOpenCallback(); };
            save_item.Activated += delegate { OnSaveCallback(); };

            //ToolBar Event-Handling
            buttons[0].Clicked += delegate { OnMoveLayerCallback(); };
            buttons[1].Clicked += delegate { OnScaleLayerCallback(); };
            buttons[2].Clicked += delegate { OnAccessoryCallback(pixbufArray[2],
                                                                 toolNames[2]); };
            buttons[3].Clicked += delegate { OnAccessoryCallback(pixbufArray[3],
                                                                 toolNames[3]); };
            buttons[4].Clicked += delegate { OnAccessoryCallback(pixbufArray[4],
                                                                 toolNames[4]); };
            buttons[5].Clicked += delegate { OnAccessoryCallback(pixbufArray[5],
                                                                 toolNames[5]); };
            buttons[6].Clicked += delegate { OnAccessoryCallback(pixbufArray[6],
                                                                 toolNames[6]); };
            buttons[7].Clicked += delegate { OnAccessoryCallback(pixbufArray[7],
                                                                 toolNames[7]); };
            buttons[8].Clicked += delegate { OnAccessoryCallback(pixbufArray[8],
                                                                 toolNames[8]); };
            buttons[9].Clicked += delegate { OnAccessoryCallback(pixbufArray[9],
                                                                 toolNames[9]); };
            buttons[10].Clicked += delegate { OnAccessoryCallback(pixbufArray[10],
                                                                  toolNames[10]); };
            //Delete Event-handling
            delete.Clicked += delegate { OnDeleteCallback(); };

            //EventBox Event-handling
            eventBox.ButtonPressEvent += delegate(object obj,
                                                  ButtonPressEventArgs args)
            {
                OnButtonPressCallback(obj, args);
            };
            eventBox.MotionNotifyEvent += delegate(object obj,
                                                   MotionNotifyEventArgs args)
            {
                OnMotionNotifyCallback(obj, args);
            };
            eventBox.ButtonReleaseEvent += delegate(object obj,
                                                    ButtonReleaseEventArgs args)
            {
                OnButtonReleaseCallback(obj, args);
            };

            //Closing Window
            DeleteEvent += delegate { Application.Quit(); };
        }