[Resolved somehow] How to know if the window has got focus?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Neo
Just popping in
Just popping in
Posts: 13
Joined: Sat Mar 30, 2013 16:49

[Resolved somehow] How to know if the window has got focus?

Postby Neo » Sat Nov 19, 2016 00:24

Hello,
I'm now working on my game. And currently i'm focusing on game-built-in map editor.
Now I want to implement "delete" function, that allow users delete their objects from scene when pressing "delete" button.

To achieve that, a event handler is attached to editor root window to deal with the key event.

The problems is, this deleting operation should be blocked when user is editing properties, for example, when a user is deleting
the numbers in position attribute, he won't see his object disappeared instead.


I have tried isActive(), isCapturedByThis(), isCapturedByChild(), they all didn't work.
So now I'm going to try hasInputFocus() of Editbox. But I have to get all editbox from root window and inspect them.
How can I do this, instead of add those editbox one by one manually?
Or is there any other solutions?
Thank you.

And to those who are curious about my work, here is the github link:
https://github.com/DarkAngelZT/NeoGameF ... ee/tankwar

--update---
I tried just investigate one of the editbox, it seems the input focus is not gone when I click out side of the editbox :(
So now the question is how to know if a window is getting focus?
Last edited by Neo on Tue Nov 22, 2016 23:18, edited 1 time in total.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: How to know if the window has got focus?

Postby Ident » Sat Nov 19, 2016 10:57

isActive() is the right function

it seems the input focus is not gone when I click out side of the editbox :(

Can you still type into it? Then isActive() should return true. It is expected behaviour.

If you do not want this to happen, then whatever you clicked on needs to be able to receive focus.
CrazyEddie: "I don't like GUIs"

Neo
Just popping in
Just popping in
Posts: 13
Joined: Sat Mar 30, 2013 16:49

Re: How to know if the window has got focus?

Postby Neo » Sat Nov 19, 2016 23:46

Yes I can still type.
The editbox is attached to a root window. The root window is just a default empty window act as a ui sheet,
The editbox will only become unable to type in when I click on another frame window or widget, but click on the root window area makes no sense

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: How to know if the window has got focus?

Postby Ident » Sun Nov 20, 2016 11:46

Neo wrote:The editbox will only become unable to type in when I click on another frame window or widget, but click on the root window area makes no sense

Can you try, just for testing, to make your root window a FrameWindow instead of a Defaultwindow to see if the behaviour changes?

The point is that the root window needs to be able to get focus.

If the above test does not work then I suggest the following:
Subscribe to the root window's event handler for mouse click, inside it call the focus() function of your root window and then return false. Havent tested this yet though, but I looked into the code and that should do the trick.
CrazyEddie: "I don't like GUIs"

Neo
Just popping in
Just popping in
Posts: 13
Joined: Sat Mar 30, 2013 16:49

Re: How to know if the window has got focus?

Postby Neo » Sun Nov 20, 2016 20:44

Ident wrote:The point is that the root window needs to be able to get focus.

Yes it can get focus when root window is a frame window. The problem is the result of isActive() is always true, no matter the root window is default window or frame window, even if I am typing in the editbox.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: How to know if the window has got focus?

Postby Ident » Sun Nov 20, 2016 22:42

Ok I think I misunderstood you at first.

So what you want in the end is a way to say isAnyEditboxBeingEdited() is that right? So you wanna know if any of the editboxes has focus, meaning that it would be receiving a DEL key input if the button was pressed.
CrazyEddie: "I don't like GUIs"

Neo
Just popping in
Just popping in
Posts: 13
Joined: Sat Mar 30, 2013 16:49

Re: How to know if the window has got focus?

Postby Neo » Mon Nov 21, 2016 06:31

Ident wrote:Ok I think I misunderstood you at first.

So what you want in the end is a way to say isAnyEditboxBeingEdited() is that right?

Yes, absolutely :D
In normal system widget programming, root window will lose focus when you are editing editbox. But in cegui, the root window still labelled as active while typing in the editbox.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: How to know if the window has got focus?

Postby Ident » Mon Nov 21, 2016 17:27

Neo wrote:In normal system widget programming, root window will lose focus when you are editing editbox. But in cegui, the root window still labelled as active while typing in the editbox.

I would like to believe that is true, but can you give me some examples / sources on that? If this is a general pattern used in widget systems, then I would like to switch to this for 1.0.

There is a function getActiveChild() which looks for the topmost-drawn active window. I think what you can do is to: call it on the root window everytime you wanna delete a game entity in your editor then check if the active window is a editbox (or whatever else you want to check) - and you should be good. Tell me if this works
CrazyEddie: "I don't like GUIs"

Neo
Just popping in
Just popping in
Posts: 13
Joined: Sat Mar 30, 2013 16:49

Re: How to know if the window has got focus?

Postby Neo » Tue Nov 22, 2016 22:49

Ident wrote:can you give me some examples / sources on that? If this is a general pattern used in widget systems, then I would like to switch to this for 1.0.


Do you mean you want a general code example other than cegui? I think I can make a simple x11 window and test how it works. Just give me some time to review my system coding lessons before I can provide a sample code XD

Ident wrote:There is a function getActiveChild() which looks for the topmost-drawn active window. I think what you can do is to: call it on the root window everytime you wanna delete a game entity in your editor then check if the active window is a editbox (or whatever else you want to check) - and you should be good. Tell me if this works

This one works! I can get to know which window is capturing event in every key up event!
This line will give me the certain type string, despite whatever widget name is.(It's lua code)

Code: Select all

g_ui_table.editor:getActiveChild():getType()

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: How to know if the window has got focus?

Postby Ident » Tue Nov 22, 2016 22:56

Neo wrote:
Ident wrote:can you give me some examples / sources on that? If this is a general pattern used in widget systems, then I would like to switch to this for 1.0.


Do you mean you want a general code example other than cegui? I think I can make a simple x11 window and test how it works. Just give me some time to review my system coding lessons before I can provide a sample code XD

I meant libraries as examples, so x11 is one.

Neo wrote:
Ident wrote:There is a function getActiveChild() which looks for the topmost-drawn active window. I think what you can do is to: call it on the root window everytime you wanna delete a game entity in your editor then check if the active window is a editbox (or whatever else you want to check) - and you should be good. Tell me if this works

This one works! I can get to know which window is capturing event in every key up event!
This line will give me the certain type string, despite whatever widget name is.(It's lua code)

Code: Select all

g_ui_table.editor:getActiveChild():getType()

Glad to have helped, I assume this is resolved then
CrazyEddie: "I don't like GUIs"

Neo
Just popping in
Just popping in
Posts: 13
Joined: Sat Mar 30, 2013 16:49

Re: [Resolved somehow] How to know if the window has got focus?

Postby Neo » Tue Nov 22, 2016 23:38

Thanks. And now I find that I can use deactivate() to forcefully remove input focus on active edit box if I click the empty area of root default window 8) .
As I said before, input focus will stay in edit box you click on the empty default window, unless a widget like a frame window or list item is clicked.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 25 guests