Esempio n. 1
0
        protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
        {
            // Ignore extra button clicks while drawing
            if (is_drawing)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();

            reset_origin = args.Event.GetPoint();

            active_control = HandleResize(point);
            if (!active_control.HasValue)
            {
                combine_mode = PintaCore.Workspace.SelectionHandler.DetermineCombineMode(args);

                double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
                double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);
                shape_origin = new PointD(x, y);

                doc.PreviousSelection.Dispose();
                doc.PreviousSelection = doc.Selection.Clone();
                doc.Selection.SelectionPolygons.Clear();

                // The bottom right corner should be selected.
                active_control = 3;
            }

            is_drawing = true;
        }
Esempio n. 2
0
        protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
        {
            // Ignore extra button clicks while drawing
            if (is_drawing)
            {
                return;
            }

            reset_origin = args.Event.GetPoint();

            Document doc = PintaCore.Workspace.ActiveDocument;

            if (!handler_active || !HandleResize(point.X, point.Y))
            {
                double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
                double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);

                shape_origin = new PointD(x, y);

                doc.Selection.SelectionPolygons.Clear();
                is_drawing = true;
            }
            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();
        }
Esempio n. 3
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                PintaCore.Actions.Edit.Deselect.Activate();
                hist.Dispose();
                hist           = null;
                handler_active = false;
                Document doc = PintaCore.Workspace.ActiveDocument;
                doc.ToolLayer.Clear();
            }
            else
            {
                if (hist != null)
                {
                    PintaCore.Workspace.ActiveDocument.History.PushNewItem(hist);
                }

                handler_active = true;
                hist           = null;
            }

            is_drawing = false;
        }
Esempio n. 4
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            ImageSurface surf = doc.SelectionLayer.Surface;

            using (Context g = new Context(surf)) {
                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                    path = null;
                }

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath();
            }

            doc.Selection.SelectionPolygons.Clear();
            doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList());
            SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);
            doc.Workspace.Invalidate();

            if (hist != null)
            {
                doc.History.PushNewItem(hist);
                hist = null;
            }

            lasso_polygon.Clear();
            is_drawing = false;
        }
Esempio n. 5
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform();

            Document doc = PintaCore.Workspace.ActiveDocument;

            original_selection = doc.Selection.Clone();

            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();
        }
Esempio n. 6
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            is_dragging = false;

            if (hist != null)
            {
                PintaCore.Workspace.ActiveDocument.History.PushNewItem(hist);
            }

            hist = null;
        }
Esempio n. 7
0
        protected override void OnFinishTransform()
        {
            base.OnFinishTransform();

            if (hist != null)
            {
                PintaCore.Workspace.ActiveDocument.History.PushNewItem(hist);
            }

            hist = null;
            original_selection = null;
        }
Esempio n. 8
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            // If we are already drawing, ignore any additional mouse down events
            if (is_dragging)
            {
                return;
            }

            origin_offset = point;
            is_dragging   = true;

            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();
        }
Esempio n. 9
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                // Mark as being done interactive drawing before invoking the deselect action.
                // This will allow AfterSelectionChanged() to clear the selection.
                is_drawing = false;

                if (hist != null)
                {
                    // Roll back any changes made to the selection, e.g. in OnMouseDown().
                    hist.Undo();

                    hist.Dispose();
                    hist = null;
                }

                PintaCore.Actions.Edit.Deselect.Activate();
            }
            else
            {
                ClearHandles(doc.ToolLayer);
                ReDraw(args.Event.State);
                if (doc.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);

                    doc.Selection.Origin = shape_origin;
                    doc.Selection.End    = shape_end;
                    PintaCore.Workspace.Invalidate();
                }
                if (hist != null)
                {
                    doc.History.PushNewItem(hist);
                    hist = null;
                }
            }

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            UpdateCursor(point);
        }
