Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ MigrationBackup/

# Fody - auto-generated XML schema
FodyWeavers.xsd
.vscode/launch.json
.vscode/tasks.json
**/.vscode/launch.json
**/.vscode/tasks.json

# Rider
.idea/
Expand Down
73 changes: 73 additions & 0 deletions src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public partial class CodeEditorPanel : MarginContainer
private PackedScene _sharpIdeCodeEditScene = GD.Load<PackedScene>("res://Features/CodeEditor/SharpIdeCodeEdit.tscn");
private TabContainer _tabContainer = null!;
private ConcurrentDictionary<SharpIdeProjectModel, ExecutionStopInfo> _debuggerExecutionStopInfoByProject = [];
private TextureRect? _backgroundTextureRect;

[Inject] private readonly RunService _runService = null!;
[Inject] private readonly SharpIdeMetadataAsSourceService _sharpIdeMetadataAsSourceService = null!;

public override void _Ready()
{
_tabContainer = GetNode<TabContainer>("TabContainer");
Expand All @@ -34,6 +36,9 @@ public override void _Ready()
tabBar.TabClosePressed += OnTabClosePressed;
GlobalEvents.Instance.DebuggerExecutionStopped.Subscribe(OnDebuggerExecutionStopped);
GlobalEvents.Instance.ProjectStoppedDebugging.Subscribe(OnProjectStoppedDebugging);
GodotGlobalEvents.Instance.BackgroundImageChanged.Subscribe(OnBackgroundImageChanged);
GodotGlobalEvents.Instance.BackgroundTransparencyChanged.Subscribe(OnBackgroundTransparencyChanged);
InitializeBackgroundImage();
}

public override void _GuiInput(InputEvent @event)
Expand Down Expand Up @@ -242,6 +247,74 @@ await this.InvokeAsync(() =>
tabForStopInfo.SetLineColour(godotLine);
});
}

private void InitializeBackgroundImage()
{
var imagePath = Singletons.AppState.IdeSettings.BackgroundImagePath;
if (string.IsNullOrEmpty(imagePath)) return;

UpdateBackgroundImage(imagePath);
}

private Task OnBackgroundImageChanged(string imagePath)
{
UpdateBackgroundImage(imagePath);
return Task.CompletedTask;
}

private void UpdateBackgroundImage(string imagePath)
{
// Remove existing background if any
if (_backgroundTextureRect != null)
{
RemoveChild(_backgroundTextureRect);
_backgroundTextureRect.QueueFree();
_backgroundTextureRect = null;
}

if (string.IsNullOrEmpty(imagePath)) return;

// Load the texture
Texture2D? tex = null;
if (File.Exists(imagePath))
{
var image = Image.LoadFromFile(imagePath);
if (image != null)
{
tex = ImageTexture.CreateFromImage(image);
}
}

if (tex == null) return;

_backgroundTextureRect = new TextureRect
{
Texture = tex,
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize,
StretchMode = TextureRect.StretchModeEnum.KeepAspectCovered,
MouseFilter = MouseFilterEnum.Ignore
};

AddChild(_backgroundTextureRect);
MoveChild(_backgroundTextureRect, 0); // Move behind TabContainer

UpdateBackgroundTransparency(Singletons.AppState.IdeSettings.BackgroundImageTransparency);
}

private Task OnBackgroundTransparencyChanged(double transparency)
{
UpdateBackgroundTransparency(transparency);
return Task.CompletedTask;
}

private void UpdateBackgroundTransparency(double transparency)
{
if (_backgroundTextureRect == null) return;

var color = _backgroundTextureRect.Modulate;
color.A = 1 - (float)transparency;
_backgroundTextureRect.Modulate = color;
}
}

file static class TabContainerExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public void UpdateThemeColorCache(LightOrDarkTheme themeType)
};
}

private Color ApplyTransparency(Color color)
{
var transparency = (float)Singletons.AppState.IdeSettings.CodeBackgroundTransparency;
color.A = 1f - transparency;
return color;
}


