mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-11 08:08:50 -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;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace MCGalaxy.Gui
|
namespace MCGalaxy.Gui
|
||||||
@ -49,6 +50,13 @@ namespace MCGalaxy.Gui
|
|||||||
|
|
||||||
public static class GuiUtils
|
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>
|
/// <summary> Opens the given url in the system's default web browser </summary>
|
||||||
/// <remarks> Catches and logs any unhandled errors </remarks>
|
/// <remarks> Catches and logs any unhandled errors </remarks>
|
||||||
public static void OpenBrowser(string url) {
|
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.Controls.Add(this.btnCancel);
|
||||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
|
this.Load += new System.EventHandler(this.ColorSelector_Load);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
@ -4,8 +4,10 @@ using System.Drawing;
|
|||||||
using System;
|
using System;
|
||||||
using MCGalaxy;
|
using MCGalaxy;
|
||||||
|
|
||||||
namespace MCGalaxy.Gui.Popups {
|
namespace MCGalaxy.Gui.Popups
|
||||||
internal sealed partial class ColorSelector : Form {
|
{
|
||||||
|
internal sealed partial class ColorSelector : Form
|
||||||
|
{
|
||||||
public char ColorCode;
|
public char ColorCode;
|
||||||
|
|
||||||
internal static Color LookupColor(char colCode, out Color textCol) {
|
internal static Color LookupColor(char colCode, out Color textCol) {
|
||||||
@ -46,6 +48,10 @@ namespace MCGalaxy.Gui.Popups {
|
|||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColorSelector_Load(object sender, EventArgs e) {
|
||||||
|
GuiUtils.SetIcon(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const int btnWidth = 130, btnHeight = 40, btnsPerCol = 8;
|
const int btnWidth = 130, btnHeight = 40, btnsPerCol = 8;
|
||||||
int index = 0;
|
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.Controls.Add(this.btnUnload);
|
||||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
|
this.Load += new System.EventHandler(this.CustomCommands_Load);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||||
|
@ -33,6 +33,10 @@ namespace MCGalaxy.Gui.Popups {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomCommands_Load(object sender, EventArgs e) {
|
||||||
|
GuiUtils.SetIcon(this);
|
||||||
|
}
|
||||||
|
|
||||||
void CreateCommand(ICompiler engine) {
|
void CreateCommand(ICompiler engine) {
|
||||||
string cmdName = txtCmdName.Text.Trim();
|
string cmdName = txtCmdName.Text.Trim();
|
||||||
if (cmdName.Length == 0) {
|
if (cmdName.Length == 0) {
|
||||||
|
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.Controls.Add(this.cmbList);
|
||||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
|
this.Load += new System.EventHandler(this.EditText_Load);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Name = "EditText";
|
this.Name = "EditText";
|
||||||
|
@ -20,8 +20,10 @@ using System.IO;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MCGalaxy.Util;
|
using MCGalaxy.Util;
|
||||||
|
|
||||||
namespace MCGalaxy.Gui.Popups {
|
namespace MCGalaxy.Gui.Popups
|
||||||
public partial class EditText : Form {
|
{
|
||||||
|
public partial class EditText : Form
|
||||||
|
{
|
||||||
TextFile curFile;
|
TextFile curFile;
|
||||||
|
|
||||||
public EditText() {
|
public EditText() {
|
||||||
@ -32,6 +34,10 @@ namespace MCGalaxy.Gui.Popups {
|
|||||||
cmbList.Text = "Select file..";
|
cmbList.Text = "Select file..";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditText_Load(object sender, EventArgs e) {
|
||||||
|
GuiUtils.SetIcon(this);
|
||||||
|
}
|
||||||
|
|
||||||
void cmbList_SelectedIndexChanged(object sender, EventArgs e) {
|
void cmbList_SelectedIndexChanged(object sender, EventArgs e) {
|
||||||
if (cmbList.SelectedIndex == -1) return;
|
if (cmbList.SelectedIndex == -1) return;
|
||||||
TrySaveChanges();
|
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.linkManually);
|
||||||
this.Controls.Add(this.linkHelpForward);
|
this.Controls.Add(this.linkHelpForward);
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
|
this.Load += new System.EventHandler(this.PortTools_Load);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Name = "PortTools";
|
this.Name = "PortTools";
|
||||||
|
@ -23,8 +23,10 @@ using System.Net.Sockets;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MCGalaxy.Core;
|
using MCGalaxy.Core;
|
||||||
|
|
||||||
namespace MCGalaxy.Gui.Popups {
|
namespace MCGalaxy.Gui.Popups
|
||||||
public partial class PortTools : Form {
|
{
|
||||||
|
public partial class PortTools : Form
|
||||||
|
{
|
||||||
|
|
||||||
readonly BackgroundWorker worker;
|
readonly BackgroundWorker worker;
|
||||||
int port;
|
int port;
|
||||||
@ -39,6 +41,10 @@ namespace MCGalaxy.Gui.Popups {
|
|||||||
btnForward.Text = "Forward " + port;
|
btnForward.Text = "Forward " + port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PortTools_Load(object sender, EventArgs e) {
|
||||||
|
GuiUtils.SetIcon(this);
|
||||||
|
}
|
||||||
|
|
||||||
void linkManually_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
void linkManually_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
||||||
GuiUtils.OpenBrowser("https://www.canyouseeme.org/");
|
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.Controls.Add(this.btnCancel);
|
||||||
this.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
|
this.Load += new System.EventHandler(this.TokenSelector_Load);
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
@ -3,8 +3,10 @@ using System;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace MCGalaxy.Gui.Popups {
|
namespace MCGalaxy.Gui.Popups
|
||||||
internal sealed partial class TokenSelector : Form {
|
{
|
||||||
|
internal sealed partial class TokenSelector : Form
|
||||||
|
{
|
||||||
public string Token;
|
public string Token;
|
||||||
|
|
||||||
public TokenSelector(string title) {
|
public TokenSelector(string title) {
|
||||||
@ -23,6 +25,10 @@ namespace MCGalaxy.Gui.Popups {
|
|||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TokenSelector_Load(object sender, EventArgs e) {
|
||||||
|
GuiUtils.SetIcon(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const int btnWidth = 110, btnHeight = 40, btnsPerCol = 9;
|
const int btnWidth = 110, btnHeight = 40, btnsPerCol = 9;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -20,10 +20,11 @@ using MCGalaxy.Eco;
|
|||||||
using MCGalaxy.Events.GameEvents;
|
using MCGalaxy.Events.GameEvents;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
|
|
||||||
namespace MCGalaxy.Gui {
|
namespace MCGalaxy.Gui
|
||||||
public partial class PropertyWindow : Form {
|
{
|
||||||
|
public partial class PropertyWindow : Form
|
||||||
|
{
|
||||||
ZombieProperties zsSettings = new ZombieProperties();
|
ZombieProperties zsSettings = new ZombieProperties();
|
||||||
internal Icon _icon;
|
|
||||||
|
|
||||||
public PropertyWindow() {
|
public PropertyWindow() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -35,7 +36,8 @@ namespace MCGalaxy.Gui {
|
|||||||
|
|
||||||
void PropertyWindow_Load(object sender, EventArgs e) {
|
void PropertyWindow_Load(object sender, EventArgs e) {
|
||||||
// try to use same icon as main window
|
// 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);
|
OnMapsChangedEvent.Register(HandleMapsChanged, Priority.Low);
|
||||||
OnStateChangedEvent.Register(HandleStateChanged, Priority.Low);
|
OnStateChangedEvent.Register(HandleStateChanged, Priority.Low);
|
||||||
|
@ -102,6 +102,7 @@ Trying to mix two versions is unsupported - you may experience issues";
|
|||||||
try {
|
try {
|
||||||
ComponentResourceManager resources = new ComponentResourceManager(typeof(Window));
|
ComponentResourceManager resources = new ComponentResourceManager(typeof(Window));
|
||||||
Icon = (Icon)(resources.GetObject("$this.Icon"));
|
Icon = (Icon)(resources.GetObject("$this.Icon"));
|
||||||
|
GuiUtils.WinIcon = Icon;
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +322,6 @@ Trying to mix two versions is unsupported - you may experience issues";
|
|||||||
void btnProperties_Click(object sender, EventArgs e) {
|
void btnProperties_Click(object sender, EventArgs e) {
|
||||||
if (!hasPropsForm) {
|
if (!hasPropsForm) {
|
||||||
propsForm = new PropertyWindow();
|
propsForm = new PropertyWindow();
|
||||||
// just doing 'propForms.Icon = Icon;' doesn't show on Mono
|
|
||||||
try { propsForm._icon = Icon; } catch { }
|
|
||||||
hasPropsForm = true;
|
hasPropsForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user