Exemple #1
0
        private void MdiChild_MouseUp(object sender, MouseEventArgs e)
        {
            MainForm parent = GetParent();
            if(e.Button == MouseButtons.Left) {

                if(isDrawing) {
                    bufferedGraphics.Render();
                    if(currentFigure.IsInside(imageSize)) {
                        if (currentFigure is Text)
                        {
                            MyTextBox textBox = new MyTextBox ( currentFigure as Text, this , MdiParent as MainForm);
                            textBox.Show(AutoScrollPosition.X, AutoScrollPosition.Y);
                        }
                        if(parent.GridAutoDrag){
                            currentFigure.DragToGrid ( parent.GridStep, imageSize );
                        }
                        listFigures.Add(currentFigure);
                    }
                    isModified = true;
                }

                if (isSelecting){

                    int X = e.X - AutoScrollPosition.X;
                    int Y = e.Y - AutoScrollPosition.Y;

                    if (X == clickPoint.X && Y == clickPoint.Y){
                        bool select = false;
                        foreach (Figure figure in listFigures){
                            if(figure.Contains ( clickPoint )){
                                select = true;
                                figure.Selected = true;
                            }
                        }

                        if(!select)
                            UnselectAllFigures();

                    }
                }

                if(isMoving){
                    int X = e.X - AutoScrollPosition.X;
                    int Y = e.Y - AutoScrollPosition.Y;

                    int shiftX = X - clickPoint.X;
                    int shiftY = Y - clickPoint.Y;

                    bool fits = true;
                    foreach(Figure figure in movingFigures){
                        if (! figure.IsInside ( imageSize, shiftX, shiftY )){
                            fits = false;
                            break;
                        }
                    }
                    if(fits){
                        foreach(Figure figure in movingFigures) {
                            figure.Move ( shiftX, shiftY );
                            if(parent.GridAutoDrag) {
                                figure.DragToGrid(parent.GridStep, imageSize);
                            }
                        }
                        isModified = true;
                    }
                }

                if(isEditedResizing){
                    int X = e.X - AutoScrollPosition.X;
                    int Y = e.Y - AutoScrollPosition.Y;

                    int shiftX = X - clickPoint.X;
                    int shiftY = Y - clickPoint.Y;

                    editedFigure.Resize (shiftX, shiftY, resizingType, imageSize );
                    isModified = true;

                    if(parent.GridAutoDrag)
                        editedFigure.DragToGrid ( parent.GridStep, imageSize );
                }

                currentFigure = null;
                movingFigures.Clear();

                isDrawing = false;
                isSelecting = false;
                isMoving = false;
                isEditedResizing = false;

                Invalidate();
            }
        }
Exemple #2
0
 private void MdiChild_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     MainForm parent = GetParent();
     if(parent.SelectMode){
         UnselectAllFigures();
         foreach (Figure figure in listFigures){
             if ( figure.Contains ( clickPoint ) ){
                 figure.Edited = true;
                 editedFigure = figure;
                 isEditing = true;
                 break;
             }
         }
         if(editedFigure != null && editedFigure is Text) {
             MyTextBox textBox = new MyTextBox(editedFigure as Text, this, MdiParent as MainForm);
             textBox.Show(AutoScrollPosition.X, AutoScrollPosition.Y);
         }
     }
 }
Exemple #3
0
        // events' handlers
        private void MdiChild_MouseDown(object sender, MouseEventArgs e)
        {
            clickPoint = new Point(e.X - AutoScrollPosition.X, e.Y - AutoScrollPosition.Y);

            if(e.Button == MouseButtons.Left){
                MainForm par = (MainForm) MdiParent;

                if(isEditing && editedFigure!= null && editedFigure.Contains(clickPoint)) {
                    if((resizingType = editedFigure.MarkersContain(clickPoint)) != Marker.NONE)
                        isEditedResizing = true;
                    else{
                        isMoving = true;
                        movingFigures.Add ( editedFigure );
                    }
                }
                else{
                    if ( editedFigure != null ){
                        editedFigure.Edited = false;
                        editedFigure = null;
                    }
                    isEditing = isEditedResizing = false;

                    if ( !par.SelectMode ){
                        isDrawing = true;
                        int X = clickPoint.X;
                        int Y = clickPoint.Y;
                        switch (par.currentFigure){
                            case Figures.Rectangle:
                                currentFigure = new Rect ( new Point ( X, Y ), new Point ( X, Y ), par.ColorLine, par.ColorBackground,
                                                           par.PenWidth, par.Fill );
                                break;
                            case Figures.Ellipse:
                                currentFigure = new Ellipse ( new Point ( X, Y ), new Point ( X, Y ), par.ColorLine, par.ColorBackground,
                                                              par.PenWidth, par.Fill );
                                break;
                            case Figures.Line:
                                currentFigure = new Line ( new Point ( X, Y ), new Point ( X, Y ), par.ColorLine, par.ColorBackground,
                                                           par.PenWidth, par.Fill );
                                break;
                            case Figures.Curve:
                                currentFigure = new Curve ( new Point ( X, Y ), new Point ( X, Y ), par.ColorLine, par.ColorBackground,
                                                            par.PenWidth, par.Fill );
                                break;
                            case Figures.Text:
                                currentFigure = new Text ( new Point ( X, Y ), new Point ( X, Y ), par.ColorLine, par.ColorBackground,
                                                           par.PenWidth, par.Fill, par.Font );
                                break;
                        }
                    }
                    else{
                        bool select = false;
                        bool hit = false;
                        foreach (Figure figure in listFigures){
                            if ( figure.Contains ( clickPoint ) ){
                                hit = true;
                                if ( !figure.Selected ){
                                    select = true;
                                }
                            }
                        }

                        if ( !hit || select ){
                            isSelecting = true;
                        }
                        if ( hit && !select ){
                            isMoving = true;

                            // add figures to moving set
                            foreach (Figure figure in listFigures){
                                if ( figure.Selected ){
                                    movingFigures.Add ( figure );
                                }
                            }
                        }
                    }
                }
            }
            else if(e.Button == MouseButtons.Middle) {
                currentFigure = null;
                listFigures.Clear();
                isDrawing = false;
            }

            Invalidate();
        }
Exemple #4
0
        public void UnselectAllFigures()
        {
            foreach(Figure figure in listFigures){
                figure.Selected = false;
            }

            if(editedFigure != null) {
                editedFigure.Edited = false;
                editedFigure = null;
            }
            isEditing = false;
        }