コード例 #1
0
            protected override bool OnExposeEvent(Gdk.EventExpose evnt)
            {
                base.OnExposeEvent(evnt);

                if (size == Gdk.Size.Empty)
                {
                    return(true);
                }

                var preview_size = Gdk.Size.Empty;
                var widget_size  = GdkWindow.GetBounds();

                // Figure out the dimensions of the preview to draw
                if (size.Width <= max_size && size.Height <= max_size)
                {
                    preview_size = size;
                }
                else if (size.Width > size.Height)
                {
                    preview_size = new Gdk.Size(max_size, (int)(max_size / ((float)size.Width / (float)size.Height)));
                }
                else
                {
                    preview_size = new Gdk.Size((int)(max_size / ((float)size.Height / (float)size.Width)), max_size);
                }

                using (var g = Gdk.CairoHelper.Create(GdkWindow)) {
                    var r = new Cairo.Rectangle((widget_size.Width - preview_size.Width) / 2, (widget_size.Height - preview_size.Height) / 2, preview_size.Width, preview_size.Height);

                    if (color.A == 0)
                    {
                        // Fill with transparent checkerboard pattern
                        using (var grid = GdkExtensions.CreateTransparentColorSwatch(false))
                            using (var surf = grid.ToSurface())
                                using (var pattern = surf.ToTiledPattern())
                                    g.FillRectangle(r, pattern);
                    }
                    else
                    {
                        // Fill with selected color
                        g.FillRectangle(r, color);
                    }

                    // Draw our canvas drop shadow
                    g.DrawRectangle(new Cairo.Rectangle(r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2), new Cairo.Color(.5, .5, .5), 1);
                    g.DrawRectangle(new Cairo.Rectangle(r.X - 2, r.Y - 2, r.Width + 4, r.Height + 4), new Cairo.Color(.8, .8, .8), 1);
                    g.DrawRectangle(new Cairo.Rectangle(r.X - 3, r.Y - 3, r.Width + 6, r.Height + 6), new Cairo.Color(.9, .9, .9), 1);
                }

                return(true);
            }
