public void Draw(SpriteBatch spriteBatch, GraphicsDeviceManager graphics) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Draw(background, new Vector2(0, 0), Color.White); TennisBall.Draw(spriteBatch); Panel.Draw(spriteBatch); JumpButton.Draw(spriteBatch); EndBlock.Draw(spriteBatch); gui.Draw(spriteBatch); spriteBatch.Draw(cursorTexture, cursorRectangle, Color.White); }
// picture box mouse down event private void pictureBox_MouseDown(object sender, MouseEventArgs e) { // disable buttons during block moving if (scrollDown) { return; } // if block has to start moving if (e.Button == MouseButtons.Middle && selected != null && !linking) { scrollDown = true; pictureBoxImage = CreateImageWithoutSelectedBlock(selected); xDis = selected.X - e.X; yDis = selected.Y - e.Y; } // (un)select block if (e.Button == MouseButtons.Right) { SelectBlock(e.X, e.Y); RefreshScheme(); pictureBoxImage = (Image)pictureBox.Image.Clone(); } // left click mouse interaction if (e.Button == MouseButtons.Left) { // create operation block if (button == OperationBoxButton) { canvas = Graphics.FromImage(pictureBox.Image); OperatingBlock bloc = new OperatingBlock(e.X, e.Y, resourceManager.GetString("OperationBlock")); bloc.Draw(canvas); blockList.Add(bloc); } // create decide block else if (button == DecidingBoxButton) { canvas = Graphics.FromImage(pictureBox.Image); DecidingBlock bloc = new DecidingBlock(e.X, e.Y, resourceManager.GetString("DecideBlock")); bloc.Draw(canvas); blockList.Add(bloc); } // create start block else if (button == startBoxButton) { if (FindNearestBlock((Block b) => { if (b.GetType().Name == "StartBlock") { return(true); } else { return(false); } }, blockList, e.X, e.Y) == null) { // create canvas = Graphics.FromImage(pictureBox.Image); StartBlock bloc = new StartBlock(e.X, e.Y, resourceManager.GetString("StartBlock")); bloc.Draw(canvas); blockList.Add(bloc); } else { // if already exist then show message MessageBox.Show(resourceManager.GetString("DoubleStartBlockWarning")); } } //create end block else if (button == endBoxButton) { canvas = Graphics.FromImage(pictureBox.Image); EndBlock bloc = new EndBlock(e.X, e.Y, resourceManager.GetString("StopBlock")); bloc.Draw(canvas); blockList.Add(bloc); } // start link creating else if (button == linkButton) { LinkPoint x = null; foreach (Block block in blockList) { if ((x = block.CheckPoint(e.X, e.Y, false)) != null) { selectedLinkPoint = x; } } if (selectedLinkPoint != null) { linking = true; pictureBox.Refresh(); pictureBoxImage = (Image)pictureBox.Image.Clone(); } } // delete block else if (button == deleteButton) { Block removed = FindNearestBlock((Block block) => block.Click(e.X, e.Y), blockList, e.X, e.Y); if (removed != null) { textSelectedBlock.Enabled = false; textSelectedBlock.Text = ""; if (selected == removed) { selected = null; } removed.Remove(); blockList.Remove(removed); } RefreshScheme(); } } pictureBox.Refresh(); }