Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of obsolete ImGui functions #302

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
with:
repository: ocornut/imgui
path: imgui
ref: v1.89
ref: v1.91.1

- name: Checkout SFML
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if(NOT IMGUI_DIR)
endif()

# This uses FindImGui.cmake provided in ImGui-SFML repo for now
find_package(ImGui 1.89 REQUIRED)
find_package(ImGui 1.91.1 REQUIRED)

# These headers will be installed alongside ImGui-SFML
set(IMGUI_PUBLIC_HEADERS
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Dependencies
-----

* [SFML](https://github.com/SFML/SFML) >= 2.5.0
* [Dear ImGui](https://github.com/ocornut/imgui) >= 1.89
* [Dear ImGui](https://github.com/ocornut/imgui) >= 1.91.1

Contributing
-----
Expand Down
49 changes: 24 additions & 25 deletions imgui-SFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ void updateJoystickDPadState(ImGuiIO& io);
void updateJoystickAxisState(ImGuiIO& io);

// clipboard functions
void setClipboardText(void* userData, const char* text);
const char* getClipboardText(void* userData);
void setClipboardText(ImGuiContext* /*ctx*/, const char* text);
const char* getClipboardText(ImGuiContext* /*ctx*/);
std::string s_clipboardText;

// mouse cursors
Expand Down Expand Up @@ -229,6 +229,7 @@ bool Init(sf::Window& window, const sf::Vector2f& displaySize, bool loadDefaultF
ImGui::SetCurrentContext(s_currWindowCtx->imContext);

ImGuiIO& io = ImGui::GetIO();
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();

// tell ImGui which features we support
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
Expand All @@ -244,8 +245,8 @@ bool Init(sf::Window& window, const sf::Vector2f& displaySize, bool loadDefaultF
io.DisplaySize = ImVec2(displaySize.x, displaySize.y);

// clipboard
io.SetClipboardTextFn = setClipboardText;
io.GetClipboardTextFn = getClipboardText;
platform_io.Platform_SetClipboardTextFn = setClipboardText;
platform_io.Platform_GetClipboardTextFn = getClipboardText;

// load mouse cursors
loadMouseCursor(ImGuiMouseCursor_Arrow, sf::Cursor::Arrow);
Expand Down Expand Up @@ -342,10 +343,10 @@ void ProcessEvent(const sf::Event& event) {
if (mod != ImGuiKey_None) {
io.AddKeyEvent(mod, down);
} else {
io.AddKeyEvent(ImGuiKey_ModCtrl, event.key.control);
io.AddKeyEvent(ImGuiKey_ModShift, event.key.shift);
io.AddKeyEvent(ImGuiKey_ModAlt, event.key.alt);
io.AddKeyEvent(ImGuiKey_ModSuper, event.key.system);
io.AddKeyEvent(ImGuiMod_Ctrl, event.key.control);
io.AddKeyEvent(ImGuiMod_Shift, event.key.shift);
io.AddKeyEvent(ImGuiMod_Alt, event.key.alt);
io.AddKeyEvent(ImGuiMod_Super, event.key.system);
}

const ImGuiKey key = keycodeToImGuiKey(event.key.code);
Expand Down Expand Up @@ -590,24 +591,22 @@ void SetJoystickMapping(int key, unsigned int joystickButton) {
// For partial backwards compatibility, also expect some ImGuiNavInput_* values.
ImGuiKey finalKey{};
switch (key) {
case ImGuiNavInput_Activate:
case ImGuiKey_GamepadFaceDown:
finalKey = ImGuiKey_GamepadFaceDown;
break;
case ImGuiNavInput_Cancel:
case ImGuiKey_GamepadFaceRight:
finalKey = ImGuiKey_GamepadFaceRight;
break;
case ImGuiNavInput_Input:
case ImGuiKey_GamepadFaceUp:
finalKey = ImGuiKey_GamepadFaceUp;
break;
case ImGuiNavInput_Menu:
case ImGuiKey_GamepadFaceLeft:
finalKey = ImGuiKey_GamepadFaceLeft;
break;
case ImGuiNavInput_FocusPrev:
case ImGuiNavInput_TweakSlow:
case ImGuiKey_GamepadL1:
finalKey = ImGuiKey_GamepadL1;
break;
case ImGuiNavInput_FocusNext:
case ImGuiNavInput_TweakFast:
case ImGuiKey_GamepadR1:
finalKey = ImGuiKey_GamepadR1;
break;
default:
Expand Down Expand Up @@ -920,11 +919,11 @@ void RenderDrawLists(ImDrawData* draw_data) {
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert),
(const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)));
(const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, pos)));
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert),
(const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)));
(const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, uv)));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert),
(const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)));
(const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, col)));

for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) {
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
Expand Down Expand Up @@ -1094,11 +1093,11 @@ void updateJoystickAxisState(ImGuiIO& io) {
s_currWindowCtx->rTriggerInfo.threshold, 100, false);
}

void setClipboardText(void* /*userData*/, const char* text) {
void setClipboardText(ImGuiContext* /*ctx*/, const char* text) {
sf::Clipboard::setString(sf::String::fromUtf8(text, text + std::strlen(text)));
}

const char* getClipboardText(void* /*userData*/) {
const char* getClipboardText(ImGuiContext* /*ctx*/) {
std::basic_string<std::uint8_t> tmp = sf::Clipboard::getString().toUtf8();
s_clipboardText.assign(tmp.begin(), tmp.end());
return s_clipboardText.c_str();
Expand Down Expand Up @@ -1341,16 +1340,16 @@ ImGuiKey keycodeToImGuiMod(sf::Keyboard::Key code) {
switch (code) {
case sf::Keyboard::LControl:
case sf::Keyboard::RControl:
return ImGuiKey_ModCtrl;
return ImGuiMod_Ctrl;
case sf::Keyboard::LShift:
case sf::Keyboard::RShift:
return ImGuiKey_ModShift;
return ImGuiMod_Shift;
case sf::Keyboard::LAlt:
case sf::Keyboard::RAlt:
return ImGuiKey_ModAlt;
return ImGuiMod_Alt;
case sf::Keyboard::LSystem:
case sf::Keyboard::RSystem:
return ImGuiKey_ModSuper;
return ImGuiMod_Super;
default:
break;
}
Expand Down
Loading