Project updates for OLED

This commit is contained in:
NinjaPug
2025-04-13 14:06:05 -04:00
parent 7622c3972a
commit 1cf596b379
13 changed files with 1781 additions and 34 deletions

View File

@@ -0,0 +1,317 @@
namespace PCPalConfigurator
{
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,215 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace PCPalConfigurator
{
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>