Ejemplo n.º 1
0
        private void frm3DSurfaceGraphViewer_MouseDown(object sender, MouseEventArgs e)
        {
            /*if (e.Button == MouseButtons.Left)
             * {
             *  // rotate
             *  this.Cursor = GenerateCursor("Turn");
             * }
             * else if (e.Button == MouseButtons.Right)
             * {
             *  // pan
             *  this.Cursor = GenerateCursor("Pan");
             * }
             * m_IsDragging = true;
             * m_p = e.Location;
             * //Invalidate();*/
            double d = 0.0;
            PointF p = new PointF();
            bool   b = sr.GetMousePoint(e.X, e.Y, out p, out d);
            string s = b.ToString() + " | " + p.ToString() + " | " + d.ToString();

            // if (b) System.Diagnostics.Debug.Write("\nMouseDown: " + s + "\n");

            if (e.Button == MouseButtons.Left)
            {
                // rotate
                this.Cursor = GenerateCursor("Turn");
            }
            else if (e.Button == MouseButtons.Right)
            {
                // pan
                this.Cursor = GenerateCursor("Pan");
            }
            m_IsDragging = true;
            m_p          = e.Location;
        }
        private void frm3DSurfaceGraphViewer_MouseMove(object sender, MouseEventArgs e)
        {
            /*if (m_IsDragging)
             * {
             *  if (e.Button == MouseButtons.Left)
             *  {
             *      int deltay = m_p.X - e.Location.X;
             *      int deltax = m_p.Y - e.Location.Y;
             *      //PointF f = sr.Project(0, 0, 0);
             *
             *      pov_y += deltay / 2;
             *      pov_x -= deltay / 2;
             *      //pov_z -= deltay / 2;
             *     // pov_y += deltax / 2;
             *      //int deltaz = m_p.Y - e.Location.Y;
             *      pov_z -= deltax / 2;
             *  }
             *  else if (e.Button == MouseButtons.Right)
             *  {
             *      int deltax = m_p.X - e.Location.X;
             *      int deltay = m_p.Y - e.Location.Y;
             *      pan_x -= deltax / 2;
             *      pan_y -= deltay / 2;
             *  }
             *
             *  sr.ReCalculateTransformationsCoeficients(pov_x, pov_y, pov_z, pan_x, pan_y, ClientRectangle.Width, ClientRectangle.Height, pov_d, 0, 0);
             *  CastGraphChangedEvent();
             *  Invalidate();
             *  m_p = e.Location;
             * }
             * else
             * {
             *  // waarden van punten weergeven als in de buurt
             *  //PointF tableposition = new Point(0,0);
             *  //double val = 0;
             *  //if (sr.GetMousePoint(e.X, e.Y, out tableposition, out val))
             *  //{
             *      //Console.WriteLine("Position = " + e.X.ToString() + ":" + e.Y.ToString() + " tablepos = " + tableposition.X.ToString() + ":" + tableposition.Y.ToString() + " value = " + val.ToString());
             * //                    m_lastMouseHoverPoint = new PointF((float)e.X, (float)e.Y);
             *      //toolTipController1.ShowHint("Mouse hit : " + m_lastMouseHoverPoint.X.ToString() + ":" + m_lastMouseHoverPoint.Y.ToString(), PointToClient(e.Location));
             *  //}
             * }*/
            if (m_IsDragging)
            {
                if (e.Button == MouseButtons.Left)
                {
                    int deltay = m_p.X - e.Location.X;
                    int deltax = m_p.Y - e.Location.Y;

                    pov_y += deltay / 2;
                    pov_x -= deltay / 2;
                    pov_z -= deltax / 2;
                }
                else if (e.Button == MouseButtons.Right)
                {
                    int deltax = m_p.X - e.Location.X;
                    int deltay = m_p.Y - e.Location.Y;
                    pan_x -= deltax / 2;
                    pan_y -= deltay / 2;
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    try
                    {
                        MapViewer mv  = ((MapViewer)this.ParentForm.Controls.Find("MapViewer", true)[0]);
                        int       pos = (lastPointY * this.Mapdata.Columns.Count) + lastPointX;
                        //TODO: make this work for 2 bytes maps as well (16 bits)

                        if (m_p.Y - e.Location.Y > 0)
                        {
                            if ((int)mv.Map_content[pos] != 255)
                            {
                                mv.Map_content[pos] = (byte)((int)mv.Map_content[pos] + 1);
                            }
                        }
                        else
                        {
                            if ((int)mv.Map_content[pos] != 0)
                            {
                                mv.Map_content[pos] = (byte)((int)mv.Map_content[pos] - 1);
                            }
                        }

                        // save user's xyz view of graph so we can set it back after the tableview "resets" the layout
                        int    __pov_x = pov_x, __pov_y = pov_y, __pov_z = pov_z;
                        int    __pan_x = pan_x, __pan_y = pan_y;
                        double __pov_d = pov_d;

                        // refresh datatable
                        mv.ReShowTable();

                        pov_x = __pov_x;
                        pov_y = __pov_y;
                        pov_d = __pov_d;
                        pan_x = __pan_x;
                        pan_y = __pan_y;
                    }
                    catch { }
                }
            }
            else
            {
                double d = 0.0;
                PointF p = new PointF();
                bool   b = sr.GetMousePoint(e.X, e.Y, out p, out d);

                if (b && !m_IsDragging)
                {
                    lastPointX = sr.Mapdata.Columns.Count - (int)p.Y - 1;
                    lastPointY = sr.Mapdata.Rows.Count - (int)p.X - 1;
                    sr.HighlightSelectionInGraph(lastPointX, lastPointY);
                }
            }
            sr.ReCalculateTransformationsCoeficients(pov_x, pov_y, pov_z, pan_x, pan_y, ClientRectangle.Width, ClientRectangle.Height, pov_d, 0, 0);
            CastGraphChangedEvent();
            Invalidate();
            m_p = e.Location;
        }