Esempio n. 10
0
        protected override void OnFillRegionComputed(Document document, Point[][] polygonSet)
        {
            var undoAction = new SelectionHistoryItem(Icon, Name);

            undoAction.TakeSnapshot();

            document.PreviousSelection.Dispose();
            document.PreviousSelection = document.Selection.Clone();

            document.Selection.SelectionPolygons.Clear();
            SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygons(polygonSet));

            document.History.PushNewItem(undoAction);
            document.Workspace.Invalidate();
        }
Esempio n. 11
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            SelectionHistoryItem undoAction = new SelectionHistoryItem(this.Icon, this.Name);

            undoAction.TakeSnapshot();

            doc.PreviousSelection.Dispose();
            doc.PreviousSelection = doc.Selection.Clone();

            doc.Selection.SelectionPolygons.Clear();
            SelectionModeHandler.PerformSelectionMode(combine_mode, polygonSet);

            doc.History.PushNewItem(undoAction);
            doc.Workspace.Invalidate();
        }
Esempio n. 12
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            if (is_drawing)
            {
                return;
            }

            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();

            combine_mode = PintaCore.Workspace.SelectionHandler.DetermineCombineMode(args);
            path         = null;
            is_drawing   = true;

            var doc = PintaCore.Workspace.ActiveDocument;

            doc.PreviousSelection.Dispose();
            doc.PreviousSelection = doc.Selection.Clone();
        }
Esempio n. 13
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            SelectionHistoryItem undoAction = new SelectionHistoryItem(this.Icon, this.Name);

            undoAction.TakeSnapshot();

            Path path = doc.SelectionPath;

            using (Context g = new Context(PintaCore.Layers.CurrentLayer.Surface)) {
                PintaCore.Layers.SelectionPath = g.CreatePolygonPath(polygonSet);

                switch (combineMode)
                {
                case CombineMode.Union:
                    g.AppendPath(path);
                    break;

                case CombineMode.Xor:
                    //not supported
                    break;

                case CombineMode.Exclude:
                    //not supported
                    break;

                case CombineMode.Replace:
                    //do nothing
                    break;
                }
            }

            (path as IDisposable).Dispose();

            //Selection.PerformChanging();
            //Selection.SetContinuation(polygonSet, this.combineMode);
            //Selection.CommitContinuation();
            //Selection.PerformChanged();

            doc.History.PushNewItem(undoAction);
            doc.Workspace.Invalidate();
        }
Esempio n. 14
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                PintaCore.Actions.Edit.Deselect.Activate();
                if (hist != null)
                {
                    hist.Dispose();
                    hist = null;
                }
                doc.ToolLayer.Clear();
            }
            else
            {
                ClearHandles(doc.ToolLayer);
                ReDraw(args.Event.State);
                if (doc.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);

                    doc.Selection.Origin = shape_origin;
                    doc.Selection.End    = shape_end;
                    PintaCore.Workspace.Invalidate();
                }
                if (hist != null)
                {
                    doc.History.PushNewItem(hist);
                    hist = null;
                }
            }

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            UpdateCursor(point);
        }
Esempio n. 15
0
        protected override void OnFinishTransform(Matrix transform)
        {
            base.OnFinishTransform(transform);

            // Also transform the base selection used for the various select modes.
            var doc = PintaCore.Workspace.ActiveDocument;

            using (var prev_selection = doc.PreviousSelection)
                doc.PreviousSelection = prev_selection.Transform(transform);

            if (hist != null)
            {
                PintaCore.Workspace.ActiveDocument.History.PushNewItem(hist);
            }

            hist = null;

            original_selection.Dispose();
            original_selection = null;
        }
Esempio n. 16
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                PintaCore.Actions.Edit.Deselect.Activate();
                hist.Dispose();
                hist           = null;
                handler_active = false;

                doc.ToolLayer.Clear();
            }
            else
            {
                ReDraw(args.Event.State);

                if (doc.Selection != null)
                {
                    doc.selHandler.PerformSelectionMode(DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
                    PintaCore.Workspace.Invalidate();
                }

                if (hist != null)
                {
                    doc.History.PushNewItem(hist);
                }

                handler_active = true;
                hist.Dispose();
                hist = null;
            }

            is_drawing = false;
            isResizing = false;
        }
