예제 #1
0
 private void RemoveBackButton_Click(object sender, RoutedEventArgs e)
 {
     action = NowAction.ClearingBack;
 }
예제 #2
0
        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;
            }
        }