mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-08 22:59:29 -04:00
GUI: Fix icon not showing in popup dialogs on Mono
This took a long time to figure out because 1) for testing purposes I set Icon before the window handle had been created 2) When the window handle was later created, mono would not actually apply the custom icon since the border style is FixedDialog (see CreateHandle in Form.cs) 3) I later set Icon again in multiple other places. However, this was essentially a noop because Mono checked if the new icon was the same as the same previously assigned icon and do nothing in that case. However, the assumption in step 3) was incorrect because the previously assigned icon had not actually been applied to the window. Unfortunately this meant the correct Icon never showed at all. So the correct solution to this is to only assign Icon once in the Load event of forms. I spent way too much time on this
This commit is contained in:
parent
8ee32ba780
commit
ada34d4c32
@ -17,6 +17,7 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MCGalaxy.Gui
|
||||
@ -49,6 +50,13 @@ namespace MCGalaxy.Gui
|
||||
|
||||
public static class GuiUtils
|
||||
{
|
||||
/// <summary> MCGalaxy window icon (shared) </summary>
|
||||
public static Icon WinIcon;
|
||||
|
||||
public static void SetIcon(Form form) {
|
||||
try { form.Icon = WinIcon; } catch { }
|
||||
}
|
||||
|
||||
/// <summary> Opens the given url in the system's default web browser </summary>
|
||||
/// <remarks> Catches and logs any unhandled errors </remarks>
|
||||
public static void OpenBrowser(string url) {
|
||||
|
1
GUI/Popups/ColorSelector.Designer.cs
generated
1
GUI/Popups/ColorSelector.Designer.cs
generated
@ -29,6 +29,7 @@
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Load += new System.EventHandler(this.ColorSelector_Load);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
|
@ -4,8 +4,10 @@ using System.Drawing;
|
||||
using System;
|
||||
using MCGalaxy;
|
||||
|
||||
namespace MCGalaxy.Gui.Popups {
|
||||
internal sealed partial class ColorSelector : Form {
|
||||
namespace MCGalaxy.Gui.Popups
|
||||
{
|
||||
internal sealed partial class ColorSelector : Form
|
||||
{
|
||||
public char ColorCode;
|
||||
|
||||
internal static Color LookupColor(char colCode, out Color textCol) {
|
||||
@ -46,6 +48,10 @@ namespace MCGalaxy.Gui.Popups {
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
void ColorSelector_Load(object sender, EventArgs e) {
|
||||
GuiUtils.SetIcon(this);
|
||||
}
|
||||
|
||||
|
||||
const int btnWidth = 130, btnHeight = 40, btnsPerCol = 8;
|
||||
int index = 0;
|
||||
|
1
GUI/Popups/CustomCommands.Designer.cs
generated
1
GUI/Popups/CustomCommands.Designer.cs
generated
@ -150,6 +150,7 @@
|
||||
this.Controls.Add(this.btnUnload);
|
||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Load += new System.EventHandler(this.CustomCommands_Load);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
|
@ -32,6 +32,10 @@ namespace MCGalaxy.Gui.Popups {
|
||||
if (!Command.IsCore(cmd)) lstCommands.Items.Add(cmd.name);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomCommands_Load(object sender, EventArgs e) {
|
||||
GuiUtils.SetIcon(this);
|
||||
}
|
||||
|
||||
void CreateCommand(ICompiler engine) {
|
||||
string cmdName = txtCmdName.Text.Trim();
|
||||
|
1
GUI/Popups/EditText.Designer.cs
generated
1
GUI/Popups/EditText.Designer.cs
generated
@ -97,6 +97,7 @@ namespace MCGalaxy.Gui.Popups
|
||||
this.Controls.Add(this.cmbList);
|
||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Load += new System.EventHandler(this.EditText_Load);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "EditText";
|
||||
|
@ -20,8 +20,10 @@ using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using MCGalaxy.Util;
|
||||
|
||||
namespace MCGalaxy.Gui.Popups {
|
||||
public partial class EditText : Form {
|
||||
namespace MCGalaxy.Gui.Popups
|
||||
{
|
||||
public partial class EditText : Form
|
||||
{
|
||||
TextFile curFile;
|
||||
|
||||
public EditText() {
|
||||
@ -32,6 +34,10 @@ namespace MCGalaxy.Gui.Popups {
|
||||
cmbList.Text = "Select file..";
|
||||
}
|
||||
|
||||
void EditText_Load(object sender, EventArgs e) {
|
||||
GuiUtils.SetIcon(this);
|
||||
}
|
||||
|
||||
void cmbList_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
if (cmbList.SelectedIndex == -1) return;
|
||||
TrySaveChanges();
|
||||
|
1
GUI/Popups/PortTools.Designer.cs
generated
1
GUI/Popups/PortTools.Designer.cs
generated
@ -121,6 +121,7 @@ namespace MCGalaxy.Gui.Popups {
|
||||
this.Controls.Add(this.linkManually);
|
||||
this.Controls.Add(this.linkHelpForward);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Load += new System.EventHandler(this.PortTools_Load);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "PortTools";
|
||||
|
@ -23,8 +23,10 @@ using System.Net.Sockets;
|
||||
using System.Windows.Forms;
|
||||
using MCGalaxy.Core;
|
||||
|
||||
namespace MCGalaxy.Gui.Popups {
|
||||
public partial class PortTools : Form {
|
||||
namespace MCGalaxy.Gui.Popups
|
||||
{
|
||||
public partial class PortTools : Form
|
||||
{
|
||||
|
||||
readonly BackgroundWorker worker;
|
||||
int port;
|
||||
@ -38,6 +40,10 @@ namespace MCGalaxy.Gui.Popups {
|
||||
this.port = port;
|
||||
btnForward.Text = "Forward " + port;
|
||||
}
|
||||
|
||||
void PortTools_Load(object sender, EventArgs e) {
|
||||
GuiUtils.SetIcon(this);
|
||||
}
|
||||
|
||||
void linkManually_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
||||
GuiUtils.OpenBrowser("https://www.canyouseeme.org/");
|
||||
|
1
GUI/Popups/TokenSelector.Designer.cs
generated
1
GUI/Popups/TokenSelector.Designer.cs
generated
@ -31,6 +31,7 @@
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Load += new System.EventHandler(this.TokenSelector_Load);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
|
@ -3,8 +3,10 @@ using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MCGalaxy.Gui.Popups {
|
||||
internal sealed partial class TokenSelector : Form {
|
||||
namespace MCGalaxy.Gui.Popups
|
||||
{
|
||||
internal sealed partial class TokenSelector : Form
|
||||
{
|
||||
public string Token;
|
||||
|
||||
public TokenSelector(string title) {
|
||||
@ -23,6 +25,10 @@ namespace MCGalaxy.Gui.Popups {
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
void TokenSelector_Load(object sender, EventArgs e) {
|
||||
GuiUtils.SetIcon(this);
|
||||
}
|
||||
|
||||
|
||||
const int btnWidth = 110, btnHeight = 40, btnsPerCol = 9;
|
||||
int index = 0;
|
||||
|
@ -125,7 +125,7 @@ namespace MCGalaxy.Gui {
|
||||
|
||||
void cmd_btnCustom_Click(object sender, EventArgs e) {
|
||||
using (CustomCommands form = new CustomCommands()) {
|
||||
form.ShowDialog();
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,11 @@ using MCGalaxy.Eco;
|
||||
using MCGalaxy.Events.GameEvents;
|
||||
using MCGalaxy.Games;
|
||||
|
||||
namespace MCGalaxy.Gui {
|
||||
public partial class PropertyWindow : Form {
|
||||
namespace MCGalaxy.Gui
|
||||
{
|
||||
public partial class PropertyWindow : Form
|
||||
{
|
||||
ZombieProperties zsSettings = new ZombieProperties();
|
||||
internal Icon _icon;
|
||||
|
||||
public PropertyWindow() {
|
||||
InitializeComponent();
|
||||
@ -35,7 +36,8 @@ namespace MCGalaxy.Gui {
|
||||
|
||||
void PropertyWindow_Load(object sender, EventArgs e) {
|
||||
// try to use same icon as main window
|
||||
try { Icon = _icon; } catch { }
|
||||
// must be done in OnLoad, otherwise icon doesn't show on Mono
|
||||
GuiUtils.SetIcon(this);
|
||||
|
||||
OnMapsChangedEvent.Register(HandleMapsChanged, Priority.Low);
|
||||
OnStateChangedEvent.Register(HandleStateChanged, Priority.Low);
|
||||
|
@ -102,6 +102,7 @@ Trying to mix two versions is unsupported - you may experience issues";
|
||||
try {
|
||||
ComponentResourceManager resources = new ComponentResourceManager(typeof(Window));
|
||||
Icon = (Icon)(resources.GetObject("$this.Icon"));
|
||||
GuiUtils.WinIcon = Icon;
|
||||
} catch { }
|
||||
}
|
||||
|
||||
@ -320,9 +321,7 @@ Trying to mix two versions is unsupported - you may experience issues";
|
||||
|
||||
void btnProperties_Click(object sender, EventArgs e) {
|
||||
if (!hasPropsForm) {
|
||||
propsForm = new PropertyWindow();
|
||||
// just doing 'propForms.Icon = Icon;' doesn't show on Mono
|
||||
try { propsForm._icon = Icon; } catch { }
|
||||
propsForm = new PropertyWindow();
|
||||
hasPropsForm = true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user