Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyfreg committed May 26, 2024
2 parents 637411b + 99bef62 commit 9386486
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 31 deletions.
24 changes: 15 additions & 9 deletions Code/Client/NetImgui_Api.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ enum eCompressionMode {
// Function typedefs
//-------------------------------------------------------------------------------------------------
typedef void (*ThreadFunctPtr)(void threadedFunction(void* pClientInfo), void* pClientInfo);
typedef void (*FontCreationFuncPtr)(float PreviousDPIScale, float NewDPIScale);
typedef void (*FontCreateFuncPtr)(float PreviousDPIScale, float NewDPIScale);

//=================================================================================================
// Initialize the Network Library
Expand All @@ -157,15 +157,19 @@ NETIMGUI_API void Shutdown();
// Note: Start a new communication thread using std::Thread by default, but can receive custom
// thread start function instead (Look at ClientExample 'CustomCommunicationThread').
//-------------------------------------------------------------------------------------------------
// clientName : Client name displayed in the Server's clients list
// serverHost : Address of the NetImgui Server application (Ex1: 127.0.0.2, Ex2: localhost)
// serverPort : PortID of the NetImgui Server application to connect to
// clientPort : PortID this Client should wait for connection from Server application
// threadFunction : User provided function to launch new networking thread.
// Use 'DefaultStartCommunicationThread' by default (relying on 'std::thread').
// clientName : Client name displayed in the Server's clients list
// serverHost : NetImgui Server Application address (Ex1: 127.0.0.2, Ex2: localhost)
// serverPort : PortID of the NetImgui Server application to connect to
// clientPort : PortID this Client should wait for connection from Server application
// threadFunction : User provided function to launch new networking thread.
// Use 'DefaultStartCommunicationThread' by default (uses 'std::thread').
// fontCreateFunction : User provided function to call when the Server expect an update of
// the font atlas, because of a monitor DPI change. When left to nullptr,
// uses 'ImGuiIO.FontGlobalScale' instead to increase text size,
// with blurier results.
//=================================================================================================
NETIMGUI_API bool ConnectToApp(const char* clientName, const char* serverHost, uint32_t serverPort=kDefaultServerPort, ThreadFunctPtr threadFunction=0, FontCreationFuncPtr FontCreateFunction = 0);
NETIMGUI_API bool ConnectFromApp(const char* clientName, uint32_t clientPort=kDefaultClientPort, ThreadFunctPtr threadFunction=0, FontCreationFuncPtr FontCreateFunction = 0);
NETIMGUI_API bool ConnectToApp(const char* clientName, const char* serverHost, uint32_t serverPort=kDefaultServerPort, ThreadFunctPtr threadFunction=0, FontCreateFuncPtr FontCreateFunction=0);
NETIMGUI_API bool ConnectFromApp(const char* clientName, uint32_t clientPort=kDefaultClientPort, ThreadFunctPtr threadFunction=0, FontCreateFuncPtr fontCreateFunction=0);

//=================================================================================================
// Request a disconnect from the NetImguiServer application
Expand Down Expand Up @@ -198,6 +202,8 @@ NETIMGUI_API bool IsDrawingRemote(void);
//=================================================================================================
// Send an updated texture used by imgui, to the NetImguiServer application
// Note: To remove a texture, set pData to nullptr
// Note: User needs to provide a valid 'dataSize' when using format 'kTexFmtCustom',
// can be ignored otherwise
//=================================================================================================
NETIMGUI_API void SendDataTexture(ImTextureID textureId, void* pData, uint16_t width, uint16_t height, eTexFormat format, uint32_t dataSize=0);

Expand Down
4 changes: 2 additions & 2 deletions Code/Client/Private/NetImgui_Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void DefaultStartCommunicationThread(void ComFunctPtr(void*), void* pClient)


//=================================================================================================
bool ConnectToApp(const char* clientName, const char* ServerHost, uint32_t serverPort, ThreadFunctPtr threadFunction, FontCreationFuncPtr FontCreateFunction)
bool ConnectToApp(const char* clientName, const char* ServerHost, uint32_t serverPort, ThreadFunctPtr threadFunction, FontCreateFuncPtr FontCreateFunction)
//=================================================================================================
{
if (!gpClientInfo) return false;
Expand Down Expand Up @@ -64,7 +64,7 @@ bool ConnectToApp(const char* clientName, const char* ServerHost, uint32_t serve
}

//=================================================================================================
bool ConnectFromApp(const char* clientName, uint32_t serverPort, ThreadFunctPtr threadFunction, FontCreationFuncPtr FontCreateFunction)
bool ConnectFromApp(const char* clientName, uint32_t serverPort, ThreadFunctPtr threadFunction, FontCreateFuncPtr FontCreateFunction)
//=================================================================================================
{
if (!gpClientInfo) return false;
Expand Down
2 changes: 1 addition & 1 deletion Code/Client/Private/NetImgui_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct ClientInfo
bool mServerCompressionSkip = false; // Force ignore compression setting for 1 frame
bool mServerForceConnectEnabled = true; // If another NetImguiServer can take connection away from the one currently active
ThreadFunctPtr mThreadFunction = nullptr; // Function to use when laucnhing new threads
FontCreationFuncPtr mFontCreationFunction = nullptr; // Method to call to generate the remote ImGui font. By default, re-use the local font, but this doesn't handle native DPI scaling on remote server
FontCreateFuncPtr mFontCreationFunction = nullptr; // Method to call to generate the remote ImGui font. By default, re-use the local font, but this doesn't handle native DPI scaling on remote server
float mFontCreationScaling = 1.f; // Last font scaling used when generating the NetImgui font
InputState mPreviousInputState; // Keeping track of last keyboard/mouse state
ImGuiID mhImguiHookNewframe = 0;
Expand Down
24 changes: 12 additions & 12 deletions Code/Sample/Common/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace NetImgui
{
using ThreadFunctPtr = void*;
using FontCreationFuncPtr = void*;
using FontCreateFuncPtr = void*;
}
#endif

Expand All @@ -26,17 +26,17 @@ class Base
virtual ImDrawData* Draw() = 0; //!< Each sample should have their Dear ImGui drawing routines in this overloaded method

protected:
void Draw_Connect(); //!< Display UI for initiating a connection to the remote NetImgui server application
const char* mSampleName = nullptr; //!< Name displayed in the Main Menu bar (must receive string pointer in constructor that remains valid)
ImGuiContext* mpContextMain = nullptr; //!< Pointer to main context created in main.cpp (used to detect when to update font texture)
ImGuiContext* mpContextLocal = nullptr; //!< Pointer to context used for local draw. Most sample leave it to the same as mpContextMain (used to detect when to update font texture)
NetImgui::ThreadFunctPtr mCallback_ThreadLaunch = nullptr; //!< [Optional] Thread launcher callback assigned on NetImgui connection. Used to start a new thread for coms with NetImgui server
NetImgui::FontCreationFuncPtr mCallback_FontGenerate = nullptr; //!< [Optional] Font generation callback assigned on NetImgui connection. Used to adjust the font data to remote server DPI
float mGeneratedFontScaleDPI = 0.f; //!< Current generated font texture DPI
bool mbShowDemoWindow = false; //!< If we should show the Dear ImGui demo window
char mConnect_HostnameServer[128] = {"localhost"}; //!< IP/Hostname used to send a connection request when when trying to reach the server
int mConnect_PortServer = 0; //!< Port used to send a connection request when when trying to reach the server
int mConnect_PortClient = 0; //!< Port opened when waiting for a server connection request
void Draw_Connect(); //!< Display UI for initiating a connection to the remote NetImgui server application
const char* mSampleName = nullptr; //!< Name displayed in the Main Menu bar (must receive string pointer in constructor that remains valid)
ImGuiContext* mpContextMain = nullptr; //!< Pointer to main context created in main.cpp (used to detect when to update font texture)
ImGuiContext* mpContextLocal = nullptr; //!< Pointer to context used for local draw. Most sample leave it to the same as mpContextMain (used to detect when to update font texture)
NetImgui::ThreadFunctPtr mCallback_ThreadLaunch = nullptr; //!< [Optional] Thread launcher callback assigned on NetImgui connection. Used to start a new thread for coms with NetImgui server
NetImgui::FontCreateFuncPtr mCallback_FontGenerate = nullptr; //!< [Optional] Font generation callback assigned on NetImgui connection. Used to adjust the font data to remote server DPI
float mGeneratedFontScaleDPI = 0.f; //!< Current generated font texture DPI
bool mbShowDemoWindow = false; //!< If we should show the Dear ImGui demo window
char mConnect_HostnameServer[128] = {"localhost"}; //!< IP/Hostname used to send a connection request when when trying to reach the server
int mConnect_PortServer = 0; //!< Port used to send a connection request when when trying to reach the server
int mConnect_PortClient = 0; //!< Port opened when waiting for a server connection request
};

//=============================================================================
Expand Down
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ The NetImgui Server application currently compiles under Windows and Mac, but fe
- `NetImgui::IsConnected()` and `NetImgui::IsDrawingRemote()` can be used during Dear ImGui drawing, helping to make selective decisions on the content to draw based on where it will be displayed.

#### Dear Imgui versions
- Tested against **Dear ImGui** versions: **1.71, 1.72, 1.73, 1.74, 1.75, 1.76, 1.76** (docking)**, 1.77, 1.78, 1.79, 1.80, 1.80** (docking)**, 1.81, 1.82, 1.83, 1.84, 1.85, 1.86, 1.87, 1.87, 1.88, 1.89** (docking)**, 1.89.1, 189.2, 189.2, 189.5**.
- Tested against **Dear ImGui** versions **1.71** to **1.90**.
- *Note*: Should support other versions without too much difficulties.
- *Note*: See **Build\GenerateCompatibilityTest.bat** for an exact list of tested versions.

# Related
Related projects making use of **NetImgui**.
Expand All @@ -103,18 +104,46 @@ Related projects making use of **NetImgui**.
### To do
- Support of additional texture formats
- Handle Linear/sRGB vertex color format
- Add logging information in netImgui server application
- Profile and optimize performances
- Add logging information to NetImgui Server Application
- Add new **Dear ImGui** multi windows support (docking branch)
- ~~Commands to assign custom backgrounds~~
- ~~Add compression to data between Client and Server~~
- ~~Support of monitor DPI~~

### Version 1.9
(2023/05/04)
### Version 1.10
(2023/12/30)
- **API Changes**
- None
- **Upgraded Dear ImGui support to 1.89.5**
- **ConnectToApp()** and **ConnectFromApp()** functions now accept a callback to be used by the NetImgui Server when wanting to update the font to a specific DPI scale.
- Can be left untouched, with *null* used by default.
- Without a callback, we apply the text scaling to **ImGuiIO.FontGlobalScale** instead of requesting the generation of a new font with increased pixel size.
- Using **ImGuiIO.FontGlobalScale** gives a blurier text result than recreating the font with the exact DPI needed.
- See **SampleFontDPI** for more info.
- **SendDataTexture()** now support a new texture format **kTexFmtCustom**.
- It requires that the **dataSize** parameter is specified since we can't deduce it anymore *(but not used for other formats)*
- It allows user to send a texture command with custom data that also needs to be added to NetImguiServer codebase.
- This could be used for movie streaming, etc...
- See **SampleTexture** for more info.
- **Upgraded Dear ImGui support to 1.90**
- **Added monitor DPI support**
- The Server now scale the text up on a high resolution monitor, so it can still be read
- The Server font atlas is regenerated with a higher pixel size to match the resolution
- The Client connected will be asked to regenerate their font atlas if they provided a callback when connecting
- When this callback is received, the client codebase should regenerate the font atlas using the provided scale
- When no callback has been assigned, the client automatically relies on **ImGuiIO.FontGlobalScale** when drawing *(blurier results)*
- See **SampleFontDPI** for more info.
- **Added Clipboard support**
- Can now seamlessly use text clipboard between Client and Server!
- Text copied on the Server PC is now sent over to the NetImgui Clients and can be pasted inside their Dear ImGui content
- Text copied inside the Client's Dear ImGui content is now received by the Server PC and can be used on it
- **Shared Client configs**
- When adding a Client configuration on the NetImgui Server application, the property *Shared* can now be specified
- When enabled, it will save the config in a *User Directory* instead of the current *Working Directory*
- This means that user can have NetImgui Server applications in various locations, but they can all still share the same *Client Configs*.
- *Note:* Requires that the function **HAL_GetUserSettingFolder()** is implemented in the NetImgui Server codebase. It has been done for Windows.
- **Various small changes and fixes**
- When the NetImgui Server config file **netImgui.cfg** is detected **readonly**, now tries to create a second one. This should help if user submit the default config file to perforce but still want to add new Clients.
- Quickly typed text was dropping characters when received by Client
- DirectX textures error when quickly recreating them

### Older
[Release Notes](https://github.com/sammyfreg/netImgui/wiki/Release-notes)
Expand Down

0 comments on commit 9386486

Please sign in to comment.