The built-in fonts incorrectly named themselves IBM_16x8, even though the glyphs were 8x16. The name has been corrected in SadConsole. If you deserialize an object and it can't find the IBM_16x8 font you have two solutions:
- Edit the json and fix the font name.
- Use the configuration
FixOldFontName()
option.
The theme concept has been removed from v10. If you had a control with its own theme, you need to migrate the theme code to the control itself. Here are some tips and notes:
-
ControlThemeState
changes toThemeState
-
_colorsLastUsed
was declared by the theme whenRefreshTheme
was called. This member no longer exists andRefreshTheme
has changed. If you used this member, instead declare aColors
object in theUpdateAndRedraw
method:Colors _colorsLastUsed = FindThemeColors();
This resolves any references to_colorsLastUsed
. Next, rename the variable to something more useful likecolors
orcurrentColors
. -
If
GetOffColor
is used, this has been moved fromThemeState
to theColors
class, for example,currentColors.GetOffColor
-
If your theme declared various properties, variables, and methods, move them to the control. I suggest making the control a partial class, then creating a new class with the file name
.Theme.cs
appended. For example, SadConsole has theCheckbox.cs
andCheckbox.Theme.cs
files. The "theme" code file contains all of the properties, methods, and variables used to draw the control.
When drawing a control override the UpdateAndRedraw
method and do the following:
-
Check if
IsDirty == false
and return. -
Get the current colors for the control
Colors currentColors = FindThemeColors();
-
Call
RefreshThemeStateColors(currentColors);
If migrating a v9 theme, override
RefreshThemeStateColors
and copy any code in the theme'sRefreshTheme
method (if overridden). -
(If migrating a v9 theme)
- Copy any code in the theme's
UpdateAndDraw
method. - If your code used the
control
parameter or castcontrol
to a specific type, do a find and replace operation withcontrol.
and a blank value. You no longer need to reference the control since the drawing code now lives in the control itself. - Replace references of
ControlThemeState
withThemeState
.
- Copy any code in the theme's
-
Draw the control by using the
Surface
property. -
Set
IsDirty = false
Here is the drawing code for the button control:
public override void UpdateAndRedraw(TimeSpan time)
{
// Step 1
if (!IsDirty) return;
// Step 2
Colors currentColors = FindThemeColors();
// Step 3
RefreshThemeStateColors(currentColors);
// Steps 4 and 5: Draw the control
ColoredGlyph appearance = ThemeState.GetStateAppearance(State);
ColoredGlyph endGlyphAppearance = ThemeState.GetStateAppearance(State);
endGlyphAppearance.Foreground = currentColors.Lines;
int middle = (Height != 1 ? Height / 2 : 0);
// Redraw the control
Surface.Fill(
appearance.Foreground,
appearance.Background,
appearance.Glyph, null);
if (ShowEnds && Width >= 3)
{
Surface.Print(1, middle, Text.Align(TextAlignment, Width - 2));
Surface.SetCellAppearance(0, middle, endGlyphAppearance);
Surface[0, middle].Glyph = LeftEndGlyph;
Surface.SetCellAppearance(Width - 1, middle, endGlyphAppearance);
Surface[Width - 1, middle].Glyph = RightEndGlyph;
}
else
Surface.Print(0, middle, Text.Align(TextAlignment, Width));
// Step 6
IsDirty = false;
}