private void add_character_button_Click(object sender, RoutedEventArgs e) { int res = checkIfAllCharactersAdded(); if (res == -1) { System.Windows.MessageBox.Show("You have added all characters"); } else if (isImageOpened) { Bitmap buffBitmap = (Bitmap)Image.FromFile(cachedPreviewName); Character newC = new Character(NeededChars[res]); System.Drawing.Point screenStart = convertToPixelsD(new System.Windows.Point( Scroller.HorizontalOffset, Scroller.VerticalOffset)); System.Drawing.Point startPoint = screenStart; System.Drawing.Point finishPoint = new System.Drawing.Point(screenStart.X + 100, screenStart.Y + 100); System.Drawing.Point beginPoint = new System.Drawing.Point(25, 25); System.Drawing.Point endPoint = new System.Drawing.Point(50, 50); newC.AddSample(new CharacterSample(BitmapFuncs.cropBitmap(buffBitmap, startPoint, finishPoint), beginPoint, endPoint)); newC.Samples[0].bitmapLoc = startPoint; Characters.Add(newC); updateLists(); buffBitmap.Dispose(); } else { System.Windows.MessageBox.Show("Firstly open image.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void add_variant_button_Click(object sender, RoutedEventArgs e) { Bitmap buffBitmap = (Bitmap)Image.FromFile(cachedPreviewName); System.Drawing.Point screenStart = convertToPixelsD(new System.Windows.Point( Scroller.HorizontalOffset, Scroller.VerticalOffset)); System.Drawing.Point startPoint = screenStart; System.Drawing.Point finishPoint = new System.Drawing.Point(screenStart.X + 100, screenStart.Y + 100); System.Drawing.Point beginPoint = new System.Drawing.Point(25, 25); System.Drawing.Point endPoint = new System.Drawing.Point(50, 50); Characters[selectedCharIndex].AddSample(new CharacterSample(BitmapFuncs.cropBitmap(buffBitmap, startPoint, finishPoint), beginPoint, endPoint)); Characters[selectedCharIndex].Samples.Last().bitmapLoc = startPoint; updateLists(); buffBitmap.Dispose(); }
private void Preview_MouseDown(object sender, MouseButtonEventArgs e) { System.Windows.Point pos = convertToPixels(e.GetPosition(Preview)); int x = (int)pos.X; int y = (int)pos.Y; CharacterSample sample = Characters[selectedCharIndex].Samples[selectedSampleIndex]; System.Drawing.Point point = new System.Drawing.Point(x, y); System.Drawing.Point startPoint = new System.Drawing.Point(sample.bitmapLoc.X, sample.bitmapLoc.Y + sample.Img.Height); System.Drawing.Point finishPoint = new System.Drawing.Point(sample.bitmapLoc.X + sample.Img.Width, sample.bitmapLoc.Y); System.Drawing.Point beginPoint = new System.Drawing.Point( sample.Begin.X + sample.bitmapLoc.X, sample.Begin.Y + sample.bitmapLoc.Y); System.Drawing.Point endPoint = new System.Drawing.Point( sample.End.X + sample.bitmapLoc.X, sample.End.Y + sample.bitmapLoc.Y); if (action == NowAction.WaitingForAction) { if (checkIfInCircle(startPoint, point)) { action = NowAction.SettingStartPoint; } else if (checkIfInCircle(finishPoint, point)) { action = NowAction.SettingFinishPoint; } else if (checkIfInCircle(beginPoint, point)) { action = NowAction.SettingBeginPoint; } else if (checkIfInCircle(endPoint, point)) { action = NowAction.SettingEndPoint; } } else if (action == NowAction.SettingStartPoint) { Bitmap buffBitmap = (Bitmap)Image.FromFile(cachedPreviewName); int X = Math.Min(x, finishPoint.X); int Y = Math.Min(y, finishPoint.Y); int W = Math.Abs(finishPoint.X - x); int H = Math.Abs(y - finishPoint.Y); Characters[selectedCharIndex].Samples[selectedSampleIndex].Img = BitmapFuncs.cropBitmap(buffBitmap, new System.Drawing.Rectangle(X, Y, W, H)); Characters[selectedCharIndex].Samples[selectedSampleIndex].bitmapLoc = new System.Drawing.Point(X, Y); showControls(Characters[selectedCharIndex].Samples[selectedSampleIndex]); action = NowAction.WaitingForAction; } else if (action == NowAction.SettingFinishPoint) { Bitmap buffBitmap = (Bitmap)Image.FromFile(cachedPreviewName); int X = Math.Min(x, startPoint.X); int Y = Math.Min(y, startPoint.Y); int W = Math.Abs(startPoint.X - x); int H = Math.Abs(y - startPoint.Y); Characters[selectedCharIndex].Samples[selectedSampleIndex].Img = BitmapFuncs.cropBitmap(buffBitmap, new System.Drawing.Rectangle(X, Y, W, H)); Characters[selectedCharIndex].Samples[selectedSampleIndex].bitmapLoc = new System.Drawing.Point(X, Y); showControls(Characters[selectedCharIndex].Samples[selectedSampleIndex]); action = NowAction.WaitingForAction; } else if (action == NowAction.SettingEndPoint) { endPoint = new System.Drawing.Point( x - sample.bitmapLoc.X, y - sample.bitmapLoc.Y); Characters[selectedCharIndex].Samples[selectedSampleIndex].End = endPoint; showControls(Characters[selectedCharIndex].Samples[selectedSampleIndex]); action = NowAction.WaitingForAction; } else if (action == NowAction.SettingBeginPoint) { beginPoint = new System.Drawing.Point( x - sample.bitmapLoc.X, y - sample.bitmapLoc.Y); Characters[selectedCharIndex].Samples[selectedSampleIndex].Begin = beginPoint; showControls(Characters[selectedCharIndex].Samples[selectedSampleIndex]); action = NowAction.WaitingForAction; } else if (action == NowAction.ClearingBack) { Bitmap bitmap = (Bitmap)Image.FromFile(cachedPreviewName); System.Drawing.Color pixel = bitmap.GetPixel(x, y); Characters[selectedCharIndex].Samples[selectedSampleIndex].Img = BitmapFuncs.replaceColor(Characters[selectedCharIndex].Samples[selectedSampleIndex].Img, pixel, System.Drawing.Color.Transparent, FillStrenght.Value); showControls(Characters[selectedCharIndex].Samples[selectedSampleIndex]); action = NowAction.WaitingForAction; } }