mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-04-21 19:24:00 +00:00
更换壁纸功能
This commit is contained in:
@@ -1 +1 @@
|
|||||||
2026-03-24 17:25:50
|
2026-03-24 17:41:18
|
||||||
@@ -1 +1 @@
|
|||||||
5fd826a
|
6c75c51
|
||||||
@@ -18,8 +18,10 @@ using Cosmos.System.Graphics;
|
|||||||
using CMLeonOS;
|
using CMLeonOS;
|
||||||
using CMLeonOS.Gui.UILib;
|
using CMLeonOS.Gui.UILib;
|
||||||
using CMLeonOS.Settings;
|
using CMLeonOS.Settings;
|
||||||
|
using CMLeonOS.Utils;
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace CMLeonOS.Gui.Apps
|
namespace CMLeonOS.Gui.Apps
|
||||||
{
|
{
|
||||||
@@ -30,6 +32,7 @@ namespace CMLeonOS.Gui.Apps
|
|||||||
AppWindow window;
|
AppWindow window;
|
||||||
|
|
||||||
Window currentCategoryWindow;
|
Window currentCategoryWindow;
|
||||||
|
private FileBrowser wallpaperBrowser;
|
||||||
|
|
||||||
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
|
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
|
||||||
|
|
||||||
@@ -92,6 +95,70 @@ namespace CMLeonOS.Gui.Apps
|
|||||||
SettingsManager.SkipToGui = @checked;
|
SettingsManager.SkipToGui = @checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowMessage(string title, string text)
|
||||||
|
{
|
||||||
|
MessageBox messageBox = new MessageBox(this, title, text);
|
||||||
|
messageBox.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetWallpaperLabel()
|
||||||
|
{
|
||||||
|
string path = SettingsManager.GUI_WallpaperPath;
|
||||||
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
|
{
|
||||||
|
return "Current wallpaper: Default";
|
||||||
|
}
|
||||||
|
|
||||||
|
string fileName = Path.GetFileName(path);
|
||||||
|
if (string.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
fileName = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"Current wallpaper: {fileName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyWallpaper(string path)
|
||||||
|
{
|
||||||
|
string sanitizedPath = string.IsNullOrWhiteSpace(path) ? string.Empty : PathUtil.Sanitize(path.Trim());
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(sanitizedPath))
|
||||||
|
{
|
||||||
|
if (!File.Exists(sanitizedPath))
|
||||||
|
{
|
||||||
|
ShowMessage("Wallpaper", "File not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Path.GetExtension(sanitizedPath).Equals(".bmp", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
ShowMessage("Wallpaper", "Only BMP wallpapers are supported.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wm.ApplyWallpaper(sanitizedPath))
|
||||||
|
{
|
||||||
|
ShowMessage("Wallpaper", "Failed to apply wallpaper.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsManager.GUI_WallpaperPath = sanitizedPath;
|
||||||
|
ShowAppearanceCategory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenWallpaperBrowser()
|
||||||
|
{
|
||||||
|
wallpaperBrowser = new FileBrowser(this, wm, (string selectedPath) =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(selectedPath))
|
||||||
|
{
|
||||||
|
ApplyWallpaper(selectedPath);
|
||||||
|
}
|
||||||
|
}, selectDirectoryOnly: false);
|
||||||
|
wallpaperBrowser.Show();
|
||||||
|
}
|
||||||
|
|
||||||
private void MouseSensitivityChanged(float value)
|
private void MouseSensitivityChanged(float value)
|
||||||
{
|
{
|
||||||
SettingsManager.GUI_MouseSensitivity = value;
|
SettingsManager.GUI_MouseSensitivity = value;
|
||||||
@@ -126,6 +193,20 @@ namespace CMLeonOS.Gui.Apps
|
|||||||
skipToGui.CheckBoxChanged = SkipToGuiChanged;
|
skipToGui.CheckBoxChanged = SkipToGuiChanged;
|
||||||
wm.AddWindow(skipToGui);
|
wm.AddWindow(skipToGui);
|
||||||
|
|
||||||
|
appearance.DrawString("Wallpaper", Color.Gray, 12, 132);
|
||||||
|
appearance.DrawString(GetWallpaperLabel(), Color.Black, 12, 152);
|
||||||
|
appearance.DrawString("Choose a BMP file or restore the embedded default wallpaper.", Color.Gray, 12, 172);
|
||||||
|
|
||||||
|
Button chooseWallpaper = new Button(appearance, 12, 198, 132, 24);
|
||||||
|
chooseWallpaper.Text = "Choose BMP";
|
||||||
|
chooseWallpaper.OnClick = (_, _) => OpenWallpaperBrowser();
|
||||||
|
wm.AddWindow(chooseWallpaper);
|
||||||
|
|
||||||
|
Button defaultWallpaper = new Button(appearance, 154, 198, 132, 24);
|
||||||
|
defaultWallpaper.Text = "Use Default";
|
||||||
|
defaultWallpaper.OnClick = (_, _) => ApplyWallpaper(string.Empty);
|
||||||
|
wm.AddWindow(defaultWallpaper);
|
||||||
|
|
||||||
wm.Update(window);
|
wm.Update(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ using CMLeonOS.Gui.ShellComponents;
|
|||||||
using CMLeonOS.Settings;
|
using CMLeonOS.Settings;
|
||||||
using CMLeonOS.Driver;
|
using CMLeonOS.Driver;
|
||||||
using CMLeonOS.Logger;
|
using CMLeonOS.Logger;
|
||||||
|
using CMLeonOS.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace CMLeonOS.Gui
|
namespace CMLeonOS.Gui
|
||||||
{
|
{
|
||||||
@@ -79,6 +81,8 @@ namespace CMLeonOS.Gui
|
|||||||
|
|
||||||
private Bitmap wallpaperResized;
|
private Bitmap wallpaperResized;
|
||||||
|
|
||||||
|
internal string CurrentWallpaperPath { get; private set; } = string.Empty;
|
||||||
|
|
||||||
internal int Fps
|
internal int Fps
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -357,7 +361,51 @@ namespace CMLeonOS.Gui
|
|||||||
|
|
||||||
private void SetupWallpaper()
|
private void SetupWallpaper()
|
||||||
{
|
{
|
||||||
wallpaperResized = wallpaperBitmap.Resize(ScreenWidth, ScreenHeight);
|
if (!ApplyWallpaper(SettingsManager.GUI_WallpaperPath, rerender: false))
|
||||||
|
{
|
||||||
|
ApplyWallpaper(string.Empty, rerender: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool ApplyWallpaper(string path, bool rerender = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Bitmap sourceBitmap = wallpaperBitmap;
|
||||||
|
string sanitizedPath = string.Empty;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(path))
|
||||||
|
{
|
||||||
|
sanitizedPath = PathUtil.Sanitize(path.Trim());
|
||||||
|
|
||||||
|
if (!File.Exists(sanitizedPath))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Path.GetExtension(sanitizedPath).Equals(".bmp", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceBitmap = new Bitmap(File.ReadAllBytes(sanitizedPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
wallpaperResized = sourceBitmap.Resize(ScreenWidth, ScreenHeight);
|
||||||
|
CurrentWallpaperPath = sanitizedPath;
|
||||||
|
|
||||||
|
if (rerender)
|
||||||
|
{
|
||||||
|
RerenderAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Logger.Instance.Error("WindowManager", $"Failed to apply wallpaper: {ex.Message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCursor()
|
private void UpdateCursor()
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace CMLeonOS.Settings
|
|||||||
{ "GUI_MouseSensitivity", "1.0" },
|
{ "GUI_MouseSensitivity", "1.0" },
|
||||||
{ "GUI_ScreenWidth", "1280" },
|
{ "GUI_ScreenWidth", "1280" },
|
||||||
{ "GUI_ScreenHeight", "800" },
|
{ "GUI_ScreenHeight", "800" },
|
||||||
|
{ "GUI_WallpaperPath", "" },
|
||||||
{ "GUI_DarkNotepad", "false" },
|
{ "GUI_DarkNotepad", "false" },
|
||||||
{ "SkipToGui", "false" }
|
{ "SkipToGui", "false" }
|
||||||
};
|
};
|
||||||
@@ -190,6 +191,23 @@ namespace CMLeonOS.Settings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GUI_WallpaperPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (settings.TryGetValue("GUI_WallpaperPath", out string value))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
settings["GUI_WallpaperPath"] = value ?? string.Empty;
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool GUI_DarkNotepad
|
public static bool GUI_DarkNotepad
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
Reference in New Issue
Block a user