public void SetHighlightingData(ImmutableArray<SharpIdeClassifiedSpan> classifiedSpans, ImmutableArray<SharpIdeRazorClassifiedSpan> razorClassifiedSpans)
{
Expand Down Expand Up @@ -160,7 +167,7 @@ private Dictionary MapRazorClassifiedSpansToHighlights(int line)

var highlightInfo = new Dictionary
{
{ ColorStringName, GetColorForRazorSpanKind(razorSpan.Kind, razorSpan.CodeClassificationType, razorSpan.VsSemanticRangeType) }
{ ColorStringName, ApplyTransparency(GetColorForRazorSpanKind(razorSpan.Kind, razorSpan.CodeClassificationType, razorSpan.VsSemanticRangeType)) }
};

highlights[columnIndex] = highlightInfo;
Expand Down Expand Up @@ -226,7 +233,7 @@ private Dictionary MapClassifiedSpansToHighlights(int line)
// Build the highlight entry
var highlightInfo = new Dictionary
{
{ ColorStringName, ClassificationToColorMapper.GetColorForClassification(ColourSetForTheme, classifiedSpans.Single().ClassificationType) }
{ ColorStringName, ApplyTransparency(ClassificationToColorMapper.GetColorForClassification(ColourSetForTheme, classifiedSpans.Single().ClassificationType)) }
};

highlights[columnIndex] = highlightInfo;
Expand Down
3 changes: 3 additions & 0 deletions src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public override void _Ready()
LinesEditedFrom += OnLinesEditedFrom;
GlobalEvents.Instance.SolutionAltered.Subscribe(OnSolutionAltered);
GodotGlobalEvents.Instance.TextEditorThemeChanged.Subscribe(UpdateEditorThemeAsync);
GodotGlobalEvents.Instance.BackgroundTransparencyChanged.Subscribe(OnBackgroundTransparencyChangedAsync);
GodotGlobalEvents.Instance.CodeBackgroundTransparencyChanged.Subscribe(OnCodeBackgroundTransparencyChangedAsync);
GodotGlobalEvents.Instance.CurrentLineHighlightColorChanged.Subscribe(OnCurrentLineHighlightColorChangedAsync);
SetCodeRegionTags("#region", "#endregion");
//AddGitGutter();
var hScrollBar = GetHScrollBar();
Expand Down
39 changes: 39 additions & 0 deletions src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public partial class SharpIdeCodeEdit
{
private static readonly StringName ThemeInfoStringName = "ThemeInfo";
private static readonly StringName IsLight1OrDark2StringName = "IsLight1OrDark2";
private static readonly StringName CurrentLineColorStringName = "current_line_color";

private void UpdateEditorThemeForCurrentTheme()
{
Expand All @@ -25,5 +26,43 @@ private void UpdateEditorTheme(LightOrDarkTheme lightOrDarkTheme)
_syntaxHighlighter.UpdateThemeColorCache(lightOrDarkTheme);
SyntaxHighlighter = null;
SyntaxHighlighter = _syntaxHighlighter; // Reassign to trigger redraw
MakeEditorTransparent();
ApplyCurrentLineHighlightColor();
}

private void MakeEditorTransparent()
{
var codeEditStyle = (StyleBoxFlat)GetThemeStylebox("normal");
var bgColor = codeEditStyle.BgColor;
bgColor.A = 0f;
codeEditStyle.BgColor = bgColor;
}

private Task OnBackgroundTransparencyChangedAsync(double transparency)
{
MakeEditorTransparent();
return Task.CompletedTask;
}

private Task OnCodeBackgroundTransparencyChangedAsync(double transparency)
{
// Force the syntax highlighter to redraw itself
var syntaxHighlighter = SyntaxHighlighter;
SyntaxHighlighter = null;
SyntaxHighlighter = syntaxHighlighter;
return Task.CompletedTask;
}

private Task OnCurrentLineHighlightColorChangedAsync(Color color)
{
ApplyCurrentLineHighlightColor();
return Task.CompletedTask;
}

private void ApplyCurrentLineHighlightColor()
{
var colorString = Singletons.AppState.IdeSettings.CurrentLineHighlightColor;
var color = new Color(colorString);
AddThemeColorOverride(CurrentLineColorStringName, color);
}
}
4 changes: 4 additions & 0 deletions src/SharpIDE.Godot/Features/IdeSettings/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class IdeSettings
public bool DebuggerUseSharpDbg { get; set; } = true;
public float UiScale { get; set; } = 1.0f;
public LightOrDarkTheme Theme { get; set; } = LightOrDarkTheme.Dark;
public string BackgroundImagePath { get; set; } = "";
public double BackgroundImageTransparency { get; set; } = 0.7;
public double CodeBackgroundTransparency { get; set; } = 0.05;
public string CurrentLineHighlightColor { get; set; } = "#0f0f0f";
}

