예제 #1
0
        private void btnUpdOrder_Click(object sender, EventArgs e)
        {
            selectIndex = listBox1.SelectedIndex;
            Debug.WriteLine(selectIndex.ToString() + " is selected ");

            int X = Convert.ToInt32(txtXpos.Text);
            int Y = Convert.ToInt32(txtYpos.Text);

            ArrayList theOrderList = myModel.OrderList;

            AnyMeal[] theMeals = (AnyMeal[])theOrderList.ToArray(typeof(AnyMeal));
            AnyMeal   am       = theMeals[selectIndex];

            am.x_pos = X;
            am.y_pos = Y;

            myModel.UpdateViews();
        }
예제 #2
0
        private void pnlDrawOn_MouseMove(object sender, MouseEventArgs e)
        {
            // set last position to current position
            lastPosition = currentPosition;
            // set current position to mouse position
            currentPosition = new Point(e.X, e.Y);
            // calculate how far mouse has moved
            int xMove = currentPosition.X - lastPosition.X;
            int yMove = currentPosition.Y - lastPosition.Y;

            if (!dragging) // mouse not down
            {
                // reset variables
                topShape = null;
                bool needsDisplay = false;

                /*
                 * // create arrayList of shaapes from myModel
                 * ArrayList theShapeList = myModel.ShapeList;
                 * // create array of shapes from array list
                 * AnyShape[] theShapes = (AnyShape[])theShapeList.ToArray(typeof(AnyShape));
                 * // graphics object to draw shapes when required
                 * Graphics g = this.pnlDrawOn.CreateGraphics();
                 */

                // create arrayList of shaapes from myModel
                ArrayList theOrderList = myModel.OrderList;
                // create array of shapes from array list
                AnyMeal[] theMeals = (AnyMeal[])theOrderList.ToArray(typeof(AnyMeal));
                // graphics object to draw shapes when required
                Graphics g = this.pnlDrawOn.CreateGraphics();

                // loop through array checking if mouse is over shape
                foreach (AnyMeal s in theMeals)
                {
                    // check if mouse is over shape
                    if (s.HitTest(new Point(e.X, e.Y)))
                    {
                        // if so make shape topShape
                        topShape = s;
                    }

                    if (s.Highlight == true)
                    {
                        // shape to be redrawn
                        needsDisplay = true;
                        // redraw shape
                        s.Display(g);
                        s.Highlight = false;
                    }
                    // 30 Oct moved this piece up to before highlight test
                    //					if (s.HitTest(new Point(e.X, e.Y)))// check if mouse is over shape
                    //					{
                    //						topShape = s; // make shape topShape
                    //					}
                }

                if (topShape != null)    // if there is a topShape
                {
                    needsDisplay = true; // need to redisplay
                    topShape.Display(g); // redisplay topShape
                    topShape.Highlight = true;
                }

                if (needsDisplay)
                {
                    // redisplay model
                    myModel.UpdateViews();
                }
            }
            else // mouse is down
            {
                // reset position of selected shape by value of mouse move
                topShape.x_pos = topShape.x_pos + xMove;
                topShape.y_pos = topShape.y_pos + yMove;

                myModel.UpdateViews();
            }
        }