Game Window Cursor Clipping: Difference between revisions
LordOf Xen (talk | contribs) |
LordOf Xen (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
== Summary == | == Summary == | ||
This implementation allows you to clip the cursor to the game window such as in [https://en.wikipedia.org/wiki/Doom_(2016_video_game) DOOM] and '''[https://en.wikipedia.org/wiki/Doom_Eternal DOOM Eternal]''' (id Tech [https://en.wikipedia.org/wiki/Id_Tech_6 6] - [https://en.wikipedia.org/wiki/Id_Tech_7 7]), also brings some fixes to various bugs on VGUI. | This implementation allows you to clip the cursor to the game window such as in [https://en.wikipedia.org/wiki/Doom_(2016_video_game) DOOM] and '''[https://en.wikipedia.org/wiki/Doom_Eternal DOOM Eternal]''' (id Tech [https://en.wikipedia.org/wiki/Id_Tech_6 6] - [https://en.wikipedia.org/wiki/Id_Tech_7 7]), also brings some fixes to various bugs on VGUI. | ||
Line 7: | Line 8: | ||
Gwccs02.gif|Example of cursor clipping while moving a VGUI panel | Gwccs02.gif|Example of cursor clipping while moving a VGUI panel | ||
</gallery> | </gallery> | ||
== Requirements == | |||
* Knowledge of C++ | |||
* Knowledge of Source Engine | |||
* Source SDK Base 2013 - Currently tested on Source SDK Base 2013 Multiplayer. | |||
== Getting the Implementation/Code== | |||
First of all, you'll need the following files from the following GitHub repository: | |||
* [https://github.com/LordOfXen/source-engine-examples/tree/main/cursor-clipping source-engine-examples-cursor-clipping] | |||
Which you will copy to '''src/game/client/'''. You can also create a subfolder if you wish to, and copy these files there. | |||
== Implementation == | |||
Now head over to ''cdll_client_int.cpp''' and include | |||
<source lang="cpp"> | |||
#include "CCursorClipManagement.h" | |||
</source> | |||
Anywhere before | |||
<source lang="cpp"> | |||
// memdbgon must be the last include file in a .cpp file!!! | |||
#include "tier0/memdbgon.h" | |||
</source> | |||
In the same cpp, find '''CHLClient::PostInit()''' and add this to the end: | |||
<source lang="cpp"> | |||
CCursorClipManagement::Init(); | |||
</source> | |||
Lastly, find '''void OnRenderEnd()''' and add this to the end: | |||
<source lang="cpp"> | |||
g_pCursorClipManager->Think(); | |||
</source> | |||
== Conclusion == | |||
You're all set! Compile your client project and check if it works. | |||
== Notes == | |||
If you start the game/mod with one of the following parameters: | |||
* -tools | |||
* -dev | |||
* -developer | |||
* -nocursorclipping | |||
Or if you're compiling into a different platform, else than WIN32, the cursor clipping will be disabled and won't work by default. | |||
This behavior can be changed by modifying '''CCursorClipManagement::Think()'''. | |||
You can also add a ConVar to enable or disable this dynamically in-game, all you'll need to do is adding one more check on '''CCursorClipManagement::Think()'''. | |||
[[Category:Programming]] | |||
[[Category:Free source code]] |
Revision as of 13:41, 6 January 2021
Summary
This implementation allows you to clip the cursor to the game window such as in DOOM and DOOM Eternal (id Tech 6 - 7), also brings some fixes to various bugs on VGUI.
Requirements
- Knowledge of C++
- Knowledge of Source Engine
- Source SDK Base 2013 - Currently tested on Source SDK Base 2013 Multiplayer.
Getting the Implementation/Code
First of all, you'll need the following files from the following GitHub repository:
Which you will copy to src/game/client/. You can also create a subfolder if you wish to, and copy these files there.
Implementation
Now head over to cdll_client_int.cpp' and include
#include "CCursorClipManagement.h"
Anywhere before
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
In the same cpp, find CHLClient::PostInit() and add this to the end:
CCursorClipManagement::Init();
Lastly, find void OnRenderEnd() and add this to the end:
g_pCursorClipManager->Think();
Conclusion
You're all set! Compile your client project and check if it works.
Notes
If you start the game/mod with one of the following parameters:
- -tools
- -dev
- -developer
- -nocursorclipping
Or if you're compiling into a different platform, else than WIN32, the cursor clipping will be disabled and won't work by default.
This behavior can be changed by modifying CCursorClipManagement::Think().
You can also add a ConVar to enable or disable this dynamically in-game, all you'll need to do is adding one more check on CCursorClipManagement::Think().