コード例 #2
0
        private void BuildDialog()
        {
            // Layout table for preset, width, and height
            var layout_table = new Table(3, 2, false);

            layout_table.RowSpacing    = 5;
            layout_table.ColumnSpacing = 6;

            // Preset Combo
            var size_label = new Label(Catalog.GetString("Preset:"));

            size_label.SetAlignment(1f, .5f);

            var preset_entries = new List <string> ();

            if (has_clipboard)
            {
                preset_entries.Add(Catalog.GetString("Clipboard"));
            }

            preset_entries.Add(Catalog.GetString("Custom"));
            preset_entries.AddRange(preset_sizes.Select(p => string.Format("{0} x {1}", p.Width, p.Height)));

            preset_combo        = new ComboBox(preset_entries.ToArray());
            preset_combo.Active = 0;

            layout_table.Attach(size_label, 0, 1, 0, 1, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
            layout_table.Attach(preset_combo, 1, 2, 0, 1, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);

            // Width Entry
            var width_label = new Label(Catalog.GetString("Width:"));

            width_label.SetAlignment(1f, .5f);

            width_entry = new Entry();
            width_entry.WidthRequest     = 50;
            width_entry.ActivatesDefault = true;

            var width_units = new Label(Catalog.GetString("pixels"));

            var width_hbox = new HBox();

            width_hbox.PackStart(width_entry, false, false, 0);
            width_hbox.PackStart(width_units, false, false, 5);

            layout_table.Attach(width_label, 0, 1, 1, 2, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
            layout_table.Attach(width_hbox, 1, 2, 1, 2, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);

            // Height Entry
            var height_label = new Label(Catalog.GetString("Height:"));

            height_label.SetAlignment(1f, .5f);

            height_entry = new Entry();
            height_entry.WidthRequest     = 50;
            height_entry.ActivatesDefault = true;

            var height_units = new Label(Catalog.GetString("pixels"));

            var height_hbox = new HBox();

            height_hbox.PackStart(height_entry, false, false, 0);
            height_hbox.PackStart(height_units, false, false, 5);

            layout_table.Attach(height_label, 0, 1, 2, 3, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
            layout_table.Attach(height_hbox, 1, 2, 2, 3, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);

            // Orientation Radio options
            var orientation_label = new Label(Catalog.GetString("Orientation:"));

            orientation_label.SetAlignment(0f, .5f);

            portrait_radio = new RadioButton(Catalog.GetString("Portrait"));
            var portrait_image = new Image(PintaCore.Resources.GetIcon(Stock.OrientationPortrait, 16));

            var portrait_hbox = new HBox();

            portrait_hbox.PackStart(portrait_image, false, false, 7);
            portrait_hbox.PackStart(portrait_radio, false, false, 0);

            landscape_radio = new RadioButton(portrait_radio, Catalog.GetString("Landscape"));
            var landscape_image = new Image(PintaCore.Resources.GetIcon(Stock.OrientationLandscape, 16));

            var landscape_hbox = new HBox();

            landscape_hbox.PackStart(landscape_image, false, false, 7);
            landscape_hbox.PackStart(landscape_radio, false, false, 0);

            // Orientation VBox
            var orientation_vbox = new VBox();

            orientation_vbox.PackStart(orientation_label, false, false, 4);
            orientation_vbox.PackStart(portrait_hbox, false, false, 0);
            orientation_vbox.PackStart(landscape_hbox, false, false, 0);

            // Background Color options
            var background_label = new Label(Catalog.GetString("Background:"));

            background_label.SetAlignment(0f, .5f);

            white_bg_radio = new RadioButton(Catalog.GetString("White"));
            var image_white = new Image(GdkExtensions.CreateColorSwatch(16, new Gdk.Color(255, 255, 255)));

            var hbox_white = new HBox();

            hbox_white.PackStart(image_white, false, false, 7);
            hbox_white.PackStart(white_bg_radio, false, false, 0);

            secondary_bg_radio = new RadioButton(white_bg_radio, Catalog.GetString("Background Color"));
            var image_bg = new Image(GdkExtensions.CreateColorSwatch(16, PintaCore.Palette.SecondaryColor.ToGdkColor()));

            var hbox_bg = new HBox();

            hbox_bg.PackStart(image_bg, false, false, 7);
            hbox_bg.PackStart(secondary_bg_radio, false, false, 0);

            trans_bg_radio = new RadioButton(secondary_bg_radio, Catalog.GetString("Transparent"));
            var image_trans = new Image(GdkExtensions.CreateTransparentColorSwatch(true));

            var hbox_trans = new HBox();

            hbox_trans.PackStart(image_trans, false, false, 7);
            hbox_trans.PackStart(trans_bg_radio, false, false, 0);

            // Background VBox
            var background_vbox = new VBox();

            background_vbox.PackStart(background_label, false, false, 4);
            background_vbox.PackStart(hbox_white, false, false, 0);

            if (allow_background_color)
            {
                background_vbox.PackStart(hbox_bg, false, false, 0);
            }

            background_vbox.PackStart(hbox_trans, false, false, 0);

            // Put all the options together
            var options_vbox = new VBox();

            options_vbox.Spacing = 10;

            options_vbox.PackStart(layout_table, false, false, 3);
            options_vbox.PackStart(orientation_vbox, false, false, 0);
            options_vbox.PackStart(background_vbox, false, false, 4);

            // Layout the preview + the options
            preview = new PreviewArea();

            var preview_label = new Label(Catalog.GetString("Preview"));

            var preview_vbox = new VBox();

            preview_vbox.PackStart(preview_label, false, false, 0);
            preview_vbox.PackStart(preview, true, true, 0);


            var main_hbox = new HBox(false, 10);

            main_hbox.PackStart(options_vbox, false, false, 0);
            main_hbox.PackStart(preview_vbox, true, true, 0);

            VBox.Add(main_hbox);

            ShowAll();
        }
コード例 #3
0
 static CanvasRenderer()
 {
     using (var grid = GdkExtensions.CreateTransparentColorSwatch(false))
         using (var surf = grid.ToSurface())
             tranparent_pattern = surf.ToTiledPattern();
 }