private void ShowCharacter_Click(object sender, RoutedEventArgs e)
        {
            CharacterSample sample = Characters[selectedCharIndex].Samples[selectedSampleIndex];

            Scroller.ScrollToHorizontalOffset(sample.bitmapLoc.X);
            Scroller.ScrollToVerticalOffset(sample.bitmapLoc.Y);
        }
 private void variants_listbox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (variants_listbox.Items.Count > 0)
     {
         Character       selectedChar = Characters[characters_listbox.SelectedIndex];
         CharacterSample sample       = selectedChar.Samples[variants_listbox.SelectedIndex];
         selectedCharIndex   = characters_listbox.SelectedIndex;
         selectedSampleIndex = variants_listbox.SelectedIndex;
         showControls(sample);
     }
 }
        void showControls(CharacterSample sample)
        {
            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);

            ControlsCanvas.Children.Clear();

            /*bitmap = (Bitmap)buffBitmap.Clone();
             * graphics = Graphics.FromImage(bitmap);*/
            drawPointControl(startPoint, Colors.Black);
            drawPointControl(finishPoint, Colors.Black);
            drawPointControl(beginPoint, Colors.Green);
            drawPointControl(endPoint, Colors.Red);
            SolidColorBrush brush      = new SolidColorBrush(Colors.Black);
            Line            firstLine  = createLine(startPoint.X, finishPoint.Y, finishPoint.X, finishPoint.Y);
            Line            secondLine = createLine(finishPoint.X, finishPoint.Y, finishPoint.X, startPoint.Y);
            Line            thirdLine  = createLine(finishPoint.X, startPoint.Y, startPoint.X, startPoint.Y);
            Line            fourthLine = createLine(startPoint.X, startPoint.Y, startPoint.X, finishPoint.Y);

            firstLine.Stroke = secondLine.Stroke = thirdLine.Stroke = fourthLine.Stroke = brush;
            ControlsCanvas.Children.Add(firstLine);
            ControlsCanvas.Children.Add(secondLine);
            ControlsCanvas.Children.Add(thirdLine);
            ControlsCanvas.Children.Add(fourthLine);

            /*System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black,
             *  1f / (float)PreviewScale.ScaleX);
             * graphics.DrawLine(pen, startPoint.X, finishPoint.Y, finishPoint.X, finishPoint.Y);
             * graphics.DrawLine(pen, finishPoint.X, finishPoint.Y, finishPoint.X, startPoint.Y);
             * graphics.DrawLine(pen, finishPoint.X, startPoint.Y, startPoint.X, startPoint.Y);
             * graphics.DrawLine(pen, startPoint.X, startPoint.Y, startPoint.X, finishPoint.Y);
             * onBitmapChanged();*/

            SymbolPreview.Source = BitmapFuncs.fromBitmap(sample.Img);
        }
Exemple #4
0
 public void AddSample(CharacterSample sample)
 {
     Samples.Add(sample);
 }
        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;
            }
        }