restructure

This commit is contained in:
NinjaPug
2025-04-14 12:46:10 -04:00
parent 1cf596b379
commit 21b6ad3d75
22 changed files with 1257 additions and 990 deletions

View File

@@ -0,0 +1,256 @@
using PCPalConfigurator.Rendering;
using PCPalConfigurator.UI;
namespace PCPalConfigurator.UI
{
partial class ConfiguratorForm
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.TabControl tabControl;
private System.Windows.Forms.TabPage tab1602;
private System.Windows.Forms.TabPage tabTFT;
private System.Windows.Forms.TabPage tabOLED;
private System.Windows.Forms.TabPage tabHelp;
private System.Windows.Forms.TabPage tabAbout;
private System.Windows.Forms.ComboBox cmbLine1;
private System.Windows.Forms.TextBox txtLine1;
private System.Windows.Forms.TextBox txtLine1Post;
private System.Windows.Forms.ComboBox cmbLine2;
private System.Windows.Forms.TextBox txtLine2;
private System.Windows.Forms.TextBox txtLine2Post;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.Label lblLine1;
private System.Windows.Forms.Label lblLine1Prefix;
private System.Windows.Forms.Label lblLine1Suffix;
private System.Windows.Forms.Label lblLine2;
private System.Windows.Forms.Label lblLine2Prefix;
private System.Windows.Forms.Label lblLine2Suffix;
// OLED tab controls
private System.Windows.Forms.TextBox txtOledMarkup;
private System.Windows.Forms.Panel panelOledButtons;
private System.Windows.Forms.Button btnInsertIcon;
private System.Windows.Forms.Button btnLoadOledExample;
private System.Windows.Forms.Button btnSaveOled;
private System.Windows.Forms.Button btnPreview;
private System.Windows.Forms.Label lblPreviewHeader;
private OledPreviewPanel oledPreviewPanel;
// Help tab controls
private System.Windows.Forms.TextBox txtHelpContent;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.tabControl = new System.Windows.Forms.TabControl();
this.tab1602 = new System.Windows.Forms.TabPage("1602 LCD");
this.tabTFT = new System.Windows.Forms.TabPage("4.6\" TFT LCD");
this.tabOLED = new System.Windows.Forms.TabPage("OLED Display");
this.tabHelp = new System.Windows.Forms.TabPage("Help");
this.tabAbout = new System.Windows.Forms.TabPage("About");
this.cmbLine1 = new System.Windows.Forms.ComboBox();
this.txtLine1 = new System.Windows.Forms.TextBox();
this.txtLine1Post = new System.Windows.Forms.TextBox();
this.cmbLine2 = new System.Windows.Forms.ComboBox();
this.txtLine2 = new System.Windows.Forms.TextBox();
this.txtLine2Post = new System.Windows.Forms.TextBox();
this.btnSave = new System.Windows.Forms.Button();
this.lblLine1 = new System.Windows.Forms.Label();
this.lblLine1Prefix = new System.Windows.Forms.Label();
this.lblLine1Suffix = new System.Windows.Forms.Label();
this.lblLine2 = new System.Windows.Forms.Label();
this.lblLine2Prefix = new System.Windows.Forms.Label();
this.lblLine2Suffix = new System.Windows.Forms.Label();
// OLED tab controls
this.txtOledMarkup = new System.Windows.Forms.TextBox();
this.panelOledButtons = new System.Windows.Forms.Panel();
this.btnInsertIcon = new System.Windows.Forms.Button();
this.btnLoadOledExample = new System.Windows.Forms.Button();
this.btnSaveOled = new System.Windows.Forms.Button();
this.btnPreview = new System.Windows.Forms.Button();
this.lblPreviewHeader = new System.Windows.Forms.Label();
this.oledPreviewPanel = new OledPreviewPanel();
// Help tab controls
this.txtHelpContent = new System.Windows.Forms.TextBox();
// === TabControl ===
this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl.TabPages.Add(this.tab1602);
this.tabControl.TabPages.Add(this.tabTFT);
this.tabControl.TabPages.Add(this.tabOLED);
this.tabControl.TabPages.Add(this.tabHelp);
this.tabControl.TabPages.Add(this.tabAbout);
this.Controls.Add(this.tabControl);
// === Line 1 UI ===
this.lblLine1.Text = "Line 1:";
this.lblLine1.Location = new System.Drawing.Point(20, 20);
this.lblLine1.AutoSize = true;
this.cmbLine1.Location = new System.Drawing.Point(100, 18);
this.cmbLine1.Size = new System.Drawing.Size(200, 21);
this.lblLine1Prefix.Text = "Prefix:";
this.lblLine1Prefix.Location = new System.Drawing.Point(20, 50);
this.lblLine1Prefix.AutoSize = true;
this.txtLine1.Location = new System.Drawing.Point(100, 48);
this.txtLine1.Size = new System.Drawing.Size(200, 21);
this.lblLine1Suffix.Text = "Suffix / Units:";
this.lblLine1Suffix.Location = new System.Drawing.Point(320, 50);
this.lblLine1Suffix.AutoSize = true;
this.txtLine1Post.Location = new System.Drawing.Point(420, 48);
this.txtLine1Post.Size = new System.Drawing.Size(120, 21);
// === Line 2 UI ===
this.lblLine2.Text = "Line 2:";
this.lblLine2.Location = new System.Drawing.Point(20, 90);
this.lblLine2.AutoSize = true;
this.cmbLine2.Location = new System.Drawing.Point(100, 88);
this.cmbLine2.Size = new System.Drawing.Size(200, 21);
this.lblLine2Prefix.Text = "Prefix:";
this.lblLine2Prefix.Location = new System.Drawing.Point(20, 120);
this.lblLine2Prefix.AutoSize = true;
this.txtLine2.Location = new System.Drawing.Point(100, 118);
this.txtLine2.Size = new System.Drawing.Size(200, 21);
this.lblLine2Suffix.Text = "Suffix / Units:";
this.lblLine2Suffix.Location = new System.Drawing.Point(320, 120);
this.lblLine2Suffix.AutoSize = true;
this.txtLine2Post.Location = new System.Drawing.Point(420, 118);
this.txtLine2Post.Size = new System.Drawing.Size(120, 21);
// === Save Button ===
this.btnSave.Text = "Save";
this.btnSave.Location = new System.Drawing.Point(20, 170);
this.btnSave.Size = new System.Drawing.Size(100, 30);
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
// === Add to 1602 Tab ===
this.tab1602.Controls.AddRange(new System.Windows.Forms.Control[]
{
lblLine1, cmbLine1, lblLine1Prefix, txtLine1, lblLine1Suffix, txtLine1Post,
lblLine2, cmbLine2, lblLine2Prefix, txtLine2, lblLine2Suffix, txtLine2Post,
btnSave
});
// === OLED Tab Setup ===
// Main panel for layout
System.Windows.Forms.Panel oledMainPanel = new System.Windows.Forms.Panel();
oledMainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabOLED.Controls.Add(oledMainPanel);
// Markup editor
this.txtOledMarkup = new System.Windows.Forms.TextBox();
this.txtOledMarkup.Multiline = true;
this.txtOledMarkup.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtOledMarkup.Font = new System.Drawing.Font("Consolas", 9.75F);
this.txtOledMarkup.TextChanged += new System.EventHandler(this.txtOledMarkup_TextChanged);
this.txtOledMarkup.Size = new System.Drawing.Size(580, 130);
this.txtOledMarkup.Location = new System.Drawing.Point(10, 10);
oledMainPanel.Controls.Add(this.txtOledMarkup);
// Button panel
this.panelOledButtons = new System.Windows.Forms.Panel();
this.panelOledButtons.Size = new System.Drawing.Size(580, 40);
this.panelOledButtons.Location = new System.Drawing.Point(10, 150);
oledMainPanel.Controls.Add(this.panelOledButtons);
this.btnInsertIcon = new System.Windows.Forms.Button();
this.btnInsertIcon.Text = "Insert Icon";
this.btnInsertIcon.Location = new System.Drawing.Point(0, 7);
this.btnInsertIcon.Size = new System.Drawing.Size(120, 26);
this.btnInsertIcon.Click += new System.EventHandler(this.btnInsertIcon_Click);
this.panelOledButtons.Controls.Add(this.btnInsertIcon);
this.btnLoadOledExample = new System.Windows.Forms.Button();
this.btnLoadOledExample.Text = "Load Example";
this.btnLoadOledExample.Location = new System.Drawing.Point(130, 7);
this.btnLoadOledExample.Size = new System.Drawing.Size(120, 26);
this.btnLoadOledExample.Click += new System.EventHandler(this.btnLoadOledExample_Click);
this.panelOledButtons.Controls.Add(this.btnLoadOledExample);
this.btnPreview = new System.Windows.Forms.Button();
this.btnPreview.Text = "Update Preview";
this.btnPreview.Location = new System.Drawing.Point(260, 7);
this.btnPreview.Size = new System.Drawing.Size(120, 26);
this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
this.panelOledButtons.Controls.Add(this.btnPreview);
this.btnSaveOled = new System.Windows.Forms.Button();
this.btnSaveOled.Text = "Save";
this.btnSaveOled.Location = new System.Drawing.Point(480, 7);
this.btnSaveOled.Size = new System.Drawing.Size(100, 26);
this.btnSaveOled.Click += new System.EventHandler(this.btnSave_Click); // Uses same event handler
this.panelOledButtons.Controls.Add(this.btnSaveOled);
// Preview header
this.lblPreviewHeader = new System.Windows.Forms.Label();
this.lblPreviewHeader.Text = "OLED Preview (256x64)";
this.lblPreviewHeader.Location = new System.Drawing.Point(10, 195);
this.lblPreviewHeader.Size = new System.Drawing.Size(580, 20);
this.lblPreviewHeader.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblPreviewHeader.BackColor = System.Drawing.SystemColors.ControlLight;
this.lblPreviewHeader.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
oledMainPanel.Controls.Add(this.lblPreviewHeader);
// Preview panel
this.oledPreviewPanel.Location = new System.Drawing.Point(10, 215);
this.oledPreviewPanel.Size = new System.Drawing.Size(580, 110);
oledMainPanel.Controls.Add(this.oledPreviewPanel);
// === Help Tab Setup ===
this.txtHelpContent = new System.Windows.Forms.TextBox();
this.txtHelpContent.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtHelpContent.Multiline = true;
this.txtHelpContent.ReadOnly = true;
this.txtHelpContent.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtHelpContent.Font = new System.Drawing.Font("Segoe UI", 9F);
this.tabHelp.Controls.Add(this.txtHelpContent);
// === TFT Tab Placeholder ===
System.Windows.Forms.Label lblTFT = new System.Windows.Forms.Label()
{
Text = "TFT configuration coming soon...",
Location = new System.Drawing.Point(20, 20),
AutoSize = true
};
this.tabTFT.Controls.Add(lblTFT);
// === About Tab ===
System.Windows.Forms.Label lblAbout = new System.Windows.Forms.Label()
{
Text = "PCPal Display Configurator\nFor ThermalTake Tower XXX\nVersion 1.0.0\n© 2025 Christopher Koch aka NinjaPug",
Location = new System.Drawing.Point(20, 20),
AutoSize = true
};
this.tabAbout.Controls.Add(lblAbout);
// === Form ===
this.Text = "Display Configurator";
this.ClientSize = new System.Drawing.Size(600, 380);
this.ResumeLayout(false);
this.PerformLayout();
}
}
}

