/** * Setup the specific coordinates of the split areas * Store the width and height the user selected * Store the total width and height of the rectangular region drawn * Store x and y coordinates, will always have 0 in them, so a list with two elements is one number range (0 to num1) * Another example: The list has three elements, so two numbers ranges (0 to num1, num1 to num2) * Store the number of times the total width and height of the rectangle divides by each * Calculate the remainder if the size of each width or height doesn't divide evenly * Add the number ranges to the width and height list * Add the remainder value to the final value in the array, this means that the final slice may be bigger than the rest * */ public static void setSplitAreas(int selectedIndex) { int eachWidth = dimensionWidths[selectedIndex]; int eachHeight = dimensionHeights[selectedIndex]; int totalRectangleWidth = SnippingTool.getRectangleWidth(); int totalRectangleHeight = SnippingTool.getRectangleHeight(); xCoordinates = new List <int>(); yCoordinates = new List <int>(); xCoordinates.Add(0); yCoordinates.Add(0); int numberOfWidthDivisions = totalRectangleWidth / eachWidth; int numberOfHeightDivisions = totalRectangleHeight / eachHeight; int remainderWidth = totalRectangleWidth % eachWidth; int remainderHeight = totalRectangleHeight % eachHeight; for (int i = 0; i < numberOfWidthDivisions; i++) { xCoordinates.Add(eachWidth + xCoordinates[i]); } for (int i = 0; i < numberOfHeightDivisions; i++) { yCoordinates.Add(eachHeight + yCoordinates[i]); } xCoordinates[numberOfWidthDivisions] = xCoordinates[numberOfWidthDivisions] + remainderWidth; yCoordinates[numberOfHeightDivisions] = yCoordinates[numberOfHeightDivisions] + remainderHeight; }
/** * When start button clicked, stores rectangle coordinates * x1 and x2 are the upper left and right corner * x1 and x2 are the lower left and right corner * checkClickInterval runs to see the time between clicks * Checks mouse speed function needed and stores the method to a variable * runManualOrAutomatic runs to see how the program will end * */ private void startButton_Click(object sender, EventArgs e) { x1 = SnippingTool.getDrawnRectangle().X; x2 = SnippingTool.getDrawnRectangle().X + SnippingTool.getRectangleWidth(); y1 = SnippingTool.getDrawnRectangle().Y; y2 = SnippingTool.getDrawnRectangle().Y + SnippingTool.getRectangleHeight(); checkClickInterval(comboBoxClickEvery, numericClickEveryMin.Value, numericClickEveryMax.Value); moveAtMouseSpeed = checkMouseSpeed(); runManualOrAutomatic(); }
/** * Listener method that runs when a tab is clicked * If basic tab selected, resizes form back to its original size * If advanced tab selected, sets the label and other components accordingly * If the displayed width or height does not match the rectangle, updates the display * If preview tab selected, shows the user's selection * Resizes the preview tab to display the entire image, accounting for the form's borders cutting off part of the image * If splitting the region into sub-areas, the preview tab will show the image with red lines drawn as dividers * */ private void tabControl1_SelectedIndexChanged(Object sender, EventArgs e) { bool basicTabSelected = tabControl1.SelectedIndex == 0; bool advancedTabSelected = tabControl1.SelectedIndex == 1; bool previewTabSelected = tabControl1.SelectedIndex == 2; widthNotZero = SnippingTool.getRectangleWidth() != 0; heightNotZero = SnippingTool.getRectangleHeight() != 0; if (basicTabSelected) { resizeFormToDefault(); } else if (advancedTabSelected && widthNotZero && heightNotZero) { resizeFormToDefault(); labelWidthHeight.Text = "The area has a width of " + SnippingTool.getRectangleWidth() + " pixels\r\n" + " and a height of " + SnippingTool.getRectangleHeight() + " pixels. Starting from: (" + SnippingTool.getDrawnRectangle().X + "," + SnippingTool.getDrawnRectangle().Y + ")"; checkBoxDivideInto.Enabled = true; if (displayedWidth != SnippingTool.getRectangleWidth() || displayedHeight != SnippingTool.getRectangleHeight()) { divideIntoEqualAreasDisplay(); } } else if (previewTabSelected && widthNotZero && heightNotZero) { previewPictureBox.Visible = true; labelPreviewInstructions.Visible = false; if (SnippingTool.Image.Width > tabControl1.Width) { this.Width = SnippingTool.Image.Width + (this.Width - tabControl1.Width) + 8; } if (SnippingTool.Image.Height > tabControl1.Height) { this.Height = SnippingTool.Image.Height + (this.Height - tabControl1.Height) + 25; } if (checkBoxDivideInto.Checked) { ImageSplitter.drawSplitImage(comboBoxDividedAreas.SelectedIndex, numericDivideIntoEqualAreas.Value); previewPictureBox.Image = ImageSplitter.drawnImage; } else { previewPictureBox.Image = SnippingTool.Image; } } }
/** * Gets the width and height of the drawn region * Sets up a dictionary to pair factors * Sets up two lists to hold each individual width and height * */ private static void pairFactorizations() { width = SnippingTool.getRectangleWidth(); height = SnippingTool.getRectangleHeight(); dimensions = new Dictionary <int, int>(); dimensionWidths = new List <int>(); dimensionHeights = new List <int>(); foreach (int factor in primeFactors) { pair(factor); } }
/** * Draws red lines over the image when user views preview tab * Store the width and height the user selected * Store the total width and height of the rectangular region drawn * Store the original region so that the newly drawn image can be reverted back * */ public static void drawSplitImage(int selectedIndex, decimal dividers) { int eachWidth = dimensionWidths[selectedIndex]; int eachHeight = dimensionHeights[selectedIndex]; int totalRectangleWidth = SnippingTool.getRectangleWidth(); int totalRectangleHeight = SnippingTool.getRectangleHeight(); drawnImage = (Image)SnippingTool.Image.Clone(); using (Graphics g = Graphics.FromImage(drawnImage)) { Color customColor = Color.FromArgb(50, Color.Gray); SolidBrush brush = new SolidBrush(customColor); g.FillRectangles(brush, new RectangleF[] { new RectangleF(new PointF(0.0F, 0.0F), new SizeF((float)totalRectangleWidth, (float)totalRectangleHeight)) }); customColor = Color.FromArgb(255, Color.Red); brush = new SolidBrush(customColor); //Draws horizontal lines, by moving along the height of the rectangle for (int i = 1; i < dividers; i++) { g.FillRectangles(brush, new RectangleF[] { new RectangleF(new PointF(0.0F, (float)eachHeight * i), new SizeF((float)totalRectangleWidth, 5.0F)) }); } //Drawrs vertical lines, by moving along the width rectangle for (int i = 1; i < dividers; i++) { g.FillRectangles(brush, new RectangleF[] { new RectangleF(new PointF((float)eachWidth * i, 0.0F), new SizeF(5.0F, (float)totalRectangleHeight)) }); } } }