Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK .NET / How do you focus the DGDK Window with code?

Author
Message
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th Oct 2011 18:22
Hi, I am using Dark GDK with the normal GDK window. I am not using the viewport control and wish to focus the window using code. It is possible to get the window handle, so in the mean time I will look up for examples on MSDN; but I cannot do a great deal with the hWnd result; would have been nice if From.FromHandle() worked with the hWnd handle. OverridehWnd causes errors all over the place here on VB2008.

I just wondered how anyone here may have acheived this DB window focusing. I currently need to listen for keypresses in Forms, WPF and the engine, since they seem to require keyboard focus. I might need to look into some lower level keyboard input measures or windows messages if necessary.

jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 31st Oct 2011 04:27
Well here is the code and also some explanation



Very easy , see

One thing you should know is that the dark GDK makes a hook to the keyboard which means that you should be able to access the keys using the GDK IO namespace as long as your form has focus and in most cases the keys should still be detected even without the form having focus.

pseudo code



" The best slaves are the ones who think they are free. "
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 31st Oct 2011 18:41
Indeed true, but I should have mentioned that I need to avoid bringing the window to the front. I use other windows for custom message boxes and user interface screens.

For instance; the player needs to still be able to move a walking character whilst having selected an inventory item from another visible custom window list box which is not a child window. Setting an inventory window to topmost may help here and there, but it doesn't seem like it is easy to integrate WPF, Forms and DirectX with global keyboard focus.

I will investigate your keyboard state example; but I am using my own custom made library which uses the GDK interfaces directly, so I do not have the DarkGDK.IO namespace created by the DarkGDK.NET guy imported at present; but I will give it a go if it works with my DLLs.

Although this doesn't mean that my goal is impossible, as I could create a keyboard handler for every control that could possibly override the main window's keyboard focus; but I am just wondering if someone has a more efficient and less time consuming method.

Thanks for your help

jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 31st Oct 2011 19:00
Perhaps you are going about this the wrong way. I would avoid using forms to make character menus and things of the such. I think a better way to approach this would be to use the 2d class to draw custom menus and just over lay them on your 3d. This way you always have focus on your main screen and the menus are a part of it.

For example the game world of warcraft. All the menus in that game are drawn using the 2d pipeline then drawn on top of the 3d. You could just use a mouse point check to see if you are hovering over an open menu.

I know this way is a little more tedious because you have draw your controls but it I think it will save you more time in the long run.

" The best slaves are the ones who think they are free. "
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Nov 2011 00:16 Edited at: 1st Nov 2011 00:20
I agree with you 100%, which is why I used 2D and sprites in the first place. It's funny because I was in tears after a weeks work making a nice GUI system with 2d functions to find out that it caused too much lag for a game with a heavy duty interface; the type with lots of item management and lists with a multiplayer environment just cannot handle the 2d and even sprite commands on a low end PC (according to my tests).



So, the reason is because the Forms and WPF can handle the display of lots of lists, panels and menus without dropping a single millisecond (most of the time). It is probably because they automatically refresh the display only when something changes, not on every loop. But if you know of a way to apply this in DB 2D I'm all ears. Bitmap commands are not bad, but there are some GDK glitches with those, and there is no SetBitmapFormat in the library.

The disadvantage of Forms+WPF is my keyboard focus problem, graphical glitches here and there, window ordering and security.

I wish I could do what you advise because it would make things neater from a programming standpoint; but in the long run, because the game requires high performance I can only use sprites and 2d for certain decorated parts of the interface, not the whole thing.

Obviously I don't have the luxury of Advance2d or D3DFunc either, so if you have any other ideas don't hesitate to let me know.

I also use 3d for certain aspects of the interface, but not for lists and inventories obviously.

I'm sure a solution will pop up.

aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 3rd Nov 2011 18:35
One method I set up is using sprites for a variety of onscreen menus; one in each corner of the display. Using the collision method, whenever the cursor sprite collides with another sprite, I set a string variable to identify the sprite object (menu item) collided with. Then, in the viewport.click event, I have a Select Case <string variable> statement determine what code to execute based upon the item collided with.

Just an idea since the sprites do not have a click event.

Russell B. Davis/aerostudios
jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 3rd Nov 2011 19:04
I am going to be making small rpg example soon and I am will use the 2d interface for menus. Once I'm done I'll post all the code. Perhaps that will help you out.

" The best slaves are the ones who think they are free. "
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 3rd Nov 2011 20:31 Edited at: 3rd Nov 2011 20:31
Quote: "One method I set up is using sprites for a variety of onscreen menus; one in each corner of the display. Using the collision method, whenever the cursor sprite collides with another sprite, I set a string variable to identify the sprite object (menu item) collided with. Then, in the viewport.click event, I have a Select Case <string variable> statement determine what code to execute based upon the item collided with"
.

Yeah this is a good method, its something like what I often use. I work alot with network operation flags (powers of 2 or hex etc) so I tend to use IF and Else If to see if a single variable contains more than one instruction, to keep network packets small:


Quote: "
I am going to be making small rpg example soon and I am will use the 2d interface for menus. Once I'm done I'll post all the code. Perhaps that will help you out."


Cool thanks. I still use 2d commands for a lot of the interface. I have a fully working 2d command based GUI, equipped with bitmap fonts, windows, buttons and animations. I just don't use it for the menus and lists, as it caused too much of a slow down; perhaps because of the quantity commands (200+) and the fact that I have to create loops to check if the menu needed to be updated, drawn and refreshed.

I'm just not in the mood to make it work efficiently; perhaps I am lazy or perhaps other areas of the game deserve more of my time. I started to use WPF based lists, menus and stackpanels so I do not need to reinvent the wheel, the frame rate does not drop, I could label UI elements easily, text boxes have selection copy and paste and I was given lots of ready made commands and events; leaving me more time for modelling and animation. But, still, the disadvantage is security and keyboard focus.

Still searching for a solution; but it seams I will just have to create two keyboard input checks per game action; then run a check during my keyup/keydown event in the base interface class. It's a good thing I bothered to derive all my UI elements from the same class, otherwise the situation would have been worse.

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 4th Nov 2011 15:27
Ok for anyone who gets the problem in future, the following class library will let you control global input when displaying a message box or when using a WPF window for prompts or help documents etc; regardless of what window, textbox or list has the focus.

System.Windows.Input.Keyboard Class
System.Windows.Input.Keyboard.IsKeyDown()
System.Windows.Input.Keyboard.IsKeyUp()
System.Windows.Input.Keyboard.Modifiers()
- See if shift/alt/ctrl are pressed
System.Windows.Input.Keyboard.IsKeyToggled()
System.Windows.Input.Keyboard.Focus()
- Give keyboard focus to a UIElement

If you want to hook a subroutine to a global key up / key down event, just use
AddKeyUpHandler() or AddKeyDownHandler(). No need to deal with input on a per control level as this is global.

After a menu click or button press, your DGDK window should get the focus back and regular GDK input commands receive input. Use a function to handle both systems by putting your GDK and Windows input checks in the same place with appropriate management.

Login to post a reply

Server time is: 2024-03-28 18:07:21
Your offset time is: 2024-03-28 18:07:21