View File

@@ -0,0 +1,292 @@
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using Newtonsoft.Json;
using PCPalConfigurator.Core;
using PCPalConfigurator.Rendering;
namespace PCPalConfigurator.UI
{
public partial class ConfiguratorForm : Form
{
private ConfigData config;
private readonly string configFile;
private SensorManager sensorManager;
private System.Windows.Forms.Timer sensorUpdateTimer;
private MarkupParser markupParser;
private List<PreviewElement> previewElements = new List<PreviewElement>();
public ConfiguratorForm()
{
InitializeComponent();
// Initialize the configuration path
configFile = GetConfigPath();
// Initialize hardware monitoring
sensorManager = new SensorManager();
sensorManager.UpdateSensorValues();
// Initialize markup parser
markupParser = new MarkupParser(sensorManager.GetAllSensorValues());
// Setup timer for sensor updates
InitSensorTimer();
// Load configuration and populate UI
LoadConfig();
PopulateSensorOptions();
PopulateHelpContent();
// Initial preview update
UpdatePreview();
}
private void InitSensorTimer()
{
// Create a timer to regularly update sensor values for the preview
sensorUpdateTimer = new System.Windows.Forms.Timer();
sensorUpdateTimer.Interval = 1000; // Update every second
sensorUpdateTimer.Tick += SensorUpdateTimer_Tick;
sensorUpdateTimer.Start();
}
private void SensorUpdateTimer_Tick(object sender, EventArgs e)
{
// Only update when the OLED tab is selected to save resources
if (tabControl.SelectedTab == tabOLED)
{
sensorManager.UpdateSensorValues();
markupParser = new MarkupParser(sensorManager.GetAllSensorValues());
UpdatePreview();
}
}
private static string GetConfigPath()
{
string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "PCPal");
Directory.CreateDirectory(folder);
return Path.Combine(folder, "config.json");
}
private void LoadConfig()
{
if (File.Exists(configFile))
{
string json = File.ReadAllText(configFile);
config = JsonConvert.DeserializeObject<ConfigData>(json) ?? new ConfigData();
ApplyConfig();
}
else
{
config = new ConfigData();
}
}
private void ApplyConfig()
{
// LCD settings
cmbLine1.SelectedItem = config.Line1Selection;
txtLine1.Text = config.Line1CustomText;
txtLine1Post.Text = config.Line1PostText;
cmbLine2.SelectedItem = config.Line2Selection;
txtLine2.Text = config.Line2CustomText;
txtLine2Post.Text = config.Line2PostText;
// OLED settings
txtOledMarkup.Text = config.OledMarkup;
// Select the appropriate tab based on screen type
if (config.ScreenType == "1602")
tabControl.SelectedTab = tab1602;
else if (config.ScreenType == "TFT4_6")
tabControl.SelectedTab = tabTFT;
else if (config.ScreenType == "OLED")
tabControl.SelectedTab = tabOLED;
}
private void SaveConfig()
{
// Determine screen type based on selected tab
if (tabControl.SelectedTab == tab1602)
config.ScreenType = "1602";
else if (tabControl.SelectedTab == tabTFT)
config.ScreenType = "TFT4_6";
else if (tabControl.SelectedTab == tabOLED)
config.ScreenType = "OLED";
// Save LCD settings
config.Line1Selection = cmbLine1.SelectedItem?.ToString();
config.Line1CustomText = txtLine1.Text;
config.Line1PostText = txtLine1Post.Text;
config.Line2Selection = cmbLine2.SelectedItem?.ToString();
config.Line2CustomText = txtLine2.Text;
config.Line2PostText = txtLine2Post.Text;
// Save OLED settings
config.OledMarkup = txtOledMarkup.Text;
string json = JsonConvert.SerializeObject(config, Formatting.Indented);
File.WriteAllText(configFile, json);
MessageBox.Show("Settings saved!");
}
private void btnSave_Click(object sender, EventArgs e)
{
SaveConfig();
}
private void PopulateSensorOptions()
{
var options = sensorManager.GetSensorOptionsForDropdown();
cmbLine1.Items.Clear();
cmbLine2.Items.Clear();
foreach (var option in options)
{
cmbLine1.Items.Add(option);
cmbLine2.Items.Add(option);
}
}
private void PopulateHelpContent()
{
// Create help content for both LCD and OLED displays
StringBuilder sb = new StringBuilder();
// General Information
sb.AppendLine("PCPal Display Configurator Help");
sb.AppendLine("==============================");
sb.AppendLine();
// LCD Display Help
sb.AppendLine("LCD DISPLAY CONFIGURATION");
sb.AppendLine("------------------------");
sb.AppendLine("1. Select a sensor for each line or choose 'Custom Text'");
sb.AppendLine("2. Set prefix text to appear before the sensor value");
sb.AppendLine("3. Set suffix/units to appear after the sensor value");
sb.AppendLine("4. Click 'Save' to apply your settings");
sb.AppendLine();
// OLED Display Help
sb.AppendLine("OLED MARKUP REFERENCE");
sb.AppendLine("---------------------");
sb.AppendLine("The OLED display accepts markup tags to create your layout.");
sb.AppendLine();
sb.AppendLine("Text: <text x=0 y=10 size=1>Hello World</text>");
sb.AppendLine(" - x, y: position coordinates (0,0 is top-left)");
sb.AppendLine(" - size: 1-3 (small to large)");
sb.AppendLine();
sb.AppendLine("Progress Bar: <bar x=0 y=20 w=100 h=8 val=75 />");
sb.AppendLine(" - x, y: position");
sb.AppendLine(" - w, h: width and height");
sb.AppendLine(" - val: value 0-100");
sb.AppendLine();
sb.AppendLine("Icon: <icon x=0 y=0 name=cpu />");
sb.AppendLine(" - Inserts a bitmap icon from the SD card");
sb.AppendLine(" - Use the 'Insert Icon' button to browse available icons");
sb.AppendLine();
sb.AppendLine("Rectangle (outline): <rect x=0 y=0 w=20 h=10 />");
sb.AppendLine();
sb.AppendLine("Filled Box: <box x=0 y=0 w=20 h=10 />");
sb.AppendLine();
sb.AppendLine("Line: <line x1=0 y1=0 x2=20 y2=20 />");
sb.AppendLine();
// Sensor variables
sb.AppendLine("SENSOR VARIABLES");
sb.AppendLine("----------------");
sb.AppendLine("Use {SensorName} syntax to include sensor values.");
sb.AppendLine("Example: <text x=0 y=10>CPU: {CPU_Core_i7_Total_Load}%</text>");
// Add available sensor variables with their current values
sb.AppendLine();
sb.AppendLine("Available sensor variables:");
var sensorGroups = sensorManager.GetAllSensorsGroupedByType();
foreach (var group in sensorGroups)
{
sb.AppendLine();
sb.AppendLine($"-- {group.Key} Sensors --");
foreach (var sensor in group.Value) // Change here - iterate over group.Value
{
string unit = SensorManager.GetSensorUnit(group.Key);
string value = SensorManager.FormatSensorValue(sensor.Value, group.Key);
sb.AppendLine($"{{{sensor.Id}}} = {value}{unit} ({sensor.Name})");
}
}
txtHelpContent.Text = sb.ToString();
}
private void btnInsertIcon_Click(object sender, EventArgs e)
{
using (var browser = new IconBrowser())
{
if (browser.ShowDialog() == DialogResult.OK)
{
// Get the icon markup and insert it at the cursor position
string iconMarkup = browser.GetIconMarkup();
if (!string.IsNullOrEmpty(iconMarkup))
{
int selectionStart = txtOledMarkup.SelectionStart;
txtOledMarkup.Text = txtOledMarkup.Text.Insert(selectionStart, iconMarkup);
txtOledMarkup.SelectionStart = selectionStart + iconMarkup.Length;
txtOledMarkup.Focus();
}
}
}
}
private void btnLoadOledExample_Click(object sender, EventArgs e)
{
// Create an example with sensors from the current system
string exampleMarkup = MarkupParser.CreateExampleMarkup(sensorManager);
txtOledMarkup.Text = exampleMarkup;
}
private void btnPreview_Click(object sender, EventArgs e)
{
sensorManager.UpdateSensorValues();
markupParser = new MarkupParser(sensorManager.GetAllSensorValues());
UpdatePreview();
}
private void txtOledMarkup_TextChanged(object sender, EventArgs e)
{
UpdatePreview();
}
private void UpdatePreview()
{
try
{
// Parse the markup into preview elements
previewElements = markupParser.ParseMarkup(txtOledMarkup.Text);
// Update the preview panel
oledPreviewPanel.SetPreviewElements(previewElements);
}
catch (Exception ex)
{
// Don't show errors during preview - just log them
Console.WriteLine($"Preview error: {ex.Message}");
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
// Clean up resources
sensorUpdateTimer?.Stop();
sensorUpdateTimer?.Dispose();
sensorManager?.Dispose();
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,320 @@
using System.Windows.Forms;
using System.Drawing;
namespace PCPalConfigurator.UI
{
partial class IconBrowser
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panelTop = new System.Windows.Forms.Panel();
this.btnBrowse = new System.Windows.Forms.Button();
this.txtIconDirectory = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.panelBottom = new System.Windows.Forms.Panel();
this.txtIconDimensions = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.numY = new System.Windows.Forms.NumericUpDown();
this.numX = new System.Windows.Forms.NumericUpDown();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtIconName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.btnInsert = new System.Windows.Forms.Button();
this.lblStatus = new System.Windows.Forms.Label();
this.splitContainer = new System.Windows.Forms.SplitContainer();
this.lstIcons = new System.Windows.Forms.ListBox();
this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.panelTop.SuspendLayout();
this.panelBottom.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numY)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numX)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
this.splitContainer.SuspendLayout();
this.SuspendLayout();
//
// panelTop
//
this.panelTop.Controls.Add(this.btnBrowse);
this.panelTop.Controls.Add(this.txtIconDirectory);
this.panelTop.Controls.Add(this.label1);
this.panelTop.Dock = System.Windows.Forms.DockStyle.Top;
this.panelTop.Location = new System.Drawing.Point(0, 0);
this.panelTop.Name = "panelTop";
this.panelTop.Size = new System.Drawing.Size(584, 40);
this.panelTop.TabIndex = 0;
//
// btnBrowse
//
this.btnBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnBrowse.Location = new System.Drawing.Point(497, 9);
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.Size = new System.Drawing.Size(75, 23);
this.btnBrowse.TabIndex = 2;
this.btnBrowse.Text = "Browse...";
this.btnBrowse.UseVisualStyleBackColor = true;
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
//
// txtIconDirectory
//
this.txtIconDirectory.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtIconDirectory.Location = new System.Drawing.Point(119, 10);
this.txtIconDirectory.Name = "txtIconDirectory";
this.txtIconDirectory.Size = new System.Drawing.Size(372, 23);
this.txtIconDirectory.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(101, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Icons Directory:";
//
// panelBottom
//
this.panelBottom.Controls.Add(this.txtIconDimensions);
this.panelBottom.Controls.Add(this.label5);
this.panelBottom.Controls.Add(this.numY);
this.panelBottom.Controls.Add(this.numX);
this.panelBottom.Controls.Add(this.label4);
this.panelBottom.Controls.Add(this.label3);
this.panelBottom.Controls.Add(this.txtIconName);
this.panelBottom.Controls.Add(this.label2);
this.panelBottom.Controls.Add(this.btnCancel);
this.panelBottom.Controls.Add(this.btnInsert);
this.panelBottom.Controls.Add(this.lblStatus);
this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelBottom.Location = new System.Drawing.Point(0, 341);
this.panelBottom.Name = "panelBottom";
this.panelBottom.Size = new System.Drawing.Size(584, 120);
this.panelBottom.TabIndex = 1;
//
// txtIconDimensions
//
this.txtIconDimensions.Location = new System.Drawing.Point(119, 39);
this.txtIconDimensions.Name = "txtIconDimensions";
this.txtIconDimensions.ReadOnly = true;
this.txtIconDimensions.Size = new System.Drawing.Size(100, 23);
this.txtIconDimensions.TabIndex = 10;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 42);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(77, 15);
this.label5.TabIndex = 9;
this.label5.Text = "Dimensions:";
//
// numY
//
this.numY.Location = new System.Drawing.Point(119, 82);
this.numY.Maximum = new decimal(new int[] {
200,
0,
0,
0});
this.numY.Name = "numY";
this.numY.Size = new System.Drawing.Size(60, 23);
this.numY.TabIndex = 8;
//
// numX
//
this.numX.Location = new System.Drawing.Point(119, 68);
this.numX.Maximum = new decimal(new int[] {
200,
0,
0,
0});
this.numX.Name = "numX";
this.numX.Size = new System.Drawing.Size(60, 23);
this.numX.TabIndex = 7;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 84);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(67, 15);
this.label4.TabIndex = 6;
this.label4.Text = "Y Position:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 70);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(67, 15);
this.label3.TabIndex = 5;
this.label3.Text = "X Position:";
//
// txtIconName
//
this.txtIconName.Location = new System.Drawing.Point(119, 10);
this.txtIconName.Name = "txtIconName";
this.txtIconName.ReadOnly = true;
this.txtIconName.Size = new System.Drawing.Size(200, 23);
this.txtIconName.TabIndex = 4;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 13);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(101, 15);
this.label2.TabIndex = 3;
this.label2.Text = "Selected Icon:";
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(497, 85);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 2;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnInsert
//
this.btnInsert.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnInsert.Location = new System.Drawing.Point(416, 85);
this.btnInsert.Name = "btnInsert";
this.btnInsert.Size = new System.Drawing.Size(75, 23);
this.btnInsert.TabIndex = 1;
this.btnInsert.Text = "Insert";
this.btnInsert.UseVisualStyleBackColor = true;
this.btnInsert.Click += new System.EventHandler(this.btnInsert_Click);
//
// lblStatus
//
this.lblStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblStatus.AutoSize = true;
this.lblStatus.Location = new System.Drawing.Point(325, 13);
this.lblStatus.Name = "lblStatus";
this.lblStatus.Size = new System.Drawing.Size(0, 15);
this.lblStatus.TabIndex = 0;
//
// splitContainer
//
this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer.Location = new System.Drawing.Point(0, 40);
this.splitContainer.Name = "splitContainer";
//
// splitContainer.Panel1
//
this.splitContainer.Panel1.Controls.Add(this.lstIcons);
this.splitContainer.Panel1Collapsed = true;
this.splitContainer.Panel1MinSize = 0;
//
// splitContainer.Panel2
//
this.splitContainer.Panel2.Controls.Add(this.flowLayoutPanel);
this.splitContainer.Size = new System.Drawing.Size(584, 301);
this.splitContainer.SplitterDistance = 194;
this.splitContainer.TabIndex = 2;
//
// lstIcons
//
this.lstIcons.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstIcons.FormattingEnabled = true;
this.lstIcons.ItemHeight = 15;
this.lstIcons.Location = new System.Drawing.Point(0, 0);
this.lstIcons.Name = "lstIcons";
this.lstIcons.Size = new System.Drawing.Size(194, 301);
this.lstIcons.TabIndex = 0;
//
// flowLayoutPanel
//
this.flowLayoutPanel.AutoScroll = true;
this.flowLayoutPanel.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.flowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel.Name = "flowLayoutPanel";
this.flowLayoutPanel.Padding = new System.Windows.Forms.Padding(10);
this.flowLayoutPanel.Size = new System.Drawing.Size(584, 301);
this.flowLayoutPanel.TabIndex = 0;
//
// IconBrowser
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 461);
this.Controls.Add(this.splitContainer);
this.Controls.Add(this.panelBottom);
this.Controls.Add(this.panelTop);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(400, 400);
this.Name = "IconBrowser";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Icon Browser";
this.Load += new System.EventHandler(this.IconBrowser_Load);
this.panelTop.ResumeLayout(false);
this.panelTop.PerformLayout();
this.panelBottom.ResumeLayout(false);
this.panelBottom.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numY)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numX)).EndInit();
this.splitContainer.Panel1.ResumeLayout(false);
this.splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
this.splitContainer.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Panel panelTop;
private Button btnBrowse;
private TextBox txtIconDirectory;
private Label label1;
private Panel panelBottom;
private Button btnCancel;
private Button btnInsert;
private Label lblStatus;
private SplitContainer splitContainer;
private ListBox lstIcons;
private FlowLayoutPanel flowLayoutPanel;
private TextBox txtIconName;
private Label label2;
private NumericUpDown numY;
private NumericUpDown numX;
private Label label4;
private Label label3;
private TextBox txtIconDimensions;
private Label label5;
}
}

