Make Mir3D Launcher panel movable on desktop

mir2pion

TL;DR
Veteran
Feb 21, 2013
3,202
535
175
I found that it cannot be simply set in panel properties but needs to be coded. Currently the Launcher is stuck in the middle of desktop.

I followed an example on YT which shows how you write code for mouseDown, mouseMove and mouseUp but VS doesn't like what I did and I suspect I need to move the code up to the very start, into the public MainForm() method as I marked in this image by a red rectangle.

1714897519059.png

When I selected mouseDown in the Events, VS entered the code for it smack at the bottom of the code for the Launcher and that put it alongside that public MainForm(), into the public partial class MainForm : Form

This is the code and I think I need to define mouseX and mouseY somehow... I thought that would be done by that 'int = mouseX = 0... line but evidently it is not.
1714899834321.png
So, how I make mouseX to exist in the current context? Same for mouseY...
1714898196656.png

It didn't put out the error underlines for the guy in the tutorial but of course he wrote the code in 'different place', in that method that I have at the very top of the code where I put the red rectangle.

Also his InitializeComponent(); is inside that public Form1() but in the Launcher code, that InitializeComponent is left 'as is'
1714898699877.png

I suppose I could move the new code into that top method but don't really believe that's what needs to be done.

C#:
        int = mouseX = 0, mouseY = 0;
        bool mouseDown;

        private void MainTab_MouseDown(object sender, MouseEventArgs e)
        {
            mouseDown = true;
        }

        private void MainTab_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                mouseX = MousePosition.X - 200;
                mouseY = MousePosition.Y - 20;

                this.SetDesktopLocation(mouseX, mouseY);
            }
        }

        private void MainTab_MouseUp(object sender, MouseEventArgs e)
        {
            mouseDown = false;
        }
    }
}
 
Last edited:

FloppyQ

Loyal Member
Loyal Member
May 12, 2020
110
2
50
40
So, how I make mouseX to exist in the current context? Same for mouseY...

C#:
        //int = mouseX = 0, mouseY = 0;
        bool mouseDown;

        private void MainTab_MouseDown(object sender, MouseEventArgs e)
        {
            mouseDown = true;
        }

        private void MainTab_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                int mouseX = MousePosition.X - 200;
                int mouseY = MousePosition.Y - 20;

                this.SetDesktopLocation(mouseX, mouseY);
            }
        }

        private void MainTab_MouseUp(object sender, MouseEventArgs e)
        {
            mouseDown = false;
        }
    }
}
 

mir2pion

TL;DR
Veteran
Feb 21, 2013
3,202
535
175
Completely new approach that works, only need to iron out Launcher panel jump to the left when start dragging.
It has to do with those numeric values. I tried increasing and decreasing them, even removing but the panel keeps jumping to the left when the mouse begins to drag it. Can drag it but the jump is a blemish. Why this mouse repositioning in the first place to begin with?
I think it is to do with the added panel size.
1714939429676.png
Post automatically merged:

Setting 'mousey -20' in the bottom SetDesktopLocation line fixed the jump up in the y direction, but no mater what I do with the mousex value, subtracting or adding to it, it makes no difference, the panel keeps jumping to the left when you start dragging it.

1714944194990.png

Clicking on the panel header at its right end next to the panel closing button (x) and starting to drag it, it jumps to the left by about half width of the panel. If start dragging the header at its left side, it jumps to the left twice the distance.
Somebody must have some idea??
 

Attachments

  • 1714925696006.png
    1714925696006.png
    171.3 KB · Views: 15
  • 1714932445086.png
    1714932445086.png
    210.3 KB · Views: 16
  • 1714932603806.png
    1714932603806.png
    6.1 KB · Views: 16
  • 1714938425261.png
    1714938425261.png
    148.7 KB · Views: 3
Last edited:

FloppyQ

Loyal Member
Loyal Member
May 12, 2020
110
2
50
40
Probably because the panels mouse event MousePosition.X and Y values have nothing to do with the desktop mouse location. They will be relative only to the panel

1715023877766.png

Hope that helps.
Post automatically merged:

C#:
        bool mouseDown;
        Point mouseOffset;
        private void MainTab_MouseDown(object sender, MouseEventArgs e)

        {
            mouseDown = true;
            mouseOffset = new Point(e.X, e.Y);
        }
        private void MainTab_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                int cursorX = System.Windows.Forms.Cursor.Position.X;
                int cursorY = System.Windows.Forms.Cursor.Position.Y;
                this.SetDesktopLocation(cursorX - mouseOffset.X, cursorY - mouseOffset.Y);
            }
        }
        private void MainTab_MouseUp(object sender, MouseEventArgs e)
        {
            mouseDown = false;
        }
 
