예제 #1
0
        public static void DrawIconWatermark()
        {
            if (FProp.Default.FUseWatermark)
            {
                using (StreamReader image = new StreamReader(FProp.Default.FWatermarkFilePath))
                {
                    if (image != null)
                    {
                        BitmapImage bmp = new BitmapImage();
                        bmp.BeginInit();
                        bmp.CacheOption  = BitmapCacheOption.OnLoad;
                        bmp.StreamSource = image.BaseStream;
                        bmp.EndInit();
                        bmp.Freeze();

                        IconCreator.ICDrawingContext.DrawImage(
                            ImagesUtility.CreateTransparency(bmp, FProp.Default.FWatermarkOpacity),
                            new Rect(
                                FProp.Default.FWatermarkXPos,
                                FProp.Default.FWatermarkYPos,
                                bmp.Width * (FProp.Default.FWatermarkScale / 515),
                                bmp.Height * (FProp.Default.FWatermarkScale / 515)
                                )
                            );
                    }
                }

                DebugHelper.WriteLine("DefaultIconCreation: Icon watermark has been applied on {0}", FWindow.FCurrentAsset);
            }
        }
예제 #2
0
        public static void DrawIconWatermark()
        {
            if (FProp.Default.FUseWatermark)
            {
                using (StreamReader image = new StreamReader(FProp.Default.FWatermarkFilePath))
                {
                    if (image != null)
                    {
                        BitmapImage bmp = new BitmapImage();
                        bmp.BeginInit();
                        bmp.CacheOption  = BitmapCacheOption.OnLoad;
                        bmp.StreamSource = image.BaseStream;
                        bmp.EndInit();
                        bmp.Freeze();

                        IconCreator.ICDrawingContext.DrawImage(ImagesUtility.CreateTransparency(bmp, FProp.Default.FWatermarkOpacity), new Rect(FProp.Default.FWatermarkXPos, FProp.Default.FWatermarkYPos, FProp.Default.FWatermarkScale, FProp.Default.FWatermarkScale));
                    }
                }
            }
        }