Esempio n. 17
0
    private void AddSelectionHistoryItem()
    {
        if (m_client != null)
        {
            if (m_client.Book != null)
            {
                if (m_client.Selection != null)
                {

                    SelectionHistoryItem item = new SelectionHistoryItem(m_client.Selection.Book, m_client.Selection.Scope, m_client.Selection.Indexes);
                    if (item != null)
                    {
                        m_client.AddHistoryItem(item);
                        UpdateBrowseHistoryButtons();
                    }
                }
            }
        }
    }
Esempio n. 18
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            SelectionHistoryItem undoAction = new SelectionHistoryItem(this.Icon, this.Name);

            undoAction.TakeSnapshot();

            //Convert Pinta's passed in Polygon Set to a Clipper Polygon collection.
            List <List <IntPoint> > newPolygons = DocumentSelection.ConvertToPolygons(polygonSet);

            using (Context g = new Context(PintaCore.Layers.CurrentLayer.Surface))
            {
                //Make sure time isn't wasted if the CombineMode is Replace - Replace is much simpler than the other 4 selection modes.
                if (combineMode == CombineMode.Replace)
                {
                    //Clear any previously stored Polygons.
                    doc.Selection.SelectionPolygons.Clear();

                    //Set the resulting selection path to the new selection path.
                    doc.Selection.SelectionPolygons = newPolygons;
                    doc.Selection.SelectionPath     = g.CreatePolygonPath(polygonSet);
                }
                else
                {
                    List <List <IntPoint> > resultingPolygons = new List <List <IntPoint> >();

                    //Specify the Clipper Subject (the previous Polygons) and the Clipper Clip (the new Polygons).
                    //Note: for Union, ignore the Clipper Library instructions - the new polygon(s) should be Clips, not Subjects!
                    doc.Selection.SelectionClipper.AddPolygons(doc.Selection.SelectionPolygons, PolyType.ptSubject);
                    doc.Selection.SelectionClipper.AddPolygons(newPolygons, PolyType.ptClip);

                    switch (combineMode)
                    {
                    case CombineMode.Xor:
                        //Xor means "Combine both Polygon sets, but leave out any areas of intersection between the two."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctXor, resultingPolygons);
                        break;

                    case CombineMode.Exclude:
                        //Exclude == Difference

                        //Exclude/Difference means "Subtract any overlapping areas of the new Polygon set from the old Polygon set."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctDifference, resultingPolygons);
                        break;

                    case CombineMode.Intersect:
                        //Intersect means "Leave only the overlapping areas between the new and old Polygon sets."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctIntersection, resultingPolygons);
                        break;

                    default:
                        //Default should only be *CombineMode.Union*, but just in case...

                        //Union means "Combine both Polygon sets, and keep any overlapping areas as well."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctUnion, resultingPolygons);
                        break;
                    }

                    //After using Clipper, it has to be cleared so there are no conflicts with its next usage.
                    doc.Selection.SelectionClipper.Clear();

                    //Set the resulting selection path to the calculated ("clipped") selection path.
                    doc.Selection.SelectionPolygons = resultingPolygons;
                    doc.Selection.SelectionPath     = g.CreatePolygonPath(DocumentSelection.ConvertToPolygonSet(resultingPolygons));
                }
            }

            doc.History.PushNewItem(undoAction);
            doc.Workspace.Invalidate();
        }
