コード例 #1
0
        public override bool HandleEvent(Gdk.Event evnt)
        {
            Gdk.EventButton eventButton = evnt as Gdk.EventButton;
            if (eventButton != null)
            {
                if (eventButton.Type == Gdk.EventType.ButtonPress)
                {
                    isDragging = true;
                    //selected = false;
                    FocusedRectangle  = default(Rectangle);
                    firstX            = eventButton.X;
                    firstY            = eventButton.Y;
                    intercationObject = new FocusRectangleShape(new Rectangle(firstX, firstY, 0, 0));
                    //
                    InteractionStateModel interState = this.Model.GetSubModel <InteractionStateModel>();
                    this.Model.BeginUpdate();
                    interState.Interaction.Add(intercationObject);
                    this.Model.EndUpdate();
                    //
                    return(true);
                }
                else if (eventButton.Type == Gdk.EventType.ButtonRelease)
                {
                    if (isDragging)
                    {
                        isDragging = false;
                        this.Model.BeginUpdate();
                        this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                        this.Model.EndUpdate();
                        FocusedRectangle  = intercationObject.Rectangle;
                        intercationObject = null;
                        //selected = true;
                        OnFocusedRectangleFinish();
                        return(true);
                    }
                }
            }

            Gdk.EventMotion eventMotion = evnt as Gdk.EventMotion;
            if (eventMotion != null)
            {
                if (isDragging)
                {
                    this.Model.BeginUpdate();

                    /*using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                     * foreach (Shape shape in this.Model.GetSubModel<InteractionStateModel>().Interaction) {
                     *  context.Save();
                     *  context.Matrix = shape.Matrix;
                     *  Distance dist = shape.DistanceToLocal(new Distance(eventMotion.X - lastX, eventMotion.Y - lastY), context);
                     *  shape.Matrix.Translate(dist.Dx, dist.Dy);
                     *  context.Restore();
                     * }
                     * }*/
                    intercationObject.Width  = eventMotion.X - firstX;
                    intercationObject.Height = eventMotion.Y - firstY;
                    //intercationObject.Rectangle = new Rectangle(
                    //  intercationObject.Rectangle.X, intercationObject.Rectangle.Y,
                    //  eventMotion.X - intercationObject.Rectangle.X, eventMotion.Y - intercationObject.Rectangle.Y
                    //);
                    this.Model.EndUpdate();
                    return(true);
                }
            }

            Gdk.EventKey eventKey = evnt as Gdk.EventKey;
            if (eventKey != null)
            {
                if (isDragging && eventKey.Key == Gdk.Key.Escape)
                {
                    this.Model.BeginUpdate();
                    this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                    this.Model.EndUpdate();
                    intercationObject = null;
                    isDragging        = false;
                    //selected = false;
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        public override bool HandleEvent(Gdk.Event evnt)
        {
            Gdk.EventButton eventButton = evnt as Gdk.EventButton;
            if (eventButton != null)
            {
                if (eventButton.Type == Gdk.EventType.ButtonPress)
                {
                    using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                        foreach (Shape shape in this.Model.GetSubModel <ShapesModel>().Shapes)
                        {
                            if (shape is ConnectorShape)
                            {
                                Glue g = CheckGlues(new PointD(eventButton.X, eventButton.Y), context, (shape as ConnectorShape).FromGlue, (shape as ConnectorShape).ToGlue);
                                if (g != null)
                                {
                                    dragGlue      = g;
                                    isDragging    = true;
                                    moved         = false;
                                    dragConnector = shape as ConnectorShape;
                                    //
                                    InteractionStateModel interState = this.Model.GetSubModel <InteractionStateModel>();
                                    this.Model.BeginUpdate();
                                    ConnectorShape interDragConnector = dragConnector.DeepCopy();
                                    interState.Interaction.Add(interDragConnector);
                                    Glue interDragGlue = dragGlue.DeepCopy();
                                    if (dragGlue == dragConnector.FromGlue)
                                    {
                                        interDragConnector.FromGlue = interDragGlue;
                                    }
                                    else
                                    {
                                        interDragConnector.ToGlue = interDragGlue;
                                    }
                                    interDragGlue.Parent = null;
                                    interDragGlue.Matrix.InitIdentity();
                                    interDragGlue.Center = new PointD(eventButton.X, eventButton.Y);
                                    interState.Interaction.Add(interDragGlue);
                                    this.Model.EndUpdate();
                                    //
                                    return(true);
                                }
                            }
                        }
                    }
                    foreach (Shape shape in this.Model.GetSubModel <SelectionModel>().Selected)
                    {
                        if (shape is ConnectorShape)
                        {
                            return(true);
                        }
                    }
                }
                else if (eventButton.Type == Gdk.EventType.ButtonRelease)
                {
                    if (dragGlue != null)
                    {
                        using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                            foreach (Shape shape in this.Model.GetSubModel <ShapesModel>().Shapes)
                            {
                                List <Shape> glues = new List <Shape>();
                                foreach (Shape subShape in shape.Items)
                                {
                                    if (subShape is Glue)
                                    {
                                        glues.Add(subShape);
                                    }
                                }
                                Glue g = CheckGlues(new PointD(eventButton.X, eventButton.Y), context, glues);
                                if (g != null)
                                {
                                    this.Model.BeginUpdate();

                                    if (dragGlue == dragConnector.FromGlue)
                                    {
                                        dragConnector.FromGlue = g;
                                        dragConnector.From     = g.Parent;
                                    }
                                    else
                                    {
                                        dragConnector.ToGlue = g;
                                        dragConnector.To     = g.Parent;
                                    }

                                    this.Model.EndUpdate();

                                    break;
                                }
                            }
                        }

                        this.Model.BeginUpdate();
                        this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                        this.Model.EndUpdate();

                        isDragging = false;
                        dragGlue   = null;
                        return(true);
                    }
                }
            }

            Gdk.EventMotion eventMotion = evnt as Gdk.EventMotion;
            if (eventMotion != null)
            {
                if (isDragging && dragGlue != null)
                {
                    this.Model.BeginUpdate();
                    ConnectorShape interConnector = (ConnectorShape)this.Model.GetSubModel <InteractionStateModel>().Interaction[0];
                    Glue           interDragGlue  = (Glue)this.Model.GetSubModel <InteractionStateModel>().Interaction[1];
                    interDragGlue.Center = new PointD(eventMotion.X, eventMotion.Y);
                    this.Model.EndUpdate();
                    moved = true;
                    return(true);
                }
            }

            return(base.HandleEvent(evnt));
        }
コード例 #3
0
        public override bool HandleEvent(Gdk.Event evnt)
        {
            Gdk.EventButton eventButton = evnt as Gdk.EventButton;
            if (eventButton != null)
            {
                if (eventButton.Type == Gdk.EventType.ButtonPress)
                {
                    isDragging = true;
                    moved      = false;
                    firstX     = eventButton.X;
                    firstY     = eventButton.Y;
                    lastX      = firstX;
                    lastY      = firstY;
                    //
                    using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                        ViewMode oldViewMode = View.Mode;
                        View.Mode = ViewMode.Select;
                        foreach (Shape shape in this.Model.GetSubModel <SelectionModel>().Selected)
                        {
                            if (shape.IsPointInShape(new PointD(eventButton.X, eventButton.Y), context, View))
                            {
                                InteractionStateModel interState = this.Model.GetSubModel <InteractionStateModel>();
                                this.Model.BeginUpdate();
                                interState.Interaction.AddRange((List <Shape>) this.Model.GetSubModel <SelectionModel>().Selected.DeepCopy());
                                this.Model.EndUpdate();
                                View.Mode = oldViewMode;
                                return(true);
                            }
                        }
                        View.Mode = oldViewMode;
                    }
                    //
                    isDragging = false;
                    return(false);
                }
                else if (eventButton.Type == Gdk.EventType.ButtonRelease)
                {
                    if (isDragging)
                    {
                        isDragging = false;
                        this.Model.BeginUpdate();
                        using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                            foreach (Shape shape in this.Model.GetSubModel <SelectionModel>().Selected)
                            {
                                context.Save();
                                context.Matrix = shape.Matrix;
                                Distance dist = shape.DistanceToLocal(new Distance(eventButton.X - firstX, eventButton.Y - firstY), context);
                                shape.Matrix.Translate(dist.Dx, dist.Dy);
                                context.Restore();
                            }
                        }
                        this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                        this.Model.EndUpdate();
                        return(true);
                    }
                }
            }

            Gdk.EventMotion eventMotion = evnt as Gdk.EventMotion;
            if (eventMotion != null)
            {
                if (isDragging)
                {
                    this.Model.BeginUpdate();
                    using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                        foreach (Shape shape in this.Model.GetSubModel <InteractionStateModel>().Interaction)
                        {
                            context.Save();
                            context.Matrix = shape.Matrix;
                            Distance dist = shape.DistanceToLocal(new Distance(eventMotion.X - lastX, eventMotion.Y - lastY), context);
                            shape.Matrix.Translate(dist.Dx, dist.Dy);
                            context.Restore();
                        }
                    }
                    this.Model.EndUpdate();
                    lastX = eventMotion.X;
                    lastY = eventMotion.Y;
                    moved = true;
                    return(true);
                }
            }

            Gdk.EventKey eventKey = evnt as Gdk.EventKey;
            if (eventKey != null)
            {
                if (isDragging && eventKey.Key == Gdk.Key.Escape)
                {
                    this.Model.BeginUpdate();
                    this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                    this.Model.EndUpdate();
                    isDragging = false;
                    moved      = false;
                    return(true);
                }
            }

            return(false);
        }