View File

@@ -0,0 +1,218 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace PCPalConfigurator.UI
{
/// <summary>
/// Dialog for browsing and selecting icons
/// </summary>
public partial class IconBrowser : Form
{
private string _selectedIconPath = "";
private int _selectedIconWidth = 0;
private int _selectedIconHeight = 0;
public string SelectedIconName { get; private set; } = "";
public IconBrowser()
{
InitializeComponent();
}
private void IconBrowser_Load(object? sender, EventArgs e)
{
// Load last used directory from settings if available
string lastDir = Properties.Settings.Default.LastIconDirectory;
if (!string.IsNullOrEmpty(lastDir) && Directory.Exists(lastDir))
{
txtIconDirectory.Text = lastDir;
LoadIconsFromDirectory(lastDir);
}
}
private void btnBrowse_Click(object? sender, EventArgs e)
{
using FolderBrowserDialog dialog = new();
if (!string.IsNullOrEmpty(txtIconDirectory.Text) && Directory.Exists(txtIconDirectory.Text))
{
dialog.InitialDirectory = txtIconDirectory.Text;
}
if (dialog.ShowDialog() == DialogResult.OK)
{
txtIconDirectory.Text = dialog.SelectedPath;
LoadIconsFromDirectory(dialog.SelectedPath);
// Save the directory for next time
Properties.Settings.Default.LastIconDirectory = dialog.SelectedPath;
Properties.Settings.Default.Save();
}
}
private void LoadIconsFromDirectory(string directory)
{
try
{
lstIcons.Items.Clear();
flowLayoutPanel.Controls.Clear();
string[] xbmFiles = Directory.GetFiles(directory, "*.bin");
if (xbmFiles.Length == 0)
{
MessageBox.Show("No XBM icon files found in the selected directory.",
"No Icons Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
foreach (string file in xbmFiles)
{
// Create a button for each icon
Button iconButton = new();
// Parse the XBM file to get dimensions
(int width, int height) = ParseXbmDimensions(file);
string fileName = Path.GetFileNameWithoutExtension(file);
iconButton.Text = $"{fileName} ({width}x{height})";
iconButton.Tag = new IconInfo
{
Path = file,
Name = fileName,
Width = width,
Height = height
};
iconButton.Size = new Size(150, 40);
iconButton.Click += IconButton_Click;
flowLayoutPanel.Controls.Add(iconButton);
}
lblStatus.Text = $"Found {xbmFiles.Length} XBM files";
}
catch (Exception ex)
{
MessageBox.Show($"Error loading icons: {ex.Message}",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private (int width, int height) ParseXbmDimensions(string filePath)
{
int width = 0;
int height = 0;
try
{
// Read the first few lines of the XBM file
using StreamReader reader = new(filePath);
string line;
while ((line = reader.ReadLine()) != null && (width == 0 || height == 0))
{
// Look for width and height definitions in XBM format
if (line.Contains("_width"))
{
width = ExtractNumberFromLine(line);
}
else if (line.Contains("_height"))
{
height = ExtractNumberFromLine(line);
}
}
}
catch
{
// If we can't parse, default to unknown dimensions
width = 0;
height = 0;
}
return (width, height);
}
private int ExtractNumberFromLine(string line)
{
// Extract the numeric value from a line like "#define icon_width 16"
try
{
string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length >= 3)
{
if (int.TryParse(parts[2], out int result))
{
return result;
}
}
}
catch { }
return 0;
}
private void IconButton_Click(object? sender, EventArgs e)
{
if (sender is Button button && button.Tag is IconInfo info)
{
// Highlight the selected button
foreach (Control control in flowLayoutPanel.Controls)
{
if (control is Button btn)
{
btn.BackColor = SystemColors.Control;
}
}
button.BackColor = Color.LightBlue;
// Store the selected icon info
SelectedIconName = info.Name;
_selectedIconPath = info.Path;
_selectedIconWidth = info.Width;
_selectedIconHeight = info.Height;
// Update UI
txtIconName.Text = info.Name;
txtIconDimensions.Text = $"{info.Width} x {info.Height}";
numX.Value = 0;
numY.Value = 0;
}
}
private void btnInsert_Click(object? sender, EventArgs e)
{
if (string.IsNullOrEmpty(SelectedIconName))
{
MessageBox.Show("Please select an icon first.",
"No Icon Selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// Mark as success and close
DialogResult = DialogResult.OK;
Close();
}
private void btnCancel_Click(object? sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
public string GetIconMarkup()
{
if (string.IsNullOrEmpty(SelectedIconName))
return string.Empty;
return $"<icon x={numX.Value} y={numY.Value} name={SelectedIconName} />";
}
// Helper class for icon information
private class IconInfo
{
public string Path { get; set; } = "";
public string Name { get; set; } = "";
public int Width { get; set; }
public int Height { get; set; }
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PCPalConfigurator.Rendering;
namespace PCPalConfigurator.UI
{
/// <summary>
/// Custom panel for displaying OLED preview
/// </summary>
public class OledPreviewPanel : Panel
{
private List<PreviewElement> previewElements = new List<PreviewElement>();
private readonly OledRenderer renderer = new OledRenderer();
public OledPreviewPanel()
{
this.BackColor = Color.Black;
this.BorderStyle = BorderStyle.FixedSingle;
this.DoubleBuffered = true; // Reduces flicker during repaints
}
/// <summary>
/// Updates the preview elements to be rendered
/// </summary>
public void SetPreviewElements(List<PreviewElement> elements)
{
previewElements = elements ?? new List<PreviewElement>();
this.Invalidate(); // Trigger a repaint
}
/// <summary>
/// Handles the paint event to render the OLED preview
/// </summary>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Render the preview elements
renderer.RenderPreview(e.Graphics, previewElements, this.Width, this.Height);
}
}
}