Exemple #1
0
        private static string GetBackgroundImageUrl(AssStyleOptions options)
        {
            byte[] imageData;
            string mimeType;

            if (options?.HasExistingBackgroundImage ?? false)
            {
                try
                {
                    imageData = File.ReadAllBytes(options.BackgroundImagePath);
                    mimeType  = ExtensionToMimeType.GetOrDefault(Path.GetExtension(options.BackgroundImagePath).ToLower()) ?? "image/png";
                }
                catch
                {
                    imageData = Resources.Checkers;
                    mimeType  = "image/png";
                }
            }
            else
            {
                imageData = Resources.Checkers;
                mimeType  = "image/png";
            }

            return($"data:{mimeType};base64,{Convert.ToBase64String(imageData)}");
        }
        private void _lstStyles_SelectedIndexChanged(object sender, EventArgs e)
        {
            AssStyleOptions options = SelectedStyleOptions;

            if (options == null)
            {
                _spltStyleOptions.Panel2.Enabled = false;
                _brwPreview.DocumentText         = string.Empty;
                return;
            }

            AssStyle style = _styles[options.Name];

            _previewSuspended = true;

            _spltStyleOptions.Panel2.Enabled = true;
            _pnlOptions.Enabled    = !_builtinStyleNames.Contains(style.Name);
            _pnlShadowType.Enabled = style.HasShadow;

            if (style.HasOutline && !style.HasOutlineBox)
            {
                _chkGlow.Checked = true;
                _chkGlow.Enabled = false;
            }
            else
            {
                _chkGlow.Checked = style.HasShadow && options.ShadowTypes.Contains(ShadowType.Glow);
                _chkGlow.Enabled = true;
            }

            _chkBevel.Checked      = style.HasShadow && options.ShadowTypes.Contains(ShadowType.Bevel);
            _chkSoftShadow.Checked = style.HasShadow && options.ShadowTypes.Contains(ShadowType.SoftShadow);
            _chkHardShadow.Checked = style.HasShadow && options.ShadowTypes.Contains(ShadowType.HardShadow);

            Color currentWordTextColor    = options.CurrentWordTextColor;
            Color currentWordOutlineColor = options.CurrentWordOutlineColor;
            Color currentWordShadowColor  = options.CurrentWordShadowColor;

            _chkKaraoke.Checked = options.IsKaraoke;
            _chkHighlightCurrentWord.Checked = !currentWordTextColor.IsEmpty;

            _txtCurrentWordTextColor.Enabled = _chkHighlightCurrentWord.Checked;
            _txtCurrentWordTextColor.Text    = _txtCurrentWordTextColor.Enabled ? ColorUtil.ToHtml(currentWordTextColor) : string.Empty;
            _btnPickTextColor.Enabled        = _txtCurrentWordTextColor.Enabled;

            _txtCurrentWordOutlineColor.Enabled = _chkHighlightCurrentWord.Checked && style.HasOutline && !style.HasOutlineBox;
            _txtCurrentWordOutlineColor.Text    = _txtCurrentWordOutlineColor.Enabled ? ColorUtil.ToHtml(currentWordOutlineColor) : string.Empty;
            _btnPickOutlineColor.Enabled        = _txtCurrentWordOutlineColor.Enabled;

            _txtCurrentWordShadowColor.Enabled = _chkHighlightCurrentWord.Checked && style.HasShadow;
            _txtCurrentWordShadowColor.Text    = _txtCurrentWordShadowColor.Enabled ? ColorUtil.ToHtml(currentWordShadowColor) : string.Empty;
            _btnPickShadowColor.Enabled        = _txtCurrentWordShadowColor.Enabled;

            UpdateBackgroundImageButton();

            _previewSuspended = false;
            UpdateStylePreview();
        }
Exemple #3
0
        private static string GetVerticalAlign(AssStyle style, AssStyleOptions options)
        {
            if (!(options?.HasExistingBackgroundImage ?? false))
            {
                return("middle");
            }

            if (AnchorPointUtil.IsTopAligned(style.AnchorPoint))
            {
                return("top");
            }

            if (AnchorPointUtil.IsBottomAligned(style.AnchorPoint))
            {
                return("bottom");
            }

            return("middle");
        }
Exemple #4
0
        private static string GetTextAlign(AssStyle style, AssStyleOptions options)
        {
            if (!(options?.HasExistingBackgroundImage ?? false))
            {
                return("center");
            }

            if (AnchorPointUtil.IsLeftAligned(style.AnchorPoint))
            {
                return("left");
            }

            if (AnchorPointUtil.IsRightAligned(style.AnchorPoint))
            {
                return("right");
            }

            return("center");
        }
