Example #1
0
        void DrawObject(DrawingAreaState state, DrawingAreaState.DrawingObject obj, Graphics gr)
        {
            switch (obj.objectType)
            {
            case DrawingAreaState.DrawingObject.ObjectType.PATH:
                DrawingAreaState.PathObject path = (DrawingAreaState.PathObject)obj;

                List <PointF> points     = new List <PointF>();
                List <byte>   pointsType = new List <byte>();

                points.Add(new PointF(path.xpos * state.areaSize.X, path.ypos * state.areaSize.Y));
                pointsType.Add((byte)System.Drawing.Drawing2D.PathPointType.Start);

                for (int i = 0; i < path.anotherXposs.Count(); ++i)
                {
                    points.Add(new PointF(path.anotherXposs[i] * state.areaSize.X, path.anotherYposs[i] * state.areaSize.Y));
                    pointsType.Add((byte)System.Drawing.Drawing2D.PathPointType.Line);
                }

                gr.DrawPath(new Pen(new SolidBrush(path.color), path.thickness * (float)state.areaSize.X), new System.Drawing.Drawing2D.GraphicsPath(points.ToArray(), pointsType.ToArray()));

                break;

            case DrawingAreaState.DrawingObject.ObjectType.RECTANGLE:
                DrawingAreaState.RectangleObject rect = (DrawingAreaState.RectangleObject)obj;

                if (rect.BGColor.A > 0)
                {
                    /*gr.FillRectangle(new SolidBrush(rect.BGColor),
                     *  (rect.xpos + rect.thickness / 2.0f) * state.areaSize.X, (rect.ypos + rect.thickness / 2.0f) * state.areaSize.Y,
                     *  (rect.width - rect.thickness) * state.areaSize.X, (rect.height - rect.thickness) * state.areaSize.Y); */

                    gr.FillRectangle(new SolidBrush(rect.BGColor),
                                     (rect.xpos) * state.areaSize.X, (rect.ypos) * state.areaSize.Y,
                                     (rect.width) * state.areaSize.X, (rect.height) * state.areaSize.Y);
                }
                gr.DrawRectangle(new Pen(new SolidBrush(rect.color), (float)(rect.thickness * (double)state.areaSize.X)),
                                 rect.xpos * state.areaSize.X, rect.ypos * state.areaSize.Y,
                                 rect.width * state.areaSize.X, rect.height * state.areaSize.Y);
                break;

            case DrawingAreaState.DrawingObject.ObjectType.OVAL:
                DrawingAreaState.OvalObject oval = (DrawingAreaState.OvalObject)obj;
                if (oval.BGColor.A > 0)
                {
                    gr.FillEllipse(new SolidBrush(oval.BGColor),
                                   (oval.xpos) * state.areaSize.X, (oval.ypos) * state.areaSize.Y,
                                   (oval.width) * state.areaSize.X, (oval.height) * state.areaSize.Y);
                }
                gr.DrawEllipse(new Pen(new SolidBrush(oval.color), (float)(oval.thickness * (double)state.areaSize.X)),
                               oval.xpos * state.areaSize.X, oval.ypos * state.areaSize.Y,
                               oval.width * state.areaSize.X, oval.height * state.areaSize.Y);
                break;
            }
        }
Example #2
0
        private void drawing_MouseUp(object sender, MouseEventArgs e)
        {
            DrawingAreaState drawingArea = client.clientMachine.drawingArea;

            drawingArea.Access();
            if (drawingArea.state == DrawingAreaState.State.DRAWING)
            {
                DrawingAreaState.DrawingObject obj = drawingArea.tempObject;

                if (client.loggedIn)
                {
                    drawingArea.FinalizeObject(this, drawingArea.tempObject);

                    switch (drawingArea.selectedTool)
                    {
                    case DrawingAreaState.Tools.RECTANGLE:
                        client.clientMachine.SendRectangle((DrawingAreaState.RectangleObject)obj);
                        break;

                    case DrawingAreaState.Tools.OVAL:
                        client.clientMachine.SendOval((DrawingAreaState.OvalObject)obj);
                        break;

                    case DrawingAreaState.Tools.PENCIL:
                        // add one more point to end
                        Point ms = drawingArea.mousepos_start;
                        Point mn = drawingArea.mousepos_now;

                        DrawingAreaState.PathObject path = (DrawingAreaState.PathObject)obj;
                        path.anotherXposs.Add((float)(mn.X) / (float)drawingArea.areaSize.X);
                        path.anotherYposs.Add((float)(mn.Y) / (float)drawingArea.areaSize.Y);

                        client.clientMachine.SendPath((DrawingAreaState.PathObject)obj);
                        break;

                    case DrawingAreaState.Tools.LINE:
                        client.clientMachine.SendPath((DrawingAreaState.PathObject)obj);
                        break;
                    }
                }

                drawingArea.tempObject = null;

                drawingArea.state = DrawingAreaState.State.IDLE;
            }
            drawingArea.Exit();



            drawing.Refresh();
            // RefreshTimer.Interval = 100;
        }
