Пример #1
0
        private void HandleDrawingMotionNotifyEvent(object o, Gtk.MotionNotifyEventArgs args)
        {
            int x, y;

            Gdk.ModifierType mask;
            GdkExtensions.GetWindowPointer(drawing.Window, out x, out y, out mask);

            if (x < 0 || x >= size || y < 0 || y >= size)
            {
                return;
            }

            if (args.Event.State == Gdk.ModifierType.Button1Mask)
            {
                // first and last control point cannot be removed
                if (last_cpx != 0 && last_cpx != size - 1)
                {
                    foreach (var controlPoints in GetActiveControlPoints())
                    {
                        if (controlPoints.ContainsKey(last_cpx))
                        {
                            controlPoints.Remove(last_cpx);
                        }
                    }
                }

                AddControlPoint(x, y);
            }

            InvalidateDrawing();
        }
Пример #2
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);
            }
Пример #3
0
        private void DrawControlPoints(Context g)
        {
            int x, y;

            Gdk.ModifierType mask;
            GdkExtensions.GetWindowPointer(drawing.Window, out x, out y, out mask);

            var infos = GetDrawingInfos();

            foreach (var controlPoints in ControlPoints)
            {
                infos.MoveNext();
                var info = infos.Current;

                for (int i = 0; i < controlPoints.Count; i++)
                {
                    int       cpx = controlPoints.Keys[i];
                    int       cpy = size - 1 - (int)controlPoints.Values[i];
                    Rectangle rect;

                    if (info.IsActive)
                    {
                        if (CheckControlPointProximity(cpx, cpy, x, y))
                        {
                            rect = new Rectangle(cpx - (radius + 2) / 2, cpy - (radius + 2) / 2, radius + 2, radius + 2);
                            g.DrawEllipse(rect, new Color(0.2, 0.2, 0.2), 2);
                            rect = new Rectangle(cpx - radius / 2, cpy - radius / 2, radius, radius);
                            g.FillEllipse(rect, new Color(0.9, 0.9, 0.9));
                        }
                        else
                        {
                            rect = new Rectangle(cpx - radius / 2, cpy - radius / 2, radius, radius);
                            g.DrawEllipse(rect, info.Color, 2);
                        }
                    }

                    rect = new Rectangle(cpx - (radius - 2) / 2, cpy - (radius - 2) / 2, radius - 2, radius - 2);
                    g.FillEllipse(rect, info.Color);
                }
            }

            g.Stroke();
        }
Пример #4
0
        private void HandleDrawingButtonPressEvent(object o, Gtk.ButtonPressEventArgs args)
        {
            int x, y;

            Gdk.ModifierType mask;
            GdkExtensions.GetWindowPointer(drawing.Window, out x, out y, out mask);

            if (args.Event.Button == 1)
            {
                AddControlPoint(x, y);
            }

            // user pressed right button
            if (args.Event.Button == 3)
            {
                foreach (var controlPoints in GetActiveControlPoints())
                {
                    for (int i = 0; i < controlPoints.Count; i++)
                    {
                        int cpx = controlPoints.Keys[i];
                        int cpy = size - 1 - (int)controlPoints.Values[i];

                        //we cannot allow user to remove first or last control point
                        if (cpx == 0 && cpy == size - 1)
                        {
                            continue;
                        }
                        if (cpx == size - 1 && cpy == 0)
                        {
                            continue;
                        }

                        if (CheckControlPointProximity(cpx, cpy, x, y))
                        {
                            controlPoints.RemoveAt(i);
                            break;
                        }
                    }
                }
            }

            InvalidateDrawing();
        }
Пример #5
0
        private void DrawPointerCross(Context g)
        {
            int x, y;

            Gdk.ModifierType mask;
            GdkExtensions.GetWindowPointer(drawing.Window, out x, out y, out mask);

            if (x >= 0 && x < size && y >= 0 && y < size)
            {
                g.LineWidth = 0.5;
                g.MoveTo(x, 0);
                g.LineTo(x, size);
                g.MoveTo(0, y);
                g.LineTo(size, y);
                g.Stroke();

                this.labelPoint.Text = string.Format("({0}, {1})", x, y);
            }
            else
            {
                this.labelPoint.Text = string.Empty;
            }
        }
Пример #6
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();
        }
Пример #7
0
 static CanvasRenderer()
 {
     using (var grid = GdkExtensions.CreateTransparentColorSwatch(false))
         using (var surf = grid.ToSurface())
             tranparent_pattern = surf.ToTiledPattern();
 }