@@ -17,6 +17,7 @@ struct FancyButtonData {
1717FancyButtonData _fancybtn[MAX_FANCY_BUTTON];
1818int _fancybtn_count;
1919Dictionary* _tvdict;
20+ FancyConfig* _default_cfg;
2021
2122int _get_btn_real_id (Button* btn)
2223{
@@ -533,11 +534,66 @@ DynamicSprite* _create_textbox_with_textspr(Fancy9Piece* f9p, int internal_width
533534// ---------------- fancy module public interface -----------------------
534535// ----------------------------------------------------------------------
535536
537+ static FancyConfig* FancyConfig::Create (FontType font, int color, int outline_color, int outline_width, Alignment align, int line_spacing)
538+ {
539+ FancyConfig* cfg = new FancyConfig;
540+ cfg.Font = font;
541+ cfg.LineSpacing = line_spacing;
542+ cfg.OutlineColor = outline_color;
543+ cfg.OutlineWidth = outline_width;
544+ cfg.TextAlign = align;
545+ cfg.TextColor = color;
546+ return cfg;
547+ }
548+
549+ void FancyConfig::Set (FancyConfig* config)
550+ {
551+ this .Font = config.Font ;
552+ this .LineSpacing = config.LineSpacing ;
553+ this .OutlineColor = config.OutlineColor ;
554+ this .OutlineWidth = config.OutlineWidth ;
555+ this .Padding = config.Padding ;
556+ this .TextAlign = config.TextAlign ;
557+ this .TextColor = config.TextColor ;
558+ }
559+
560+ FancyConfig* FancyConfig::Clone ()
561+ {
562+ FancyConfig* cfg = new FancyConfig;
563+ cfg.Font = this .Font ;
564+ cfg.LineSpacing = this .LineSpacing ;
565+ cfg.OutlineColor = this .OutlineColor ;
566+ cfg.OutlineWidth = this .OutlineWidth ;
567+ cfg.Padding = this .Padding ;
568+ cfg.TextAlign = this .TextAlign ;
569+ cfg.TextColor = this .TextColor ;
570+ return cfg;
571+ }
572+
536573static void Fancy::AddAlias (String key, int value)
537574{
538575 _tvdict.Set (key, String.Format (" %d" , value));
539576}
540577
578+ static FancyConfig* Fancy::get_FancyConfig ()
579+ {
580+ if (_default_cfg == null) {
581+ _default_cfg = FancyConfig.Create ();
582+ }
583+ return _default_cfg;
584+ }
585+
586+ static void Fancy::set_FancyConfig (FancyConfig* value)
587+ {
588+ if (value == null) {
589+ value = FancyConfig.Create ();
590+ }
591+ if (_default_cfg == null) {
592+ _default_cfg = FancyConfig.Create ();
593+ }
594+ _default_cfg.Set (value);
595+ }
596+
541597void Fancy9Piece::Set (int top, int bottom, int left, int right, int top_left, int top_right, int bottom_left, int bottom_right, int background, int bg_color)
542598{
543599 this .T = top;
@@ -599,31 +655,10 @@ static Fancy9Piece* Fancy9Piece::CreateFromTextWindowGui(GUI* text_window_gui)
599655 sprite_bg, bg_color);
600656}
601657
602- static FancyConfig* FancyConfig::Create (FontType font, int color, int outline_color, int outline_width, Alignment align, int line_spacing)
603- {
604- FancyConfig* cfg = new FancyConfig;
605- cfg.Font = font;
606- cfg.TextColor = color;
607- cfg.OutlineColor = outline_color;
608- cfg.OutlineWidth = outline_width;
609- cfg.TextAlign = align;
610- cfg.LineSpacing = line_spacing;
611- return cfg;
612- }
613-
614- void FancyConfig::Set (FancyConfig* config)
615- {
616- this .Font = config.Font ;
617- this .LineSpacing = config.LineSpacing ;
618- this .OutlineColor = config.OutlineColor ;
619- this .OutlineWidth = config.OutlineWidth ;
620- this .Padding = config.Padding ;
621- this .TextAlign = config.TextAlign ;
622- this .TextColor = config.TextColor ;
623- }
624-
625658void DrawFancyString (this DrawingSurface*, int x, int y, const string text, FancyConfig* config, int width)
626659{
660+ if (String.IsNullOrEmpty (text)) return ;
661+ if (config == null) config = _default_cfg.Clone ();
627662 FancyTextToken* tk_arr[] = _NewTxtTok ();
628663 FancyState* fs = NewState (x, y);
629664 int tk_count = _parse_text (tk_arr, text, config);
@@ -633,6 +668,8 @@ void DrawFancyString(this DrawingSurface*, int x, int y, const string text, Fanc
633668
634669DynamicSprite* CreateFromFancyString (static DynamicSprite, const string text, FancyConfig* config, int width)
635670{
671+ if (String.IsNullOrEmpty (text)) return null;
672+ if (config == null) config = _default_cfg.Clone ();
636673 FancyTextToken* tk_arr[] = _NewTxtTok ();
637674 FancyState* fs = NewState (0 , 0 );
638675 int tk_count = _parse_text (tk_arr, text, config);
@@ -650,6 +687,7 @@ DynamicSprite* CreateFromFancyString(static DynamicSprite, const string text, Fa
650687DynamicSprite* CreateFromFancyTextBox (static DynamicSprite, const string text, FancyConfig* config, int width, Fancy9Piece* f9p)
651688{
652689 if (String.IsNullOrEmpty (text)) return null;
690+ if (config == null) config = _default_cfg.Clone ();
653691
654692 DynamicSprite* text_spr = DynamicSprite.CreateFromFancyString (text, config, width);
655693 if (f9p == null) return text_spr;
@@ -669,6 +707,8 @@ DynamicSprite* CreateFromFancyTextBox(static DynamicSprite, const string text, F
669707
670708Overlay* CreateFancyTextBox (static Overlay, int x, int y, const string text, FancyConfig* config, int width, Fancy9Piece* f9p)
671709{
710+ if (String.IsNullOrEmpty (text)) return null;
711+ if (config == null) config = _default_cfg.Clone ();
672712 DynamicSprite* spr = DynamicSprite.CreateFromFancyTextBox (text, config, width, f9p);
673713 Overlay* ovr = Overlay.CreateGraphical (x, y, spr.Graphic , true , true );
674714 spr.Delete ();
@@ -766,7 +806,7 @@ void FancyTextBase::SetDrawingArea(int x, int y, int width)
766806
767807void FancyTextBase::SetFancyText (String text)
768808{
769- if (this ._cfg == null) { this .set_FancyConfig (null ); }
809+ if (this ._cfg == null) { this ._cfg = _default_cfg. Clone ( ); }
770810 if (this ._width <= 0 ) { this ._width = FANCY_INFINITE_WIDTH; }
771811 if (this ._fs == null) { this ._fs = NewState (0 , 0 ); }
772812
0 commit comments