[JsonConverter(typeof(JsonStringEnumConverter))]
Expand Down
70 changes: 69 additions & 1 deletion src/SharpIDE.Godot/Features/Settings/SettingsWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Godot;
using System;
using SharpIDE.Godot.Features.IdeSettings;

namespace SharpIDE.Godot.Features.Settings;
Expand All @@ -9,6 +10,12 @@ public partial class SettingsWindow : Window
private LineEdit _debuggerFilePathLineEdit = null!;
private CheckButton _debuggerUseSharpDbgCheckButton = null!;
private OptionButton _themeOptionButton = null!;
private LineEdit _backgroundImageLineEdit = null!;
private Button _backgroundImageSelectBtn = null!;
private HSlider _backgroundImageTransparencySlider = null!;
private HSlider _codeBackgroundTransparencySlider = null!;
private FileDialog _fileDialog = null!;
private ColorPickerButton _currentLineHighlightColorPickerButton = null!;

public override void _Ready()
{
Expand All @@ -17,11 +24,30 @@ public override void _Ready()
_debuggerFilePathLineEdit = GetNode<LineEdit>("%DebuggerFilePathLineEdit");
_debuggerUseSharpDbgCheckButton = GetNode<CheckButton>("%DebuggerUseSharpDbgCheckButton");
_themeOptionButton = GetNode<OptionButton>("%ThemeOptionButton");
_backgroundImageLineEdit = GetNode<LineEdit>("%BackgroundImageLineEdit");
_backgroundImageSelectBtn = GetNode<Button>("%BackgroundImageSelectBtn");
_backgroundImageTransparencySlider = GetNode<HSlider>("%BackgroundImageTransparencySlider");
_codeBackgroundTransparencySlider = GetNode<HSlider>("%CodeBackgroundTransparencySlider");
_currentLineHighlightColorPickerButton = GetNode<ColorPickerButton>("%CurrentLineHighlightColorPickerButton");
_currentLineHighlightColorPickerButton.EditAlpha = true;
_fileDialog = new FileDialog
{
Access = FileDialog.AccessEnum.Filesystem,
CurrentDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures),
FileMode = FileDialog.FileModeEnum.OpenFile,
Filters = ["*.png, *.jpg, *.jpeg, *.svg, *.bmp, *.webp ; Image Files"]
};
_uiScaleSpinBox.ValueChanged += OnUiScaleSpinBoxValueChanged;
_debuggerFilePathLineEdit.TextChanged += OnDebuggerFilePathChanged;
_debuggerUseSharpDbgCheckButton.Toggled += OnDebuggerUseSharpDbgToggled;
_themeOptionButton.ItemSelected += OnThemeItemSelected;
_backgroundImageSelectBtn.Pressed += OnBackgroundImageSelectBtnPressed;
_backgroundImageTransparencySlider.ValueChanged += OnBackgroundImageTransparencySliderChanged;
_codeBackgroundTransparencySlider.ValueChanged += OnCodeBackgroundTransparencySliderChanged;
_currentLineHighlightColorPickerButton.ColorChanged += OnCurrentLineHighlightColorChanged;
_fileDialog.FileSelected += OnFileDialogFileSelected;
AboutToPopup += OnAboutToPopup;
AddChild(_fileDialog);
}