Last edited:
  • Like
Reactions: Jev

mir2pion

TL;DR
Veteran
Feb 21, 2013
3,202
535
175
Your code refers to the MainTab which the biggest inclosing panel in the Launcher designer display (selected in this image).

1715199439367.png
I pasted your code straight in (commented out my previous code) and while it compiled, the Launcher panel would not budge, no mater where I grabbed it.

So I remade my previous 'panel1' placed over the Launcher header and renamed it 'header' (the selected panel in this image)
1715199347473.png
Then I copied into my previous code relevant parts from your code above here. But again, the Launcher panel won't budge.

I belive that empty 'private void header_Paint' is not needed, checked without it and it didn't make a difference as I thought.

C#:
        bool mousedown;
        Point mouseOffset;

        private void header_Paint(object sender, PaintEventArgs e)
        {

        }

        private void header_MouseDown(object sender, MouseEventArgs e)
        {
            mousedown = true;
            mouseOffset = new Point(e.X, e.Y);
        }

        private void header_MouseMove(object sender, MouseEventArgs e)
        {
            if (mousedown)
            {
                int cursorX = System.Windows.Forms.Cursor.Position.X;
                int cursorY = System.Windows.Forms.Cursor.Position.Y;
                this.SetDesktopLocation(cursorX - mouseOffset.X, cursorY - mouseOffset.Y);
            }

        }

        private void header_MouseUp(object sender, MouseEventArgs e)
        {
            mousedown = false;
        }
 

Jev

ғᴜᴄᴋɪɴɢ ᴊᴇᴠ
Staff member
Moderator
May 16, 2017
3,563
21
2,039
270
Job Centre Plus
Your code refers to the MainTab which the biggest inclosing panel in the Launcher designer display (selected in this image).

View attachment 34661
I pasted your code straight in (commented out my previous code) and while it compiled, the Launcher panel would not budge, no mater where I grabbed it.

So I remade my previous 'panel1' placed over the Launcher header and renamed it 'header' (the selected panel in this image)
View attachment 34660
Then I copied into my previous code relevant parts from your code above here. But again, the Launcher panel won't budge.

I belive that empty 'private void header_Paint' is not needed, checked without it and it didn't make a difference as I thought.

C#:
        bool mousedown;
        Point mouseOffset;

        private void header_Paint(object sender, PaintEventArgs e)
        {

        }

        private void header_MouseDown(object sender, MouseEventArgs e)
        {
            mousedown = true;
            mouseOffset = new Point(e.X, e.Y);
        }

        private void header_MouseMove(object sender, MouseEventArgs e)
        {
            if (mousedown)
            {
                int cursorX = System.Windows.Forms.Cursor.Position.X;
                int cursorY = System.Windows.Forms.Cursor.Position.Y;
                this.SetDesktopLocation(cursorX - mouseOffset.X, cursorY - mouseOffset.Y);
            }

        }

        private void header_MouseUp(object sender, MouseEventArgs e)
        {
            mousedown = false;
        }

PR 26

MainTab is the biggest panel and is front facing so I just used mouse events, Also did it for AccountLoginTab as it overlapped MainTab slightly on the top and bottom. Better safe then sorry.

C#:
private void AccountLoginTab_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // Capture the offset between the mouse cursor and the form's location
                offset = new Point(e.X, e.Y);
            }
        }

        private void AccountLoginTab_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // Calculate the new location of the form based on the offset
                Point newLocation = this.PointToScreen(new Point(e.X, e.Y));
                newLocation.Offset(-offset.X, -offset.Y);

                // Set the new location of the form
                this.Location = newLocation;
            }
        }

        private void AccountLoginTab_MouseUp(object sender, MouseEventArgs e)
        {
            // Reset the offset when the mouse button is released
            offset = Point.Empty;
        }

        private void MainTab_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // Capture the offset between the mouse cursor and the form's location
                offset = new Point(e.X, e.Y);
            }
        }

        private void MainTab_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // Calculate the new location of the form based on the offset
                Point newLocation = this.PointToScreen(new Point(e.X, e.Y));
                newLocation.Offset(-offset.X, -offset.Y);

                // Set the new location of the form
                this.Location = newLocation;
            }
        }

        private void MainTab_MouseUp(object sender, MouseEventArgs e)
        {
            // Reset the offset when the mouse button is released
            offset = Point.Empty;
        }
 

