/** * 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; } } }
/** * Runs if ending automatically from a certain number of clicks * If choosing to divide the region into areas, sets the areas to be clicked * Clicks each area * Otherwise clicks randomly until finished, since not choosing to divide into areas * */ private void checkForDividedAreas(decimal duration) { if (checkBoxDivideInto.Checked) { ImageSplitter.setSplitAreas(comboBoxDividedAreas.SelectedIndex); clickAllAreas(numericClickEachArea.Value); } else { clickUntilFinished(duration); } }
/** * Update the combo box to provide all the different ways the area can be divided into * Gets dimensions based on number of areas * Clears combo box of any previous data * Adds dimension selection into the combo box * Stores the displayed width and height for error checking * Displayed width is always at the beginning of the width array, and height at the end of the height array * */ private void divideIntoEqualAreasDisplay() { ImageSplitter.getDimensions((int)numericDivideIntoEqualAreas.Value); comboBoxDividedAreas.Items.Clear(); for (int i = 0; i < ImageSplitter.dimensions.Count(); i++) { String s = ImageSplitter.dimensionWidths[i] + " x " + ImageSplitter.dimensionHeights[i]; comboBoxDividedAreas.Items.Add(s); } displayedWidth = ImageSplitter.dimensionWidths[0]; displayedHeight = ImageSplitter.dimensionHeights[ImageSplitter.dimensionHeights.Count - 1]; }