private void OnAboutToPopup()
Expand All @@ -31,12 +57,17 @@ private void OnAboutToPopup()
_debuggerUseSharpDbgCheckButton.ButtonPressed = Singletons.AppState.IdeSettings.DebuggerUseSharpDbg;
var themeOptionIndex = _themeOptionButton.GetOptionIndexOrNullForString(Singletons.AppState.IdeSettings.Theme.ToString());
if (themeOptionIndex is not null) _themeOptionButton.Selected = themeOptionIndex.Value;
_backgroundImageLineEdit.Text = Singletons.AppState.IdeSettings.BackgroundImagePath;
_backgroundImageTransparencySlider.Value = Singletons.AppState.IdeSettings.BackgroundImageTransparency;
_codeBackgroundTransparencySlider.Value = Singletons.AppState.IdeSettings.CodeBackgroundTransparency;
_currentLineHighlightColorPickerButton.Color = new Color(Singletons.AppState.IdeSettings.CurrentLineHighlightColor);
}

private void OnUiScaleSpinBoxValueChanged(double value)
{
var valueFloat = (float)value;
Singletons.AppState.IdeSettings.UiScale = valueFloat;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);

GetTree().GetRoot().ContentScaleFactor = valueFloat;
PopupCenteredRatio(0.5f); // Re-size the window after scaling
Expand All @@ -45,11 +76,13 @@ private void OnUiScaleSpinBoxValueChanged(double value)
private void OnDebuggerFilePathChanged(string newText)
{
Singletons.AppState.IdeSettings.DebuggerExecutablePath = newText;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
}

private void OnDebuggerUseSharpDbgToggled(bool pressed)
{
Singletons.AppState.IdeSettings.DebuggerUseSharpDbg = pressed;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
}

private void OnThemeItemSelected(long index)
Expand All @@ -62,7 +95,42 @@ private void OnThemeItemSelected(long index)
_ => throw new InvalidOperationException($"Unknown theme selected: {selectedTheme}")
};
Singletons.AppState.IdeSettings.Theme = lightOrDarkTheme;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
this.SetIdeTheme(lightOrDarkTheme);
GodotGlobalEvents.Instance.TextEditorThemeChanged.InvokeParallelFireAndForget(lightOrDarkTheme);
}
}

private void OnBackgroundImageSelectBtnPressed()
{
_fileDialog.PopupCentered();
}

private void OnFileDialogFileSelected(string path)
{
_backgroundImageLineEdit.Text = path;
Singletons.AppState.IdeSettings.BackgroundImagePath = path;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
GodotGlobalEvents.Instance.BackgroundImageChanged.InvokeParallelFireAndForget(path);
}

private void OnBackgroundImageTransparencySliderChanged(double newValue)
{
Singletons.AppState.IdeSettings.BackgroundImageTransparency = newValue;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
GodotGlobalEvents.Instance.BackgroundTransparencyChanged.InvokeParallelFireAndForget(newValue);
}

private void OnCodeBackgroundTransparencySliderChanged(double newValue)
{
Singletons.AppState.IdeSettings.CodeBackgroundTransparency = newValue;
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
GodotGlobalEvents.Instance.CodeBackgroundTransparencyChanged.InvokeParallelFireAndForget(newValue);
}

private void OnCurrentLineHighlightColorChanged(Color color)
{
Singletons.AppState.IdeSettings.CurrentLineHighlightColor = color.ToHtml();
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
GodotGlobalEvents.Instance.CurrentLineHighlightColorChanged.InvokeParallelFireAndForget(color);
}
}
Loading