Esempio n. 19
0
    public void LoadHistoryItems()
    {
        string filename = Globals.HISTORY_FOLDER + "/" + m_username + "/" + "History" + ".txt";
        if (File.Exists(filename))
        {
            using (StreamReader reader = File.OpenText(filename))
            {
                try
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        string[] parts = null;

                        if (line == "")
                        {
                            continue;
                        }
                        else if (line == "BrowseHistoryItem")
                        {
                            line = reader.ReadLine();
                            SelectionScope scope = (SelectionScope)Enum.Parse(typeof(SelectionScope), line);
                            List<int> indexes = new List<int>();

                            line = reader.ReadLine();
                            parts = line.Split(',');
                            foreach (string part in parts)
                            {
                                try
                                {
                                    int index = int.Parse(part);
                                    indexes.Add(index);
                                }
                                catch
                                {
                                    continue;
                                }
                            }

                            SelectionHistoryItem item = new SelectionHistoryItem(m_book, scope, indexes);
                            AddHistoryItem(item);
                        }
                        else if (line == "FindHistoryItem")
                        {
                            FindHistoryItem item = new FindHistoryItem();

                            line = reader.ReadLine();
                            parts = line.Split('\t');
                            if ((parts.Length == 2) && (parts[0].Trim() == "FindType"))
                            {
                                item.FindType = (FindType)Enum.Parse(typeof(FindType), parts[1].Trim());
                            }

                            line = reader.ReadLine();
                            parts = line.Split('\t');
                            if ((parts.Length == 2) && (parts[0].Trim() == "NumberSearchType"))
                            {
                                item.NumberSearchType = (NumberSearchType)Enum.Parse(typeof(NumberSearchType), parts[1].Trim());
                            }

                            line = reader.ReadLine();
                            parts = line.Split('\t');
                            if ((parts.Length == 2) && (parts[0].Trim() == "Text"))
                            {
                                item.Text = parts[1].Trim();
                            }

                            line = reader.ReadLine();
                            parts = line.Split('\t');
                            if ((parts.Length == 2) && (parts[0].Trim() == "Header"))
                            {
                                item.Header = parts[1].Trim();
                            }

                            line = reader.ReadLine();
                            parts = line.Split('\t');
                            if ((parts.Length == 2) && (parts[0].Trim() == "Language"))
                            {
                                item.LanguageType = (LanguageType)Enum.Parse(typeof(LanguageType), parts[1].Trim());
                            }

                            line = reader.ReadLine();
                            parts = line.Split('\t');
                            if ((parts.Length == 2) && (parts[0].Trim() == "Translation"))
                            {
                                item.Translation = parts[1].Trim();
                            }

                            // CSV: Phrase.Verse.Number, Phrase.Text, Phrase.Position
                            while (true)
                            {
                                line = reader.ReadLine();
                                if (line == END_OF_HISTORY_ITME_MARKER)
                                {
                                    break;
                                }
                                parts = line.Split(',');
                                if (parts.Length == 1) // verse.Number
                                {
                                    //TODO: Load NumberQuery with each search result

                                    int verse_index = int.Parse(parts[0].Trim()) - 1;
                                    if ((verse_index >= 0) && (verse_index < m_book.Verses.Count))
                                    {
                                        Verse verse = m_book.Verses[verse_index];
                                        if (!item.Verses.Contains(verse))
                                        {
                                            item.Verses.Add(verse);
                                        }
                                    }
                                }
                                else if (parts.Length == 3) // phrase.Verse.Number,phrase.Text,phrase.Position
                                {
                                    int verse_index = int.Parse(parts[0].Trim()) - 1;
                                    if ((verse_index >= 0) && (verse_index < m_book.Verses.Count))
                                    {
                                        Verse verse = m_book.Verses[verse_index];
                                        if (!item.Verses.Contains(verse))
                                        {
                                            item.Verses.Add(verse);
                                        }

                                        string phrase_text = parts[1].Trim();
                                        if (phrase_text.Length > 0)
                                        {
                                            int phrase_position = int.Parse(parts[2].Trim());
                                            Phrase phrase = new Phrase(verse, phrase_position, phrase_text);
                                            item.Phrases.Add(phrase);
                                        }
                                    }
                                }
                            } // while

                            AddHistoryItem(item);
                        }
                    } // while
                }
                catch
                {
                    throw new Exception("Invalid " + filename + " format.");
                }
            }
        }
    }