Example #3
0
        private void drawing_MouseMove(object sender, MouseEventArgs e)
        {
            DrawingAreaState drawingArea = client.clientMachine.drawingArea;

            drawingArea.Access();
            drawingArea.mousePosition.X = (float)e.Location.X / (float)drawingArea.areaSize.X;
            drawingArea.mousePosition.Y = (float)e.Location.Y / (float)drawingArea.areaSize.Y;

            if (client.loggedIn && checkBox1.Checked)
            {
                if (mousePositionLastSentTime + new TimeSpan(0, 0, 0, 0, mousePositionSendInterval_ms) < DateTime.Now)
                {
                    mousePositionLastSentTime = DateTime.Now;

                    client.clientMachine.SendMousePosition(drawingArea.mousePosition);
                }
            }


            DrawingAreaState.State drawingAreaState = drawingArea.state;
            if (drawingArea.state == DrawingAreaState.State.DRAWING)
            {
                drawingArea.mousepos_now = new Point(e.X, e.Y);
                Point ms = drawingArea.mousepos_start;
                Point mn = drawingArea.mousepos_now;

                DrawingAreaState.DrawingObject obj = drawingArea.tempObject;
                switch (drawingArea.selectedTool)
                {
                case DrawingAreaState.Tools.LINE:
                    DrawingAreaState.PathObject line = (DrawingAreaState.PathObject)obj;
                    line.anotherXposs.Clear();
                    line.anotherYposs.Clear();
                    line.anotherXposs.Add((float)(mn.X) / (float)drawingArea.areaSize.X);
                    line.anotherYposs.Add((float)(mn.Y) / (float)drawingArea.areaSize.Y);
                    break;

                case DrawingAreaState.Tools.PENCIL:
                    if (pencilLastSentTime + new TimeSpan(0, 0, 0, 0, pencilSendInterval_ms) < DateTime.Now)
                    {
                        pencilLastSentTime = DateTime.Now;

                        DrawingAreaState.PathObject path = (DrawingAreaState.PathObject)obj;
                        path.anotherXposs.Add((float)(mn.X) / (float)drawingArea.areaSize.X);
                        path.anotherYposs.Add((float)(mn.Y) / (float)drawingArea.areaSize.Y);

                        if (path.anotherXposs.Count > 300)
                        {
                            // dirty fix -> every 5 seconds end existing path and begin next to circumvent overflow exception.
                            drawingArea.Exit();
                            drawing_MouseUp(sender, e);
                            drawing_MouseDown(sender, e);
                            drawingArea.Access();
                        }
                    }


                    break;

                case DrawingAreaState.Tools.RECTANGLE:
                    DrawingAreaState.RectangleObject rect = (DrawingAreaState.RectangleObject)obj;
                    rect.xpos   = (mn.X - ms.X) > 0 ? ((float)ms.X / (float)drawingArea.areaSize.X) : ((float)mn.X / (float)drawingArea.areaSize.X);
                    rect.ypos   = (mn.Y - ms.Y) > 0 ? ((float)ms.Y / (float)drawingArea.areaSize.Y) : ((float)mn.Y / (float)drawingArea.areaSize.Y);
                    rect.width  = (mn.X - ms.X) > 0 ? ((float)(mn.X - ms.X) / (float)drawingArea.areaSize.X) : ((float)(ms.X - mn.X) / (float)drawingArea.areaSize.X);
                    rect.height = (mn.Y - ms.Y) > 0 ? ((float)(mn.Y - ms.Y) / (float)drawingArea.areaSize.Y) : ((float)(ms.Y - mn.Y) / (float)drawingArea.areaSize.Y);
                    break;

                case DrawingAreaState.Tools.OVAL:
                    DrawingAreaState.OvalObject oval = (DrawingAreaState.OvalObject)obj;
                    oval.xpos   = (mn.X - ms.X) > 0 ? ((float)ms.X / (float)drawingArea.areaSize.X) : ((float)mn.X / (float)drawingArea.areaSize.X);
                    oval.ypos   = (mn.Y - ms.Y) > 0 ? ((float)ms.Y / (float)drawingArea.areaSize.Y) : ((float)mn.Y / (float)drawingArea.areaSize.Y);
                    oval.width  = (mn.X - ms.X) > 0 ? ((float)(mn.X - ms.X) / (float)drawingArea.areaSize.X) : ((float)(ms.X - mn.X) / (float)drawingArea.areaSize.X);
                    oval.height = (mn.Y - ms.Y) > 0 ? ((float)(mn.Y - ms.Y) / (float)drawingArea.areaSize.Y) : ((float)(ms.Y - mn.Y) / (float)drawingArea.areaSize.Y);
                    break;
                }
            }
            drawingArea.Exit();

            if (drawingAreaState == DrawingAreaState.State.DRAWING || drawingAreaState == DrawingAreaState.State.EDITING)
            {
                drawing.Refresh();
            }

            /*
             * drawingArea.Access();
             * drawingArea.mousePositions["nkpkiller"] = new DrawingAreaState.MousePosition((float)(e.X) / (float)drawingArea.areaSize.X, (float)(e.Y) / (float)drawingArea.areaSize.Y, "nkpkiller");
             * drawingArea.Exit();
             */

            Application.DoEvents();
            // drawing.Refresh();
        }