예제 #3
0
        private static void DrawHeader(string displayName, string lastfolder, SolidColorBrush PrimaryColor, SolidColorBrush SecondaryColor, Stream image)
        {
            Point dStart = new Point(0, 256);

            LineSegment[] dSegments = new[]
            {
                new LineSegment(new Point(1024, 256), true),
                new LineSegment(new Point(1024, 241), true),
                new LineSegment(new Point(537, 236), true),
                new LineSegment(new Point(547, 249), true),
                new LineSegment(new Point(0, 241), true)
            };
            PathFigure   dFigure = new PathFigure(dStart, dSegments, true);
            PathGeometry dGeo    = new PathGeometry(new[] { dFigure });

            Typeface      typeface      = new Typeface(TextsUtility.Burbank, FontStyles.Normal, FontWeights.Black, FontStretches.Normal);
            FormattedText formattedText =
                new FormattedText(
                    displayName.ToUpperInvariant(),
                    CultureInfo.CurrentUICulture,
                    FlowDirection.LeftToRight,
                    typeface,
                    55,
                    Brushes.White,
                    IconCreator.PPD
                    );

            formattedText.TextAlignment = TextAlignment.Left;
            formattedText.MaxTextWidth  = 768;
            formattedText.MaxLineCount  = 1;
            Point textLocation = new Point(isBanner || !hasDisplayStyle ? 50 : 310, 165 - formattedText.Height);

            IconCreator.ICDrawingContext.DrawRectangle(PrimaryColor, null, new Rect(0, 0, 1024, 256));

            #region IMAGE
            if (FProp.Default.FUseChallengeWatermark)
            {
                if (!string.IsNullOrEmpty(FProp.Default.FBannerFilePath))
                {
                    BitmapImage bmp = new BitmapImage(new Uri(FProp.Default.FBannerFilePath));
                    IconCreator.ICDrawingContext.DrawImage(ImagesUtility.CreateTransparency(bmp, FProp.Default.FBannerOpacity), new Rect(0, 0, 1024, 256));
                }
                else if (image != null)
                {
                    using (image)
                    {
                        BitmapImage bmp = new BitmapImage();
                        bmp.BeginInit();
                        bmp.CacheOption  = BitmapCacheOption.OnLoad;
                        bmp.StreamSource = image;
                        bmp.EndInit();
                        bmp.Freeze();

                        IconCreator.ICDrawingContext.DrawImage(isBanner ? ImagesUtility.CreateTransparency(bmp, 50) : bmp, new Rect(0, 0, isBanner ? 1024 : 256, 256));
                    }
                }
            }
            else if (image != null)
            {
                using (image)
                {
                    BitmapImage bmp = new BitmapImage();
                    bmp.BeginInit();
                    bmp.CacheOption  = BitmapCacheOption.OnLoad;
                    bmp.StreamSource = image;
                    bmp.EndInit();
                    bmp.Freeze();

                    IconCreator.ICDrawingContext.DrawImage(isBanner ? ImagesUtility.CreateTransparency(bmp, 50) : bmp, new Rect(0, 0, isBanner ? 1024 : 256, 256));
                }
            }
            #endregion

            IconCreator.ICDrawingContext.DrawGeometry(SecondaryColor, null, dGeo);
            IconCreator.ICDrawingContext.DrawText(formattedText, textLocation);

            formattedText =
                new FormattedText(
                    lastfolder.ToUpperInvariant(),
                    CultureInfo.CurrentUICulture,
                    FlowDirection.LeftToRight,
                    typeface,
                    30,
                    SecondaryColor,
                    IconCreator.PPD
                    );
            formattedText.TextAlignment = TextAlignment.Left;
            formattedText.MaxTextWidth  = 768;
            formattedText.MaxLineCount  = 1;
            textLocation = new Point(isBanner || !hasDisplayStyle ? 50 : 310, 100 - formattedText.Height);
            Geometry geometry = formattedText.BuildGeometry(textLocation);
            Pen      pen      = new Pen(ChallengesUtility.DarkBrush(SecondaryColor, 0.3f), 1);
            pen.LineJoin = PenLineJoin.Round;
            IconCreator.ICDrawingContext.DrawGeometry(SecondaryColor, pen, geometry);

            string watermark = FProp.Default.FChallengeWatermark;
            if (watermark.Contains("{BundleName}"))
            {
                watermark = watermark.Replace("{BundleName}", displayName);
            }
            if (watermark.Contains("{Date}"))
            {
                watermark = watermark.Replace("{Date}", DateTime.Now.ToString("dd/MM/yyyy"));
            }
            typeface      = new Typeface(TextsUtility.FBurbank, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            formattedText =
                new FormattedText(
                    watermark,
                    CultureInfo.CurrentUICulture,
                    FlowDirection.LeftToRight,
                    typeface,
                    20,
                    new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)),
                    IconCreator.PPD
                    );
            formattedText.TextAlignment = TextAlignment.Right;
            formattedText.MaxTextWidth  = 1014;
            formattedText.MaxLineCount  = 1;
            textLocation = new Point(0, 205);
            IconCreator.ICDrawingContext.DrawText(formattedText, textLocation);
        }
