Skip to content

Commit

Permalink
fix(Studio): Don't serialize SKPaint cache
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Oct 27, 2024
1 parent 95115ba commit 95552b0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Studio/CelesteStudio/Editing/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SkiaSharp;
using System;
using System.Collections.Generic;
using Tomlet.Attributes;

namespace CelesteStudio.Editing;

Expand Down Expand Up @@ -70,26 +71,46 @@ public struct Theme {
public Style Frame;
public Style Comment;

// Cache SKPaints
#region SKPaint cache
// Cache SKPaint instances to avoid creating, disposing and configuring them for every draw

[TomlNonSerialized]
private StylePaint? _actionPaint, _anglePaint, _breakpointPaint, _savestateBreakpointPaint, _delimiter, _command, _frame, _comment;
[TomlNonSerialized]
private SKPaint? _commentBox, _statusFgPaint, _subpixelIndicatorDotPaint, _popupMenuFgPaint, _popupMenuFgDisabledPaint, _popupMenuFgExtraPaint, _popupMenuBgPaint, _popupMenuSelectedPaint;

[TomlNonSerialized]
public StylePaint ActionPaint => _actionPaint ??= Action.CreatePaint();
[TomlNonSerialized]
public StylePaint AnglePaint => _anglePaint ??= Angle.CreatePaint();
[TomlNonSerialized]
public StylePaint BreakpointPaint => _breakpointPaint ??= Breakpoint.CreatePaint();
[TomlNonSerialized]
public StylePaint SavestateBreakpointPaint => _savestateBreakpointPaint ??= SavestateBreakpoint.CreatePaint();
[TomlNonSerialized]
public StylePaint DelimiterPaint => _delimiter ??= Delimiter.CreatePaint();
[TomlNonSerialized]
public StylePaint CommandPaint => _command ??= Command.CreatePaint();
[TomlNonSerialized]
public StylePaint FramePaint => _frame ??= Frame.CreatePaint();
[TomlNonSerialized]
public StylePaint CommentPaint => _comment ??= Comment.CreatePaint();
[TomlNonSerialized]
public SKPaint CommentBoxPaint => _commentBox ??= Comment.CreateForegroundPaint(SKPaintStyle.Stroke);

[TomlNonSerialized]
public SKPaint StatusFgPaint => _statusFgPaint ??= new SKPaint { ColorF = StatusFg.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };
[TomlNonSerialized]
public SKPaint SubpixelIndicatorDotPaint => _subpixelIndicatorDotPaint ??= new SKPaint { ColorF = SubpixelIndicatorDot.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };
[TomlNonSerialized]
public SKPaint PopupMenuFgPaint => _popupMenuFgPaint ??= new SKPaint { ColorF = PopupMenuFg.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };
[TomlNonSerialized]
public SKPaint PopupMenuFgDisabledPaint => _popupMenuFgDisabledPaint ??= new SKPaint { ColorF = PopupMenuFgDisabled.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };
[TomlNonSerialized]
public SKPaint PopupMenuFgExtraPaint => _popupMenuFgExtraPaint ??= new SKPaint { ColorF = PopupMenuFgExtra.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };
[TomlNonSerialized]
public SKPaint PopupMenuBgPaint => _popupMenuBgPaint ??= new SKPaint { ColorF = PopupMenuBg.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };
[TomlNonSerialized]
public SKPaint PopupMenuSelectedPaint => _popupMenuSelectedPaint ??= new SKPaint { ColorF = PopupMenuSelected.ToSkia(), Style = SKPaintStyle.Fill, IsAntialias = true };

public void InvalidateCache() {
Expand All @@ -115,6 +136,8 @@ public void InvalidateCache() {
_commentBox = _statusFgPaint = _subpixelIndicatorDotPaint = _popupMenuFgPaint = _popupMenuFgDisabledPaint = _popupMenuFgExtraPaint = _popupMenuBgPaint = _popupMenuSelectedPaint = null;
}

#endregion

public bool DarkMode;

public const string BuiltinLight = "Light";
Expand Down

0 comments on commit 95552b0

Please sign in to comment.