Ejemplo n.º 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();
        }