예제 #4
0
        private void UpdateChallengeCustomTheme()
        {
            bool   watermarkEnabled = (bool)bCustomChallenge.IsChecked;
            string watermark        = WatermarkChallenge_TextBox.Text;
            string path             = FProp.Default.FBannerFilePath;
            int    opacity          = Convert.ToInt32(OpacityBanner_Slider.Value);

            string[]        primaryParts   = FProp.Default.FPrimaryColor.Split(':');
            string[]        secondaryParts = FProp.Default.FSecondaryColor.Split(':');
            SolidColorBrush PrimaryColor   = new SolidColorBrush(Color.FromRgb(Convert.ToByte(primaryParts[0]), Convert.ToByte(primaryParts[1]), Convert.ToByte(primaryParts[2])));
            SolidColorBrush SecondaryColor = new SolidColorBrush(Color.FromRgb(Convert.ToByte(secondaryParts[0]), Convert.ToByte(secondaryParts[1]), Convert.ToByte(secondaryParts[2])));

            if (watermarkEnabled)
            {
                DrawingVisual drawingVisual = new DrawingVisual();
                double        PPD           = VisualTreeHelper.GetDpi(drawingVisual).PixelsPerDip;
                using (DrawingContext drawingContext = drawingVisual.RenderOpen())
                {
                    //INITIALIZATION
                    drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(new Point(0, 0), new Size(1024, 410)));

                    Point         dStart    = new Point(0, 256);
                    LineSegment[] dSegments = new[]
                    {
                        new LineSegment(new Point(1024, 256), true),
                        new LineSegment(new Point(1024, 241), true),
                        new LineSegment(new Point(537, 236), true),
                        new LineSegment(new Point(547, 249), true),
                        new LineSegment(new Point(0, 241), true)
                    };
                    PathFigure   dFigure = new PathFigure(dStart, dSegments, true);
                    PathGeometry dGeo    = new PathGeometry(new[] { dFigure });

                    Typeface      typeface      = new Typeface(TextsUtility.Burbank, FontStyles.Normal, FontWeights.Black, FontStretches.Normal);
                    FormattedText formattedText =
                        new FormattedText(
                            "{BUNDLE DISPLAY NAME HERE}",
                            CultureInfo.CurrentUICulture,
                            FlowDirection.LeftToRight,
                            typeface,
                            55,
                            Brushes.White,
                            PPD
                            );
                    formattedText.TextAlignment = TextAlignment.Left;
                    formattedText.MaxTextWidth  = 768;
                    formattedText.MaxLineCount  = 1;
                    Point textLocation = new Point(50, 165 - formattedText.Height);

                    drawingContext.DrawRectangle(PrimaryColor, null, new Rect(0, 0, 1024, 256));
                    if (!string.IsNullOrEmpty(path))
                    {
                        BitmapImage bmp = new BitmapImage(new Uri(path));
                        drawingContext.DrawImage(ImagesUtility.CreateTransparency(bmp, opacity), new Rect(0, 0, 1024, 256));
                    }
                    drawingContext.DrawGeometry(SecondaryColor, null, dGeo);
                    drawingContext.DrawText(formattedText, textLocation);

                    formattedText =
                        new FormattedText(
                            "{LAST FOLDER HERE}",
                            CultureInfo.CurrentUICulture,
                            FlowDirection.LeftToRight,
                            typeface,
                            30,
                            SecondaryColor,
                            IconCreator.PPD
                            );
                    formattedText.TextAlignment = TextAlignment.Left;
                    formattedText.MaxTextWidth  = 768;
                    formattedText.MaxLineCount  = 1;
                    textLocation = new Point(50, 100 - formattedText.Height);
                    Geometry geometry = formattedText.BuildGeometry(textLocation);
                    Pen      pen      = new Pen(ChallengesUtility.DarkBrush(SecondaryColor, 0.3f), 1);
                    pen.LineJoin = PenLineJoin.Round;
                    drawingContext.DrawGeometry(SecondaryColor, pen, geometry);

                    typeface      = new Typeface(TextsUtility.FBurbank, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
                    formattedText =
                        new FormattedText(
                            watermark,
                            CultureInfo.CurrentUICulture,
                            FlowDirection.LeftToRight,
                            typeface,
                            20,
                            new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)),
                            IconCreator.PPD
                            );
                    formattedText.TextAlignment = TextAlignment.Right;
                    formattedText.MaxTextWidth  = 1014;
                    formattedText.MaxLineCount  = 1;
                    textLocation = new Point(0, 205);
                    drawingContext.DrawText(formattedText, textLocation);

                    LinearGradientBrush linGrBrush = new LinearGradientBrush();
                    linGrBrush.StartPoint = new Point(0, 0);
                    linGrBrush.EndPoint   = new Point(0, 1);
                    linGrBrush.GradientStops.Add(new GradientStop(Color.FromArgb(75, SecondaryColor.Color.R, SecondaryColor.Color.G, SecondaryColor.Color.B), 0));
                    linGrBrush.GradientStops.Add(new GradientStop(Color.FromArgb(25, PrimaryColor.Color.R, PrimaryColor.Color.G, PrimaryColor.Color.B), 0.15));
                    linGrBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 1));

                    drawingContext.DrawRectangle(ChallengesUtility.DarkBrush(PrimaryColor, 0.3f), null, new Rect(0, 256, 1024, 144));
                    drawingContext.DrawRectangle(linGrBrush, null, new Rect(0, 256, 1024, 144));

                    typeface = new Typeface(TextsUtility.Burbank, FontStyles.Normal, FontWeights.Black, FontStretches.Normal);
                    int y = 300;

                    drawingContext.DrawRectangle(ChallengesUtility.DarkBrush(PrimaryColor, 0.3f), null, new Rect(0, y, 1024, 90));
                    drawingContext.DrawRectangle(PrimaryColor, null, new Rect(25, y, 1024 - 50, 70));

                    dStart    = new Point(32, y + 5);
                    dSegments = new[]
                    {
                        new LineSegment(new Point(29, y + 67), true),
                        new LineSegment(new Point(1024 - 160, y + 62), true),
                        new LineSegment(new Point(1024 - 150, y + 4), true)
                    };
                    dFigure = new PathFigure(dStart, dSegments, true);
                    dGeo    = new PathGeometry(new[] { dFigure });
                    drawingContext.DrawGeometry(ChallengesUtility.LightBrush(PrimaryColor, 0.04f), null, dGeo);

                    drawingContext.DrawRectangle(SecondaryColor, null, new Rect(60, y + 47, 500, 7));

                    dStart    = new Point(39, y + 35);
                    dSegments = new[]
                    {
                        new LineSegment(new Point(45, y + 32), true),
                        new LineSegment(new Point(48, y + 37), true),
                        new LineSegment(new Point(42, y + 40), true)
                    };
                    dFigure = new PathFigure(dStart, dSegments, true);
                    dGeo    = new PathGeometry(new[] { dFigure });
                    drawingContext.DrawGeometry(SecondaryColor, null, dGeo);
                }

                if (drawingVisual != null)
                {
                    RenderTargetBitmap RTB = new RenderTargetBitmap(1024, 410, 96, 96, PixelFormats.Pbgra32);
                    RTB.Render(drawingVisual);
                    RTB.Freeze(); //We freeze to apply the RTB to our imagesource from the UI Thread

                    FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        ImageBox_ChallengePreview.Source = BitmapFrame.Create(RTB); //thread safe and fast af
                    });
                }
            }
            else
            {
                BitmapImage source = new BitmapImage(new Uri("pack://application:,,,/Resources/Template_Challenge.png"));
                ImageBox_ChallengePreview.Source = source;
            }
        }
