aboutsummaryrefslogtreecommitdiff
path: root/client/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/ui')
-rw-r--r--client/src/ui/imgui/imgui_stdlib.cpp76
-rw-r--r--client/src/ui/imgui/imgui_stdlib.h22
-rw-r--r--client/src/ui/ui.cpp23
-rw-r--r--client/src/ui/ui.h4
4 files changed, 106 insertions, 19 deletions
diff --git a/client/src/ui/imgui/imgui_stdlib.cpp b/client/src/ui/imgui/imgui_stdlib.cpp
new file mode 100644
index 0000000..cb1fe17
--- /dev/null
+++ b/client/src/ui/imgui/imgui_stdlib.cpp
@@ -0,0 +1,76 @@
+// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
+// This is also an example of how you may wrap your own similar types.
+
+// Compatibility:
+// - std::string support is only guaranteed to work from C++11.
+// If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
+
+// Changelog:
+// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
+
+#include "imgui.h"
+#include "imgui_stdlib.h"
+
+struct InputTextCallback_UserData
+{
+ std::string* Str;
+ ImGuiInputTextCallback ChainCallback;
+ void* ChainCallbackUserData;
+};
+
+static int InputTextCallback(ImGuiInputTextCallbackData* data)
+{
+ InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData;
+ if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
+ {
+ // Resize string callback
+ // If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want.
+ std::string* str = user_data->Str;
+ IM_ASSERT(data->Buf == str->c_str());
+ str->resize(data->BufTextLen);
+ data->Buf = (char*)str->c_str();
+ }
+ else if (user_data->ChainCallback)
+ {
+ // Forward to user callback, if any
+ data->UserData = user_data->ChainCallbackUserData;
+ return user_data->ChainCallback(data);
+ }
+ return 0;
+}
+
+bool ImGui::InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
+{
+ IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
+ flags |= ImGuiInputTextFlags_CallbackResize;
+
+ InputTextCallback_UserData cb_user_data;
+ cb_user_data.Str = str;
+ cb_user_data.ChainCallback = callback;
+ cb_user_data.ChainCallbackUserData = user_data;
+ return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
+}
+
+bool ImGui::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
+{
+ IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
+ flags |= ImGuiInputTextFlags_CallbackResize;
+
+ InputTextCallback_UserData cb_user_data;
+ cb_user_data.Str = str;
+ cb_user_data.ChainCallback = callback;
+ cb_user_data.ChainCallbackUserData = user_data;
+ return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data);
+}
+
+bool ImGui::InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
+{
+ IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
+ flags |= ImGuiInputTextFlags_CallbackResize;
+
+ InputTextCallback_UserData cb_user_data;
+ cb_user_data.Str = str;
+ cb_user_data.ChainCallback = callback;
+ cb_user_data.ChainCallbackUserData = user_data;
+ return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
+}
diff --git a/client/src/ui/imgui/imgui_stdlib.h b/client/src/ui/imgui/imgui_stdlib.h
new file mode 100644
index 0000000..f860b0c
--- /dev/null
+++ b/client/src/ui/imgui/imgui_stdlib.h
@@ -0,0 +1,22 @@
+// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
+// This is also an example of how you may wrap your own similar types.
+
+// Compatibility:
+// - std::string support is only guaranteed to work from C++11.
+// If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
+
+// Changelog:
+// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
+
+#pragma once
+
+#include <string>
+
+namespace ImGui
+{
+ // ImGui::InputText() with std::string
+ // Because text input needs dynamic resizing, we need to setup a callback to grow the capacity
+ IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
+ IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
+ IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
+}
diff --git a/client/src/ui/ui.cpp b/client/src/ui/ui.cpp
index 3e46a67..242bb5c 100644
--- a/client/src/ui/ui.cpp
+++ b/client/src/ui/ui.cpp
@@ -8,26 +8,15 @@ ID3D11RenderTargetView* ui::main_render_target;
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT WINAPI ui::wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
+LRESULT ui::wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
if (ImGui_ImplWin32_WndProcHandler(hwnd, message, wparam, lparam))
return true;
switch (message)
{
- case WM_SIZE:
- if (wparam != SIZE_MINIMIZED) {
- cleanup_target();
- swap_chain->ResizeBuffers(0, (UINT)LOWORD(lparam), (UINT)HIWORD(wparam), DXGI_FORMAT_UNKNOWN, 0);
- create_target();
- }
- return 0;
- case WM_SYSCOMMAND:
- if ((wparam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
+ case WM_DESTROY:
+ PostQuitMessage(0);
return 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
@@ -47,9 +36,9 @@ HWND ui::create(HINSTANCE instance, const std::pair<int, int> size, const std::p
RegisterClassEx(&wc);
- auto flag = WS_OVERLAPPEDWINDOW;
- flag &= ~WS_MAXIMIZEBOX;
- flag &= ~WS_SIZEBOX;
+ auto flag = WS_POPUP;
+ /*flag &= ~WS_MAXIMIZEBOX;
+ flag &= ~WS_SIZEBOX;*/
return CreateWindowEx(WS_EX_TOPMOST, wc.lpszClassName, "client", flag, pos.first, pos.second, size.first, size.second, 0, 0, wc.hInstance, 0);
}
diff --git a/client/src/ui/ui.h b/client/src/ui/ui.h
index 3383c25..7fd3248 100644
--- a/client/src/ui/ui.h
+++ b/client/src/ui/ui.h
@@ -4,6 +4,7 @@
#include "imgui/imgui_impl_win32.h"
#include "imgui/imgui_impl_dx11.h"
+#include "imgui/imgui_stdlib.h"
#include <d3d11.h>
namespace ui {
@@ -12,11 +13,10 @@ namespace ui {
extern IDXGISwapChain* swap_chain;
extern ID3D11RenderTargetView* main_render_target;
- LRESULT WINAPI wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+ LRESULT wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
HWND create(HINSTANCE instance, const std::pair<int, int> size, const std::pair<int, int> pos = { 400, 400 });
-
bool create_device(HWND hwnd);
void create_target();
void cleanup_target();