Damian

LOMCN Developer
Developer
Ravagers
Game Master
Jun 13, 2003
1,113
107
310
Only just seen this post, would be faster to post the issue to the bug tracker
 

mir2pion

TL;DR
Veteran
Feb 21, 2013
3,202
535
175
Its not a bug but it has been bugging me from day one. I suppose it is not an issue if you log in to play but translating the client meant logging in tons of times for a whole last year or two and this launcher is sticking right in the middle of your screen.
I thought how dumb to make it like this until I found it wasn't an oversight, it requires extra effort coding it in because winforms are so primitive, they don't provide for dragging panel around, such a basic thing, as if anybody would want to make a program window that can't be moved around.

I was hoping someone would step in if they saw my bumbling efforts but was losing hopes of that happening.

MainTab is the biggest panel and is front facing so I just used mouse events, Also did it for AccountLoginTab as it overlapped MainTab slightly on the top and bottom. Better safe then sorry.

I am lost in those panels, why should there be two like that, nested, why not just one main one and inside smaller panels for buttons, the pic, etc.
Since mouse grabbing should work only on the panel 'title bar', I made a new panel to cover just that area and tied mouse moves to it. I figured if I made it for the MainTab, then you could grab the panel almost anywhere to move it, which is very much non-standard.

I'll look at your code to maybe learn something from it but why don't you just push it to GH repo then.
 

Jev

ғᴜᴄᴋɪɴɢ ᴊᴇᴠ
Staff member
Moderator
May 16, 2017
3,563
21
2,039
270
Job Centre Plus
I'll look at your code to maybe learn something from it but why don't you just push it to GH repo then.
I did push it to the HC GitHub.
The reason they were nested was because it’s using a tab control that switches depending on what you’ve pressed.
 
  • Like
Reactions: mir2pion

mir2pion

TL;DR
Veteran
Feb 21, 2013
3,202
535
175
Ahh, I get it. It switches from login into server selection interface. So if you made the first MainTab movable, it wouldn't work when in the server selection tab.

Does that ConfigButton on line 615 belong to that mouse panel dragging and if not, what is it?

Those lines 217-220 & 354, is that elimination of hanging spaces, in the case of line 354 the whole bunch of them?
I recall now, when I opened the code, it asked me about correcting CRLF (line ending thing), is that what caused these hanging spaces deletions?
1715263901240.png

Edit: opening the code locally, configForm looks like a new addition, putting that question mark to use, finally :cool: nothing to do with that mouse panel drag.
1715267477886.png 1715267760730.png
 
Last edited:

Jev

ғᴜᴄᴋɪɴɢ ᴊᴇᴠ
Staff member
Moderator
May 16, 2017
3,563
21
2,039
270
Job Centre Plus
Ahh, I get it. It switches from login into server selection interface. So if you made the first MainTab movable, it wouldn't work when in the server selection tab.

Does that ConfigButton on line 615 belong to that mouse panel dragging and if not, what is it?

Those lines 217-220 & 354, is that elimination of hanging spaces, in the case of line 354 the whole bunch of them?
I recall now, when I opened the code, it asked me about correcting CRLF (line ending thing), is that what caused these hanging spaces deletions?
View attachment 34683

Edit: opening the code locally, configForm looks like a new addition, putting that question mark to use, finally :cool: nothing to do with that mouse panel drag.
View attachment 34687 View attachment 34688
Yea I added the config form yesterday, it’s not done as I mentioned in the PR but it’ll be useless in the coming days as I’ve been working on reskinning the launcher to match official.

Preview below.

and yes it's moveable :kekw:
 
  • Wow
Reactions: mir2pion

Martyn

Smir.co.uk
Staff member
Administrator
Mar 24, 2003
3,826
2
856
400
Kent - UK
Yea I added the config form yesterday, it’s not done as I mentioned in the PR but it’ll be useless in the coming days as I’ve been working on reskinning the launcher to match official.

Preview below.

and yes it's moveable :kekw:
is that how the image is or a bad attempt to rip it? :P
 

Jev

ғᴜᴄᴋɪɴɢ ᴊᴇᴠ
Staff member
Moderator
May 16, 2017
3,563
21
2,039
270
Job Centre Plus
is that how the image is or a bad attempt to rip it? :P
It's taken straight from the main launcher, Not sure why some of the transparency has gone weird. I'm just going to get everything in for now and then I can mess around with swapping the image.
 
  • Like
Reactions: Martyn