예제 #5
0
        private async Task UpdateImageWithWatermark()
        {
            bool   watermarkEnabled = (bool)bWatermarkIcon.IsChecked;
            string rarityDesign     = ((ComboBoxItem)ComboBox_Design.SelectedItem).Content.ToString();
            bool   isFeatured       = (bool)bFeaturedIcon.IsChecked;
            int    opacity          = Convert.ToInt32(Opacity_Slider.Value);
            double scale            = Scale_Slider.Value;
            double xPos             = xPos_Slider.Value;
            double yPos             = yPos_Slider.Value;

            await Task.Run(() =>
            {
                DrawingVisual drawingVisual = new DrawingVisual();
                using (DrawingContext drawingContext = drawingVisual.RenderOpen())
                {
                    //INITIALIZATION
                    drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(new Point(0, 0), new Size(515, 515)));

                    BitmapImage source = null;
                    switch (rarityDesign)
                    {
                    case "Default":
                        source = new BitmapImage(new Uri(isFeatured ? "pack://application:,,,/Resources/Template_D_F.png" : "pack://application:,,,/Resources/Template_D_N.png"));
                        break;

                    case "Flat":
                        source = new BitmapImage(new Uri(isFeatured ? "pack://application:,,,/Resources/Template_F_F.png" : "pack://application:,,,/Resources/Template_F_N.png"));
                        break;

                    case "Minimalist":
                        source = new BitmapImage(new Uri(isFeatured ? "pack://application:,,,/Resources/Template_M_F.png" : "pack://application:,,,/Resources/Template_M_N.png"));
                        break;
                    }
                    drawingContext.DrawImage(source, new Rect(new Point(0, 0), new Size(515, 515)));

                    if (!string.IsNullOrEmpty(FProp.Default.FWatermarkFilePath) && watermarkEnabled)
                    {
                        using (StreamReader image = new StreamReader(FProp.Default.FWatermarkFilePath))
                        {
                            if (image != null)
                            {
                                BitmapImage bmp = new BitmapImage();
                                bmp.BeginInit();
                                bmp.CacheOption  = BitmapCacheOption.OnLoad;
                                bmp.StreamSource = image.BaseStream;
                                bmp.EndInit();

                                drawingContext.DrawImage(ImagesUtility.CreateTransparency(bmp, opacity), new Rect(xPos, yPos, scale, scale));
                            }
                        }
                    }
                }

                if (drawingVisual != null)
                {
                    RenderTargetBitmap RTB = new RenderTargetBitmap(515, 515, 96, 96, PixelFormats.Pbgra32);
                    RTB.Render(drawingVisual);
                    RTB.Freeze(); //We freeze to apply the RTB to our imagesource from the UI Thread

                    FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        ImageBox_RarityPreview.Source = BitmapFrame.Create(RTB); //thread safe and fast af
                    });
                }
            }).ContinueWith(TheTask =>
            {
                TasksUtility.TaskCompleted(TheTask.Exception);
            });
        }