Exemple #5
0
        private void _btnBackgroundImage_Click(object sender, EventArgs e)
        {
            AssStyleOptions options = SelectedStyleOptions;

            if (options.HasExistingBackgroundImage)
            {
                options.BackgroundImagePath = null;
            }
            else
            {
                if (_dlgOpenImage.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                options.BackgroundImagePath = _dlgOpenImage.FileName;
            }

            UpdateBackgroundImageButton();
            UpdateStylePreview();
        }
Exemple #6
0
        public static string GenerateHtml(AssStyle style, AssStyleOptions options, float defaultFontSize)
        {
            StringBuilder html = new StringBuilder();

            html.Append($@"
                  <!DOCTYPE html>
                  <html>
                  <head>
                      <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />
                      <style>
                          html, body
                          {{
                              width: 100%;
                              height: 100%;
                              padding: 0;
                              margin: 0;
                              cursor: default;
                          }}
                          body
                          {{
                              display: table;
                              background-image: url({GetBackgroundImageUrl(options)});
                              background-position: {GetBackgroundImagePosition(options)};
                              background-repeat: {GetBackgroundImageRepeat(options)};
                              -ms-user-select: none;
                          }}
                          #wrapper
                          {{
                              display: table-cell;
                              height: 100%;
                              padding: 10px;
                              text-align: {GetTextAlign(style, options)};
                              vertical-align: {GetVerticalAlign(style, options)};
                          }}
            ");

            if (options != null)
            {
                GenerateBackgroundCss(html, "#background", style, defaultFontSize);
                GenerateForegroundCss(html, "#regular", style, style.PrimaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                if (options.IsKaraoke)
                {
                    GenerateForegroundCss(
                        html,
                        "#singing",
                        style,
                        !options.CurrentWordTextColor.IsEmpty ? options.CurrentWordTextColor : style.PrimaryColor,
                        !options.CurrentWordOutlineColor.IsEmpty ? options.CurrentWordOutlineColor : style.OutlineColor,
                        !options.CurrentWordShadowColor.IsEmpty ? options.CurrentWordShadowColor : style.ShadowColor,
                        options.ShadowTypes
                        );
                    GenerateForegroundCss(html, "#unsung", style, style.SecondaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                }
            }

            html.Append(@"
                      </style>
                  </head>
                  <body>
                      <div id=""wrapper"">
            ");

            if (options != null)
            {
                html.Append(@"<span id=""background"">");

                if (options.IsKaraoke)
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleKaraoke1}</span>");
                    html.Append($@"<span id=""singing"">{Resources.PreviewSampleKaraoke2}</span>");
                    html.Append($@"<span id=""unsung"">{Resources.PreviewSampleKaraoke3}</span>");
                }
                else
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleRegular}</span>");
                }

                html.Append(@"</span>");
            }

            html.Append(@"
                      </div>
                  </body>
                  </html>
            ");
            return(html.ToString());
        }
Exemple #7
0
 private static string GetBackgroundImageRepeat(AssStyleOptions options)
 {
     return(options?.HasExistingBackgroundImage ?? false ? "no-repeat" : "repeat");
 }
Exemple #8
0
 private static string GetBackgroundImagePosition(AssStyleOptions options)
 {
     return(options?.HasExistingBackgroundImage ?? false ? "center center" : "left top");
 }
Exemple #9
0
        public static string GenerateHtml(AssStyle style, AssStyleOptions options)
        {
            StringBuilder html = new StringBuilder();

            html.Append($@"
                  <!DOCTYPE html>
                  <html>
                  <head>
                      <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />
                      <style>
                          html, body {{ width: 100%; height: 100%; padding: 0; margin: 0; }}
                          body {{ display: table; background-image: url(data:image/png;base64,{BackgroundImageData}); }}
                          #wrapper {{ display: table-cell; height: 100%; text-align: center; vertical-align: middle; }}
            ");

            if (options != null)
            {
                GenerateBackgroundCss(html, "#background", style);
                GenerateForegroundCss(html, "#regular", style, style.PrimaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                if (options.IsKaraoke)
                {
                    GenerateForegroundCss(
                        html,
                        "#singing",
                        style,
                        !options.CurrentWordTextColor.IsEmpty ? options.CurrentWordTextColor : style.PrimaryColor,
                        !options.CurrentWordOutlineColor.IsEmpty ? options.CurrentWordOutlineColor : style.OutlineColor,
                        !options.CurrentWordShadowColor.IsEmpty ? options.CurrentWordShadowColor : style.ShadowColor,
                        options.ShadowTypes
                        );
                    GenerateForegroundCss(html, "#unsung", style, style.SecondaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                }
            }

            html.Append(@"
                      </style>
                  </head>
                  <body>
                      <div id=""wrapper"">
            ");

            if (options != null)
            {
                html.Append(@"<span id=""background"">");

                if (options.IsKaraoke)
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleKaraoke1}</span>");
                    html.Append($@"<span id=""singing"">{Resources.PreviewSampleKaraoke2}</span>");
                    html.Append($@"<span id=""unsung"">{Resources.PreviewSampleKaraoke3}</span>");
                }
                else
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleRegular}</span>");
                }

                html.Append(@"</span>");
            }

            html.Append(@"
                      </div>
                  </body>
                  </html>
            ");
            return(html.ToString());
        }