Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Syncing nuklear form's position with GLFW's window position ? #658

Closed
malvinn13 opened this issue Apr 5, 2018 · 9 comments
Closed

Syncing nuklear form's position with GLFW's window position ? #658

malvinn13 opened this issue Apr 5, 2018 · 9 comments

Comments

@malvinn13
Copy link

malvinn13 commented Apr 5, 2018

Hey, i want to make a window that is borderless(From GLFW) and i want to make it movable.
It looks like this:
image
I want to make it movable so i tried to override the nuklear.h code but didn't worked. Can you help me with this ?
The Nuklear Form' width and height are the same as GLFW's.
EDIT: i want to handle the X button, the window is closing but instantly reopens when i press the button, dont rlly know how to work with it, can you help me with this too ?

@vurtun
Copy link
Owner

vurtun commented Apr 5, 2018

Hey @malvinro,
if I understand you correctly you want to span a nuklear window completely over the OS window and use nuklears window header as os window header.

What I would propose is to use the OS window header and a headerless nuklear window. The problem with using nuklear for OS window movement is that the OS renderer is always faster than nuklear in drawing (The kernel has more information). So while possible to do what you want it causes glitches.

So the best cause of action would be to use the OS window decoration for maximum smoothness for movement.

EDIT: i want to handle the X button, the window is closing but instantly reopens when i press the button, dont rlly know how to work with it, can you help me with this too ?

Nuklear does not close the window. It only marks it as closed to be polled if closed. So you have to detect in your code that it was closed and not call the window anymore. This can be easily implemented by having a boolean check:

static int win_unresolved_visible = true;
if (win_unresolved_visible) {
    if (nk_begin(..., "unresolved",....)) {
        /* ... */
    }
    nk_end(...);
}
win_unresolved_visible = nk_window_is_closed(ctx, "unresolved") ? false : true;

or if you want to close the application something like this:

if (nk_begin(..., "unresolved",....)) {
    /* ... */
}
nk_end(...);

if (nk_window_is_closed(ctx, "unresolved")) {
    exit(1);
}

EDIT:
Also if you mean how to span nuklears window over the OS window do this:

if (nk_begin(..., "unresolved", ....)) {
    nk_window_set_size(ctx, "unresolved", nk_vec2(glfw.width, glfw.height));
}
nk_end(...);

@malvinn13
Copy link
Author

Thw win_unresolved_visible variable is never turning false, that's my code:
image
The OS header looks like shit, i want to overwrite your code, and instead of changing the nuklear form's position i would change the os window position, that should not glitch. It's glitching now bc NK_MOVABLE move the nuklear window, if the calculation of the new position would write the OS Window Position than it should do the work.

@malvinn13
Copy link
Author

This is happening, can't get it closed.
https://i.gyazo.com/b72c7c0013cca9152bbc3294e8875754.gif
image

@vurtun
Copy link
Owner

vurtun commented Apr 5, 2018

Oops you are correct it should be:

if (nk_window_is_hidden(ctx, "unresolved"))
    exit(1);

The 'x' only hides the specified window. While nk_window_close actually closes the window which can be checked with nk_window_is_closed.

@malvinn13
Copy link
Author

malvinn13 commented Apr 6, 2018

Yeah, now it's working.
I m trying to move the window myself but i can't find the the mouse position on the header, could you help me with this ?
I found the Mouse X, Y, the window X,Y, but when i need to move it i need to set the window position to the Mouse X,Y Position - some value for which i cant find a formula for.

EDIT:
I've changed the taskbar icon but the icon from here wont change, do you have any idea about how i could change it ?
image

@malvinn13
Copy link
Author

malvinn13 commented Apr 6, 2018

Found out how to make it movable, if someone wants to do it too simply create a variable (mine's a point named distFromWinToMouse) then insert this into your while function.

if ((GetKeyState(VK_LBUTTON) & 0x100) != 0) {
	POINT p;
	int curX, curY;
	if (GetCursorPos(&p)){
		glfwGetWindowPos(win, &curX, &curY);
		if (iMPressed && p.x < curX + WINDOW_WIDTH + 500 && p.x > curX - 500 && p.y < curY + ctx->active->layout->header_height + 500 && p.y > curY - 500)
		 glfwSetWindowPos(win, p.x - distFromWinToMouse.x, p.y - distFromWinToMouse.y);
		else {
		if (p.x < curX + WINDOW_WIDTH && p.x > curX &&
		p.y < curY + ctx->active->layout->header_height && p.y > curY) {
		distFromWinToMouse.x = p.x - curX;
		distFromWinToMouse.y = p.y - curY;
		glfwSetWindowPos(win, p.x - distFromWinToMouse.x, p.y - distFromWinToMouse.y);
		iMPressed = true;
		}		
	}		
}
}

Now i just want to change the icon from the taskbar, when i click right my program.

@vurtun
Copy link
Owner

vurtun commented Apr 8, 2018

I think I am a little lost at this point. Can this issue be marked fixed?

@malvinn13
Copy link
Author

Nah, if you could help me, how i can change this icon:
image
And how can i set the icon to the app to be like an embed icon. If i run the app from a folder it wont show the icon :(

@dumblob
Copy link
Contributor

dumblob commented Apr 10, 2018

The icon question is out of the Nuklear scope. But I would start e.g. with https://msdn.microsoft.com/en-us/library/windows/desktop/ms648051(v=vs.85).aspx or similar (just google it - this was right the second match I got).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants